【问题标题】:Tensorflow object detection api test time (Google object detection running time)Tensorflow object detection api test time(谷歌物体检测运行时间)
【发布时间】:2018-08-14 12:17:17
【问题描述】:

Google 对象检测 API:

https://github.com/tensorflow/models/tree/master/research/object_detection

测试代码:

https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb

我执行了 Google Object Detection API 的测试代码如下:

with detection_graph.as_default():
  with tf.Session(graph=detection_graph) as sess:
    start = time.time()
    image_tensor = 
    detection_graph.get_tensor_by_name('image_tensor:0')
    # Each box represents a part of the image where a particular 
    #object was detected.
    detection_boxes = 
    detection_graph.get_tensor_by_name('detection_boxes:0')        
    detection_scores = 
    detection_graph.get_tensor_by_name('detection_scores:0')
    detection_classes = 
    detection_graph.get_tensor_by_name('detection_classes:0')
    num_detections = 
    detection_graph.get_tensor_by_name('num_detections:0')

    for image_path in TEST_IMAGE_PATHS:
      image = Image.open(image_path)
      image_np = load_image_into_numpy_array(image)
      image_np_expanded = np.expand_dims(image_np, axis=0)
      # Actual detection.
      (boxes, scores, classes, num) = sess.run(
          [detection_boxes, detection_scores, detection_classes, 
         num_detections], feed_dict={image_tensor: image_np_expanded})

      # Visualization of the results of a detection.
      vis_util.visualize_boxes_and_labels_on_image_array(
          image_np,
          np.squeeze(boxes),
          np.squeeze(classes).astype(np.int32),
          np.squeeze(scores),
          category_index,
          use_normalized_coordinates=True,
          line_thickness=2)

    print("--- %s seconds ---" % (time.time() - start))    

根据谷歌研究论文,谷歌对象检测 API 支持的所有模型都具有实时性能! 但是,上面的测试代码显示检测一张图像大约需要 3 秒(实际上是 200 帧->130 秒,400 帧->250 秒)。我认为这个结果是错误的,因为这个模型具有实时性能。

我预期的可能原因...

  1. GPU 无法正常工作。
  2. 错误的测量测试运行时方法

请告诉我如何准确测量检测时间。

更多详情请参考以下链接 https://github.com/tensorflow/models/issues/3531

【问题讨论】:

    标签: tensorflow object-detection-api


    【解决方案1】:

    实际上,“object_detection_tutorial notebook”运行非常缓慢,因为它不仅仅是实际的推理。它加载图像,将其放入一个 numpy 数组中,加载图形(计算量非常大),以 1 的批大小运行实际推理,并输出带有框的图像。

    此脚本远未优化,也不适用于时间紧迫的目的。它只是用于对模型进行快速视觉验证。

    如果您想为生产部署模型(通常需要时间),Tensorflow Serve 就是您要找的。使用 Tensorflow 服务,您可以轻松构建运行模型的 GPU 服务器。它有几个功能可以让您的生活更轻松。因此,您只需将图像传递给您的服务器,它就会返回模型的输出。后处理应该在另一台服务器上完成,因为 GPU 服务器通常非常昂贵。那里有几个很好的教程,描述了如何使用 Tensorflow Serve 设置对象检测服务器。例如here。它需要一些 docker 经验,但你会相处得很好!

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-20
      • 1970-01-01
      • 2018-01-28
      • 2018-07-28
      • 1970-01-01
      相关资源
      最近更新 更多