Problem: I am training a model for multilabel image recognition. My images are therefore associated with multiple y labels. This is conflicting with the conveni
You could write a custom generator class that would read the files in from the directory and apply the labeling. That custom generator could also take in an ImageDataGenerator instance which would produce the batches using flow().
I am imagining something like this:
class Generator():
def __init__(self, X, Y, img_data_gen, batch_size):
self.X = X
self.Y = Y # Maybe a file that has the appropriate label mapping?
self.img_data_gen = img_data_gen # The ImageDataGenerator Instance
self.batch_size = batch_size
def apply_labels(self):
# Code to apply labels to each sample based on self.X and self.Y
def get_next_batch(self):
"""Get the next training batch"""
self.img_data_gen.flow(self.X, self.Y, self.batch_size)
Then simply:
img_gen = ImageDataGenerator(...)
gen = Generator(X, Y, img_gen, 128)
model.fit_generator(gen.get_next_batch(), ...)
*Disclaimer: I haven't actually tested this, but it should work in theory.