Tensorflow对象检测api测试时间(Google对象检测运行时间)

Tensorflow对象检测api测试时间(Google对象检测运行时间),tensorflow,object-detection-api,Tensorflow,Object Detection Api,Google对象检测API: 测试代码: 我执行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')

Google对象检测API:

测试代码:

我执行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秒)。我认为这个结果是错误的,因为这个模型具有实时性

可能的原因我期待

  • GPU不能正常工作
  • 错误的测量测试运行时方法
  • 请告诉我如何准确测量检测时间。

    有关更多详细信息,请参阅下面的链接

    实际上,“对象检测教程笔记本”运行得非常慢,因为它不仅仅是实际的推理。它加载图像,将其放入numpy数组,加载图形(计算成本非常高),运行批大小为1的实际推断,并输出带有方框的图像

    这个脚本远远没有得到优化,也不是为了时间关键的目的。它只是为了对模型进行快速的视觉验证

    如果您想要为生产部署一个模型(时间通常很重要),这就是您想要的。使用Tensorflow服务,您可以轻松构建运行您的模型的GPU服务器。它有几个特点,使您的生活更轻松。因此,您只需向服务器传递一个映像,它就会返回模型的输出。后处理应该使用另一台服务器完成,因为GPU服务器通常非常昂贵。有几个很好的教程介绍了如何使用Tensorflow服务设置对象检测服务器。例如这需要一些与docker的经验,但你会与之相处

    希望这有帮助