【问题标题】:Reshaping tensorflow output tensors重塑张量流输出张量
【发布时间】:2020-10-13 14:19:28
【问题描述】:

我正在使用 Azure customvision.ai 训练对象检测模型。模型输出为 tensorflow,保存模型 .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.

这里发生了什么?如何重塑我的 tensorflow 模型以匹配 4 个输出张量的设备要求?

有效的模型

不工作的模型

编辑,这会输出一个 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

【问题讨论】:

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


    【解决方案1】:

    您正在运行一个对象检测演示,其中引擎期望模型有 4 个输出,而您的模型只有一个输出。也许您的 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

    【讨论】:

    • 嘿,谢谢!我尝试了这个(在 OP 中留下了我在上面所做的更改),虽然它仍然输出一个 tflite 模型,但它并没有改变模型输出。有什么想法吗?
    • Humnn,我想我不太确定 Azure 生成的是什么类型的模型,并假设它是一个 ssd 移动网络,因为您厌倦了将它与我们的检测引擎一起使用。您对模型输出的期望是什么?我建议使用基本引擎或纯 tflite API 而不是检测引擎
    猜你喜欢
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 2016-10-18
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-15
    相关资源
    最近更新 更多