重塑张量流输出张量

时间:2020-06-23 13:40:43

标签: tensorflow microsoft-cognitive azure-cognitive-services google-coral microsoft-custom-vision

我正在使用Azure customvision.ai训练对象检测模型。模型输出带有张量流,可以保存为.pb,.tf或.tflite。

模型输出类型指定为float32 [1,13,13,50]

然后,我将.tflite推送到Google Coral Edge设备上并尝试运行它(先前使用Google Cloud训练的.tflite模型起作用,但是我现在绑定到公司Azure,需要使用customvision.ai)。这些命令与

一起使用
$ mdt shell

$ export DEMO_FILES="/usr/lib/python3/dist*/edgetpu/demo"

$ export DISPLAY=:0 && edgetpu_detect \
$ --source /dev/video1:YUY2:1280x720:20/1  \
$ --model ${DEMO_FILES}/model.tflite

最后,模型尝试运行,但会导致ValueError

'This model has a {}.'.format(output_tensors_sizes.size)))
ValueError: Detection model should have 4 output tensors! This model has 1.

这是怎么回事?如何重塑我的张量流模型以匹配4个输出张量的设备要求?

有效的模型 enter image description here

无效的模型 enter image description here

编辑,这会输出一个tflite模型,但仍然只有一个输出

python tflite_convert.py \
--output_file=model.tflite \
--graph_def_file=saved_model.pb \
--saved_model_dir="C:\Users\b0588718\AppData\Roaming\Python\Python37\site-packages\tensorflow\lite\python" \
--inference_type=FLOAT \
--input_shapes=1,416,416,3  \
--input_arrays=Placeholder \
--output_arrays='TFLite_Detection_PostProcess','TFLite_Detection_PostProcess:1','TFLite_Detection_PostProcess:2','TFLite_Detection_PostProcess:3' \
--mean_values=128 \
--std_dev_values=128 \
--allow_custom_ops \
--change_concat_input_ranges=false \
--allow_nudging_weights_to_use_fast_gemm_kernel=true

1 个答案:

答案 0 :(得分:2)

您正在运行一个对象检测演示,其中引擎期望模型提供4个输出,而模型只有1个输出。也许您的tflite转换不正确?例如,如果您从我们的动物园抢购了Face SSD模型,则转换应如下所示:

$ tflite_convert \ 
--output_file=face_ssd.tflite \
--graph_def_file=tflite_graph.pb \
--inference_type=QUANTIZED_UINT8 \
--input_shapes=1,320,320,3 \
--input_arrays normalized_input_image_tensor \
--output_arrays "TFLite_Detection_PostProcess,TFLite_Detection_PostProcess:1,TFLite_Detection_PostProcess:2,TFLite_Detection_PostProcess:3" \ 
--mean_values 128 \
--std_dev_values 128 \
--allow_custom_ops \
--change_concat_input_ranges=false \
--allow_nudging_weights_to_use_fast_gemm_kernel=true

请查看类似的查询以获取更多详细信息: https://github.com/google-coral/edgetpu/issues/135#issuecomment-640677917