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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With