Hello,
I ran into an issue when trying to use ImageDataAugmentor with a single directory, asking it to split into a training and validation set.
I have figured out two ways to acomplish this, both with faults:
datagen = ImageDataAugmentor(
augment = AUGMENTATIONS,
validation_split=0.2)
train_generator = datagen.flow_from_directory(
'data',
subset="training",
target_size=image_size,
class_mode='binary',
seed=123)
validation_generator = datagen.flow_from_directory(
'data',
subset="validation",
target_size=image_size,
class_mode='binary',
seed=123)
This approach runs into one big issue, namely, the validation dataset now has augmentations applied, which goes against best practice. My second approach fares better in this department:
train_datagen = ImageDataAugmentor(
augment = AUGMENTATIONS,
validation_split=0.2)
test_datagen = ImageDataAugmentor(
validation_split=0.2)
train_generator = train_datagen.flow_from_directory(
'data',
subset="training",
target_size=image_size,
class_mode='binary',
seed=123)
validation_generator = test_datagen.flow_from_directory(
'data',
subset="validation",
target_size=image_size,
batch_size=1,
class_mode='binary',
seed=123)
However, I have discovered a second, large issue: although the flow_from_directory method can handle shuffling data, because the list of filenames is not shuffled prior to the split, the validation dataset receives the first 0.2 files listed alphabetically, which can lead to huge biases. This can be verified by printing validation_generator.filenames.
Please advise me on this issue. I think shuffling the dataset prior to applying the validation split would be the solution here.
Hello,
I ran into an issue when trying to use ImageDataAugmentor with a single directory, asking it to split into a training and validation set.
I have figured out two ways to acomplish this, both with faults:
This approach runs into one big issue, namely, the validation dataset now has augmentations applied, which goes against best practice. My second approach fares better in this department:
However, I have discovered a second, large issue: although the
flow_from_directorymethod can handle shuffling data, because the list of filenames is not shuffled prior to the split, the validation dataset receives the first 0.2 files listed alphabetically, which can lead to huge biases. This can be verified by printingvalidation_generator.filenames.Please advise me on this issue. I think shuffling the dataset prior to applying the validation split would be the solution here.