I am trying to build a semantic segmentation model using tensorflow.keras. The dataset that I am using has the images and masks stored in separate directories and each filename has is an id for mapping an image file with its respective mask.
Following is the structure of my dataset directory:
new
- rendered_imges
- render
- image_1.tif
- image_2.tif
- image_3.tif
- ground_truths
- masks
- mask_1.tif
- mask_2.tif
- mask_3.tif
In the above directory structure, image_{i}.tif corresponds to mask_{i}.tif.
I tried writing an ImageDataGenerator for augmenting both the images and their respective masks in exactly the same way. My approach was the following:
SEED = 100
image_data_generator = ImageDataGenerator(
width_shift_range = 0.1,
height_shift_range = 0.1,
rotation_range = 10,
zoom_range = 0.1
).flow_from_directory('./new/rendered_images', batch_size = 16, target_size = (150, 150), seed = SEED)
mask_data_generator = ImageDataGenerator(
width_shift_range = 0.1,
height_shift_range = 0.1,
rotation_range = 10,
zoom_range = 0.1
).flow_from_directory('./new/ground_truths', batch_size = 16, target_size = (150, 150), seed = SEED)
With the above approach although I am getting the same augmentations applied to both image and mask, the images are not getting paired with their respective masks according to their filenames. It would be great if someone can suggest a way to do this properly using Keras or Tensorflow.