2016-06-12 83 views
0

我想用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()但它也无法工作。 我列出我的代码和错误如下:Tensorflow:Tensor.set_shape()ValueError:'image'必须完全定义

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) 

它的工作原理。我认为重塑形状并不会改变Tensor中的价值秩序,对吧?也许它可能是解决方案。

回答

1

的问题是在

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

你覆盖方法tf.Tensor.set_shape并将其设置为一个值就行了。

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

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

之后,您的代码将工作。

I think reshape to the same shape does not change the order of values in Tensor, am I right?

是的,你说得对

+0

哦。非常感谢你。这是一个愚蠢的错误... –

相关问题