python3 的 mobilenetv2 tflite 不是预期的输出大小

mobilenetv2 tflite not expected output size with python3

我 运行 我的 mobilenetV2 SSD 型号有问题。 我使用详细的步骤 here 转换它,除了我使用 CLI 工具 tflite_convert 进行相关步骤。

这工作正常,我能够执行推理,但输出大小不是我预期的。

下面python代码行

interpreter.get_output_details()

告诉我要取回 10 个检测框 :

[{'shape': array([ 1, 10,  4], dtype=int32), 'index': 252, 'name': 'TFLite_Detection_PostProcess', 'quantization': (0.0, 0), 'dtype': <class 'numpy.float32'>}, {'shape': array([ 1, 10], dtype=int32), 'index': 253, 'name': 'TFLite_Detection_PostProcess:1', 'quantization': (0.0, 0), 'dtype': <class 'numpy.float32'>}, {'shape': array([ 1, 10], dtype=int32), 'index': 254, 'name': 'TFLite_Detection_PostProcess:2', 'quantization': (0.0, 0), 'dtype': <class 'numpy.float32'>}, {'shape': array([1], dtype=int32), 'index': 255, 'name': 'TFLite_Detection_PostProcess:3', 'quantization': (0.0, 0), 'dtype': <class 'numpy.float32'>}]

到目前为止一切顺利,但在我的 pipeline.config 文件中,我指定了以下 post_processing 设置

post_processing {
    batch_non_max_suppression {
        score_threshold: 9.99999993922529e-09
        iou_threshold: 0.6000000238418579
        max_detections_per_class: 100                                                            
        max_total_detections: 100
    }
    score_converter: SIGMOID
}

所以我希望检测的输出数量为 100,因为 运行 经典 tensorflow 中的相同模型给了我 100 个盒子。

有没有办法改变输出张量的大小?是在转换时还是 运行 时?

我在经典张量流的张量输出细节下面添加:

[<tf.Tensor 'prefix/detection_boxes:0' shape=<unknown> dtype=float32>, <tf.Tensor 'prefix/detection_scores:0' shape=<unknown> dtype=float32>, <tf.Tensor 'prefix/detection_classes:0' shape=<unknown> dtype=float32>, <tf.Tensor 'prefix/num_detections:0' shape=<unknown> dtype=float32>]

其中形状未知,这是有道理的,因为我们可以有 100 个或更少的盒子...

如能提供任何信息,我们将不胜感激。

如果已经有人问过类似的问题但我显然没有找到,请原谅。谢谢。

重新阅读 export_tflite_ssd_graph.py 脚本后,似乎有一个选项可以设置保留的最大检测数。

将此设置为 100 解决了我的问题。心情不好

对于那些感兴趣的人,我将导出命令从

更改为
python3 object_detection/export_tflite_ssd_graph.py \                                            
    --pipeline_config_path=$model_dir/pipeline.config \                                          
    --trained_checkpoint_prefix=$model_dir/model.ckpt \                                          
    --output_directory=$output_dir \                                                             
    --add_post_processing_op=true

python3 object_detection/export_tflite_ssd_graph.py \                                            
    --pipeline_config_path=$model_dir/pipeline.config \                                          
    --trained_checkpoint_prefix=$model_dir/model.ckpt \                                          
    --output_directory=$output_dir \                                                             
    --add_post_processing_op=true \                                                              
    --max_detections=100