Can I use keras.Layers to build custom layer to mask to whole dataset and return masked dataset. That is
class AttnMask(Layer):
def __init__(self, img_size, attention_map):
super().__init__()
self.imgSize = img_size
self.attentionMap = attention_map
def call(self, x, *args, **kwargs):
return tf.math.multiply(x, self.attentionMap)
And to call the function
attenMaskLayer = attention_mask.AttnMask(img_size, attention_map)
maskedDataset = attenMaskLayer(dataset)
the dataset is retrieve from the directory hierarchy via tf.keras.preprocessing.image.ImageDataGenerator() and train_datagen.flow_from_directory() method.
Now it will return error ValueError: Only input tensors may be passed as positional arguments. The following argument value should be passed as a keyword argument: <keras.src.legacy.preprocessing.image.DirectoryIterator object at 0x00000169F47DF500> (of type <class 'keras.src.legacy.preprocessing.image.DirectoryIterator'>)