Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get ValueError('\'image\' must be fully defined.') when transforming image in Tensorflow?

Tags:

tensorflow

I want to do real time data augmentation by chaining different image transformation operators in tensorflow. My code begins with image decoding and then runs different transformations but it throw a ValueError('\'image\' must be fully defined.'). Here is an example to reproduce this error :

def decode_and_augment(image_raw):
  decoded = tf.image.decode_jpeg(image_raw)
  flipped = tf.image.random_flip_left_right(decoded)
  return flipped
like image 729
jrabary Avatar asked Jan 12 '16 14:01

jrabary


People also ask

How does Tensorflow store images?

Internally, images are either stored in as one float32 per channel per pixel (implicitly, values are assumed to lie in [0,1) ) or one uint8 per channel per pixel (values are assumed to lie in [0,255] ). TensorFlow can convert between images in RGB or HSV or YIQ.


1 Answers

This error arises because the tf.image.random_flip_left_right() op checks the static shape of its input when you build the graph, and tf.image.decode_jpeg() produces tensors that have a data dependency on the contents of image_raw so it the shape isn't statically known. Currently the only way to work around this is to set the static shape of the decoded tensor using Tensor.set_shape(), as follows:

decoded = tf.image.decode_jpeg(image_raw)
decoded.set_shape([IMAGE_HEIGHT, IMAGE_WIDTH, NUM_CHANNELS])
flipped = tf.image.random_flip_left_right(decoded)

The downside of this is that all images must now have the same size (and number of channels).

Many of the image ops don't follow the same gradual and dynamic shape inference as the rest of TensorFlow (which allows you to have unknown shapes or dimensions, assumes that the program is correct as you build the graph, and checks the real shapes at runtime). This is considered a bug at the present time, and we'll figure out a way to fix it.

like image 161
mrry Avatar answered Oct 21 '22 03:10

mrry