I am using tf.data.Dataset
to create my dataset and training a CNN with keras. I need to apply masks on the images, and the mask depends on the shape of the image, there are no predefined pixel coordinates.
When looking for an answer on the internet, I found that there are 2 ways of accessing shapes of images in TensorFlow (in training time):
Using eager execution (which is not enabled by default in my case, I'm using tf v 12.0)
Using a session
I do not want to use eager execution because it slows down training, and cannot use a session because I train and test the CNN using Keras (I feed the data to model.train()
using iterators of tf.data.Dataset
).
As a consequence, I have no way of knowing the shapes of images, and thus cannot access specific pixels for data augmentation.
I wrote a function using OpenCV (cv2) that applies the masks. Is there a way to integrate it with the TensorFlow data pipeline?
EDIT : I found a solution. I used tf.py_func to wrap the python functions