2016-03-08 64 views
0

我的目标是为数据增强目的引入随机缩放和转换。为什么`tf.image.resize_images`设置图像形状?

distorted_image = tf.image.resize_images(distorted_image, random_scale, random_scale) 
distorted_image = tf.image.crop_to_bounding_box(distorted_image, random_y, random_x, 299, 299) 

这种失败'image' must be fully defined.交换行工作,但并没有做什么,我真正需要的。

distorted_image = tf.image.crop_to_bounding_box(distorted_image, random_y, random_x, 299, 299) 
distorted_image = tf.image.resize_images(distorted_image, random_scale, random_scale) 

所以好像resize_images失去了像张量的形状,然后crop_to_bouding_box失败。这是故意的,我错过了什么?调整大小后random_crop如何工作,但crop_to_bounding_box不是?

回答

2

tf.image.resize_images() op 确实设置图像形状,在this line的实现。 (这在TensorFlow 0.7添加。)

然而,如果任一new_heightnew_width参数是动态值,然后TensorFlow不能推断该维度单个形状,因此使用None该维度。我注意到在你的代码中,新的高度和宽度值被称为random_scale:如果在每个步骤上绘制一个新的随机值,那么该形状对于高度和宽度尺寸将具有None

注意,在这种情况下,运算tf.image.crop_to_bounding_box()不会因为工作—作为错误消息指示—当前的实现要求输入的形状来完全定义。正如我在a recent answer中指出的那样,最好的解决方法可能是使用实施tf.image.crop_to_bounding_box()的低层操作(特别是带有计算指数的tf.slice())。

+0

我结束了内联'random_crop'并做了小的修改,并且像魅力一样工作。谢谢! – Clash