首页 > 解决方案 > 对象检测在笔记本电脑上运行非常缓慢

问题描述

我逐步完成了以下教程:https ://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_pets.md

然后我尝试使用以下方法运行推理:https ://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb

这运行得非常快(每张图像大约 1 秒)。我注意到代码正在从http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2017_11_17拉下一个预训练模型(不是我在第一个教程中尝试过的模型)。

当我使用教程中导出的图表加载并执行推理时,大约需要 10 秒才能完成。我使用以下方法导出了图表:

python object_detection/export_inference_graph.py \
    --input_type image_tensor \
    --pipeline_config_path object_detection/samples/configs/faster_rcnn_resnet101_pets.config \
    --trained_checkpoint_prefix model.ckpt-${CHECKPOINT_NUMBER} \
    --output_directory exported_graphs

我正在使用以下代码进行推理:

model = tf.saved_model.load(
        os.path.join(os.getcwd(), 'exported_graphs', 'saved_model'))
model = model.signatures['serving_default']

output_dict = model(input_tensor)

我正在运行带有 HighSierra 的 MacOS。我是否以次优方式导出了图表?我的机器是不是不够快?我仍然是一个初学者,所以任何方向都会非常有帮助 - 我可能会错过一些非常基本的东西。

标签: tensorflow

解决方案


您首先运行的图表ssd_mobilenet_v1花费了您大约 1 秒。另一张图faster_rcnn_resnet101花了你大约 10 秒。他们两个是完全不同的架构。faster_rcnn_resnet101运行速度会比ssd_mobilenet_v1.


推荐阅读