MatMul无法推断形状,因为输入尺寸不兼容

时间:2019-08-06 22:03:26

标签: tensorflow keras lstm openvino

我正在frozon .pb模型文件上运行OpenVINO优化。运行优化时,它显示以下错误消息:

E0806 16:58:26.145075 140020238079808 matmul.py:52] MatMul wasn't able to infer shape because input dimensions are not compatible
E0806 16:58:26.146022 140020238079808 infer.py:152] Shape is not defined for output 0 of "lstm_27/while/MatMul_3".
E0806 16:58:26.146118 140020238079808 infer.py:180] Cannot infer shapes or values for node "lstm_27/while/MatMul_3".
E0806 16:58:26.146183 140020238079808 infer.py:181] Not all output shapes were inferred or fully defined for node "lstm_27/while/MatMul_3". 
 For more information please refer to Model Optimizer FAQ (https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_Model_Optimizer_FAQ.html), question #40. 
E0806 16:58:26.146232 140020238079808 infer.py:182] 
E0806 16:58:26.146281 140020238079808 infer.py:183] It can happen due to bug in custom shape infer function <function tf_matmul_infer at 0x7f586c514e18>.
E0806 16:58:26.146322 140020238079808 infer.py:184] Or because the node inputs have incorrect values/shapes.
E0806 16:58:26.146360 140020238079808 infer.py:185] Or because input shapes are incorrect (embedded to the model or passed via --input_shape).

model.summary()的输出

Model: "sequential_11"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lstm_27 (LSTM)               (None, 10, 50)            10600     
_________________________________________________________________
lstm_28 (LSTM)               (None, 10, 40)            14560     
_________________________________________________________________
lstm_29 (LSTM)               (None, 30)                8520      
_________________________________________________________________
dense_7 (Dense)              (None, 1)                 31        
=================================================================
Total params: 33,711
Trainable params: 33,711
Non-trainable params: 0

我正在按照以下要求进行优化。

input_shape = [0, 10, 50]
input_shape_str = str(input_shape).replace(' ','')
input_shape_str

!python3 {mo_tf_path} --input_model {pb_file} --output_dir {output_dir} --input_shape {input_shape_str} --data_type FP32

这是什么问题?

1 个答案:

答案 0 :(得分:0)

mo_tf需要精确的输入形状,即input_shape = [1、10、50]。使用-1、0或跳过第一维将引发错误。

相关问题