【问题标题】:Why doesn't `tf.image.resize_images` set the image shape?为什么 tf.image.resize_images 不设置图像形状?
【发布时间】:2016-03-08 09:57:48
【问题描述】:

我的目标是为数据增强目的引入随机缩放和转换。

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 却不行?

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    tf.image.resize_images() 操作 确实 设置图像形状,在实现的 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())。

    【讨论】:

    • 我最终内联 random_crop 并进行了一些小修改,这就像一个魅力。谢谢!
    猜你喜欢
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    • 2012-08-14
    • 2018-02-03
    相关资源
    最近更新 更多