tf.image.crop_and_resize()返回断开的裁剪图像

时间:2018-01-09 07:37:07

标签: tensorflow object-detection bounding-box

我尝试使用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())

执行上面的代码时,结果如下图所示: enter image description here

如您所见,第二个是裁剪后的图像被破坏了。边界框的值是变量' _boxes'的第一个值。这是 " _boxes [0]"

我有什么遗失的吗?我一直坚持这个问题。

2 个答案:

答案 0 :(得分:0)

似乎"standard"期望像素值在[0,1]范围内。将代码更改为

tf.image.crop_and_resize

为我解决了这个问题。

答案 1 :(得分:0)

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