1

I want to load only images without labels in using data generator. I am training an autoencoder for image reconstruction on imagenet dataset. The architecture of Imagenet dataset is similar to given below.

data/ data/train/ data/train/red/ data/train/blue/ data/train/green/ data/train/pink/

I am using the code given below.

train_it = datagen.flow_from_directory(directory=”/dataset/Imagenet2012/train/”,
                                       target_size=(224, 224),
                                       color_mode=”rgb”,
                                       batch_size=32,
                                       class_mode=None,
                                       shuffle=True,
                                       seed=42
                                       )

I have changed class_mode to None but still, I am getting the error given below when I call the fit function. Code for my fit function is given below.

autoencoder.fit(val_it,val_it,
                batch_size=32,
                epochs=5,
                verbose=2,
                shuffle=True

)

And the error I am getting is

y argument is not supported when data is a generator or Sequence instance.Instead pass targets
as the second element of the generator.

I want to pass the original image as y variable in model.fit function. This dataset includes 1281167 images for training. When I try to load all the images using numpy, it is taking approx 6 hours to load. Please help me with this. Or please suggest me a code for custom data generator.

Thanks

1 Answers1

1

If you want your generator to pass the same Image as the X and y, you have to set class_mode='input'.

Also, since it is a generator, you do not have to pass the X and y explicitly. The class_mode='input' will handle that for you.


train_it = datagen.flow_from_directory(directory=”/dataset/Imagenet2012/train/”,
                                       target_size=(224, 224),
                                       color_mode=”rgb”,
                                       batch_size=32,
                                       class_mode="input",
                                       shuffle=True,
                                       seed=42)
autoencoder.fit(train_it,
                epochs=5,
                verbose=2)

Read more about it in the docs.

class_mode = "input" will be images identical to input images (mainly used to work with autoencoders).

Imanpal Singh
  • 1,105
  • 1
  • 12
  • 22