【问题标题】:Tensorflow: Tensor.set_shape() ValueError: 'image' must be fully definedTensorflow:Tensor.set_shape()ValueError:'image'必须完全定义
【发布时间】:2016-06-12 08:46:33
【问题描述】:

我想使用tf.image.resize_image_with_crop_or_pad 裁剪输入图像的一部分。但是出现了一个错误:ValueError: 'image' must be fully defined。我检查了Why do I get ValueError('\'image\' must be fully defined.') when transforming image in Tensorflow? 我添加了Tensor.set_shape() 但它也无法工作。 我列出我的代码和错误如下:

example = tf.image.decode_png(file_contents, channels=3)
example.set_shape = ([256,256,3])
crop_image = tf.image.resize_image_with_crop_or_pad(example, crop_size, crop_size)

错误:

File "/home/kang/Documents/work_code_PC1/VGG_tensorflow_UCMerced/readUClandUsedImagetxt.py", line 97, in _input_pipeline
    crop_image = tf.image.resize_image_with_crop_or_pad(image, crop_size, crop_size)

  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/image_ops.py", line 534, in resize_image_with_crop_or_pad
    _Check3DImage(image, require_static=True)

  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/image_ops.py", line 221, in _Check3DImage
    raise ValueError('\'image\' must be fully defined.')

ValueError: 'image' must be fully defined.

即使我将某些形状设置为图像,我也不知道为什么会出现错误。 但是,我这样测试代码:

example = tf.image.decode_png(file_contents, channels=3)
example = tf.reshape(example, [256,256,3])
crop_image = tf.image.resize_image_with_crop_or_pad(example, crop_size, crop_size)

它有效。我认为重塑为相同的形状不会改变张量中值的顺序,对吗?也许它可以成为解决方案。

【问题讨论】:

    标签: python tensorflow deep-learning


    【解决方案1】:

    问题出在一线

    example.set_shape = ([256,256,3])
    

    您正在覆盖方法 tf.Tensor.set_shape 并将其设置为一个值。

    set_shape 是一种方法,因此您必须正确调用它:

    example.set_shape([256,256,3])
    

    之后,你的代码就可以工作了。

    我认为 reshape 到相同的形状不会改变 Tensor 中值的顺序,对吗?

    是的,你是对的

    【讨论】:

      猜你喜欢
      • 2019-04-02
      • 1970-01-01
      • 2021-06-09
      • 2014-09-23
      • 2021-03-16
      • 1970-01-01
      • 2021-05-09
      • 2018-08-21
      • 2017-12-28
      相关资源
      最近更新 更多