【问题标题】:Tensor-flow object detection API match resolution of output images to the input test images张量流对象检测 API 将输出图像的分辨率与输入测试图像匹配
【发布时间】:2018-07-17 22:57:40
【问题描述】:

我正在使用 Tensorflow 对象检测 API,具体来说,我指的是这个 Ipython 笔记本的检测部分 (https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb) 我在 test_image 文件夹中输入了图像,该图像的分辨率为 1737x979。但是,当我通过 Tensorflow 对象检测 API 的检测部分运行此代码时。我得到的图像尺寸为 1200x800。如何以与输入相同的比例输出图像(在这种情况下,输出图像的分辨率应为 1737x979 而不是 1200x800)

IMAGE_SIZE = (12, 8) #output image size in inches


with detection_graph.as_default():
  with tf.Session(graph=detection_graph) as sess:
    # Definite input and output Tensors for detection_graph
    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')
    # Each score represent how level of confidence for each of the objects.
    # Score is shown on the result image, together with the class label.
    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')

    #myFile = open('example2.csv', 'w')
    i=0
    #boxeslist=[]
    new_boxes = []
    for image_path in TEST_IMAGE_PATHS:
      image = Image.open(image_path)
      # the array based representation of the image will be used later in order to prepare the
      # result image with boxes and labels on it.
      image_np = load_image_into_numpy_array(image)
      # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
      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=4)
      plt.figure(figsize=IMAGE_SIZE)
      plt.imshow(image_np)

我需要更改 IMAGE_SIZE 以保持输入图像的尺寸。 另外,输出图像是白色背景的图形,如何去除这个白色轮廓?

【问题讨论】:

    标签: python-3.x tensorflow computer-vision deep-learning object-detection


    【解决方案1】:

    如果您仔细观察输出图像与我们在 matplotlib 中绘制图形时得到的图像相似,则可以解决此问题。放大,你会看到图像的 x 和 y 尺寸,无论你改变 IMAGE_SIZE 变量,这些 x 和 y 尺寸都保持不变

    【讨论】:

      猜你喜欢
      • 2018-06-13
      • 2018-01-10
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多