Reputation: 19
I'm trying to give a directory as input to ImageDataGenerator.flow_from_directory but I'm unable to do it.
train_data_dir = "/train"
validation_data_dir = "/test"
train_generator = ImageDataGenerator.flow_from_directory(directory=train_data_dir,
target_size = (img_height, img_width),
batch_size = batch_size,
class_mode = "categorical")
validation_generator = ImageDataGenerator.flow_from_directory(directory=validation_data_dir,
target_size = (img_height, img_width),
class_mode = "categorical")
The above code returns the following error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-126-39ed634afa51> in <module>
2 target_size = (img_height, img_width),
3 batch_size = batch_size,
----> 4 class_mode = "categorical")
5
6 validation_generator = ImageDataGenerator.flow_from_directory(validation_data_dir,
TypeError: flow_from_directory() missing 1 required positional argument: 'self'
How do I solve this?
Upvotes: 1
Views: 3102
Reputation: 2642
You can not directly call flow_from_directory method from ImageDataGenerator. You'll have to create instance of this class first. Try this:
train_gen = ImageDataGenerator()
val_gen = ImageDataGenerator()
you can add parameters for augmentation here. Refer: https://keras.io/preprocessing/image/
After that you can use flow_from_directory.
train_generator = train_gen.flow_from_directory(directory=train_data_dir,
target_size = (img_height, img_width),
batch_size = batch_size,
class_mode = "categorical")
Upvotes: 2