【问题标题】:tf.image.crop_and_resize() returns broken cropped imagetf.image.crop_and_resize() 返回损坏的裁剪图像
【发布时间】:2018-06-18 04:52:34
【问题描述】:

我正在尝试使用由 TensorFlow API 实现的 Faster R-CNN 的边界框来捕获裁剪后的图像。 (特别是我从tensorflow关注并定制了this tutorial)

我按照上面教程的代码如下:

for image_path in TEST_IMAGE_PATHS[0:1]:
            image = Image.open(image_path)
            image_np = load_image_into_numpy_array(image)
            image_np_expanded = np.expand_dims(image_np, axis=0)

            (_image_tensor,_boxes, scores, classes, num) = sess.run(
              [image_tensor,detection_boxes, detection_scores, detection_classes, num_detections],
              feed_dict={image_tensor: image_np_expanded})

            test = tf.image.crop_and_resize(image=image_np_expanded,
                                                             boxes=[[0.27640104,0.2573258,0.57859987,0.7340185]],
                                                             box_ind=[0],
                                                             crop_size=[50,50])
            plt.figure()
            plt.imshow(image_np)

            plt.figure()
            plt.imshow(test[0].eval())

上面的代码执行后,结果如下图:

如您所见,裁剪后的第二张图片已损坏。边界框的值是变量 '_boxes' 的第一个值,即 "_boxes[0]"

我有什么遗漏吗?我被这个问题困住了。

【问题讨论】:

    标签: tensorflow object-detection bounding-box


    【解决方案1】:

    tf.image.crop_and_resize 似乎需要 [0,1] 范围内的像素值。将代码更改为

    test = tf.image.crop_and_resize(image=image_np_expanded/255., ...)
    

    为我解决了问题。

    【讨论】:

    • 它也为我解决了问题。谢谢,但你为什么使用“256。”?我确实使用了“255”。
    • 感谢您的修复,您是如何通过看到损坏的图像提出解决方案的?
    • 我不只是看到它,我自己尝试过并尝试过它,直到它起作用。这实际上有点令人惊讶,因为crop_and_resize 只应该执行线性插值,原则上不需要检查饱和度。但显然在此过程中的某个地方正在执行饱和截止。
    • 感谢您的诚意!
    【解决方案2】:

    TensorFlow 提供 tf.image.convert_image_dtype 用于 int 和 float 之间的转换。在转换回 int(并使用saturate=True)时特别有用。但我建议在任一方向使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-06
      • 1970-01-01
      • 1970-01-01
      • 2017-05-22
      • 2017-03-13
      • 1970-01-01
      • 2018-01-08
      • 1970-01-01
      相关资源
      最近更新 更多