I want to normalize and standardize the images of each batch from Dataset. The formula is: Xi = (Xi - mean) / std (pixel-level global mean (SD))
I use ImageDataGenerator and flow_from_directory as below:
datagen = ImageDataGenerator(featurewise_center=True,
featurewise_std_normalization=True,
vertical_flip=True, #data augmentation
validation_split= 0.1, #validation
rescale=1./255, #Scaling
horizontal_flip=True) #data augmentation
train_gen = datagen.flow_from_directory(
train_data_dir,
target_size=(img_height,img_width),
batch_size=batch_size,
class_mode='binary',
subset='training',
shuffle=True)
valid_gen = datagen.flow_from_directory(...)
model = Model(...) #I use ResNet and some fully connected layer
model.compile(...)
trainer= model.fit(train_gen,
validation_data= valid_gen,
epochs=16,
verbose=2)
As what I need, I use featurewise_center and featurewise_std_normalization in ImageDataGenerator. but it seems that these options do NOT work with flow_from_directory ! also I should use flow_from_directory because my data is heavy (I don't have enough RAM for processing whole the dataset at the same time).
Can you give me some recommendations or advice for solving this problem,. i.e how to implement pixel-level global mean (SD) for pictures in this method?