how to apply imgaug augmentation to tf.dataDataset in Tensorflow 2.0
Please go to the TF Dataset documentation to see why you need to return shapes of your images when you are using tf.py_function
.
def tf_random_rotate_image(image, label):
im_shape = image.shape
[image,] = tf.py_function(random_rotate_image, [image], [tf.float32])
image.set_shape(im_shape)
return image, label
Is this due to non using eager mode? I thought Eager mode was default in TF2.0. Any ideas on how to approach this?
Yes, Dataset pre-processing is not executed in eager mode. This is, I assume, deliberate and certainly makes sense if you consider that Datasets can represent arbitrarily large (even infinite) streams of data.
Assuming that it is not possible/practical for you to translate the augmentation you are doing to tensorflow operations (which would be the first choice!) then you can use tf.numpy_function
to execute arbitrary python code (this is a replacement for the now deprecated tf.py_func
)