这种怀疑与本[条款] https://www.tensorflow.org/lite/models/pose_estimation/overview有关。它描述了由Tensorflow提供的tflite模型用于姿势估计。我使用模型完成了推理部分。模型以特定格式输出值。我的目标是在测试图像上添加检测到的关键点。但是输出dict不包含任何键的指定关键点。我用谷歌搜索并找到了将其解码的代码。但是背后没有真正的想法。有谁知道这些输出值意味着什么。
到目前为止,我已经编写了用于加载tflite模型,分配模型,设置张量,输入输入图像并获得原始预测的代码。
这是推理代码
try :
import sys
sys.path.remove( '/opt/ros/kinetic/lib/python2.7/dist-packages' )
except :
pass
try :
from tensorflow.contrib import lite
from numpy import expand_dims
from cv2 import imread, resize
except :
print( '[ INFO ] Error importing' )
try :
interpreter = lite.Interpreter( '../model/multi_person_mobilenet_v1_075_float.tflite' )
except :
interpreter = lite.Interpreter( '../model/multi_person_mobilenet_v1_075_float.tflite' )
interpreter.allocate_tensors( )
input_details = interpreter.get_input_details( )
print( '[ INFO ] Input details : {}'.format( input_details ) )
# print( '[ INFO ] Model takes data of shape : {}'.format( input_details[ 0 ][ 'shape' ] ) )
output_details = interpreter.get_output_details( )
print( '[ INFO ] Output details : {}'.format( output_details ) )
# print( '[ INFO ] Model has output shape : {}'.format( output_details[ 0 ][ 'shape' ] ) )
try :
image = imread( '../pictures/pose_test_0.jpg' )
image_cc = image.copy( )
assert len( image.shape ) == 3
image = image.astype( 'float32' )
image = resize( image, ( 257, 353 ) )
print( '[ INFO ] Image is of type : {}'.format( image.dtype ) )
image = expand_dims( image, 0 )
print( '[ INFO ] Image shape after expanding : {}'.format( image.shape ) )
interpreter.set_tensor( input_details[0][ 'index' ], image )
interpreter.invoke( )
print( '[ INFO ] Output details : {}'.format( interpreter.get_tensor( output_details[ 2 ][ 'index' ] )[ 0 ][ 0 ] ) )
except AssertionError :
print( '[ INFO ] Expecting image to have 3 dimensions but found image with dimension(s) {}'.format( image.shape ) )
这是模型的输出详细信息
[{'name': 'float_heatmaps', 'index': 93, 'shape': array([ 1, 23, 17, 17]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0)}, {'name': 'float_short_offsets', 'index': 96, 'shape': array([ 1, 23, 17, 34]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0)}, {'name': 'float_mid_offsets', 'index': 94, 'shape': array([ 1, 23, 17, 64]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0)}, {'name': 'float_segments', 'index': 95, 'shape': array([ 1, 23, 17, 1]), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0)}]
TIA