I'm new to CNNs, starting off with keras. I'm currently using ImageDataGenerator to import my train/validation folders (which each have 2 class subfolders for my binary classification task). Was wondering how can I import my train/validation files without using ImageDataGenerator? I'm aware that ImageDataGenerator is good for accuracy as it does some augmentation, but I want to compare the accuracy to a training set without any augmentations. Essentially I think I need to put all the images into an array, but not sure how to.

Basically I want to know what is the normal way to import training/validation data for images, so I can compare what is the accuracy difference with/without imagedatagen. I know with normal NN tasks it's easy as you can just do pd.read_csv().

I'm currently importing like so:

train_datagen = ImageDataGenerator(

test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(
        target_size=(150, 150),

validation_generator = test_datagen.flow_from_directory(
        target_size=(150, 150),

The docs for ImageDataGenerator suggest that no augmentation is done by default. So you could instantiate it without any augmentation parameters and keep the rest of your code for handling your directory structure:

train_datagen = ImageDataGenerator(rescale=1./255)

You are also allowed to write your own custom data generator and pass it to model.fit_generator(). Here is a nice tutorial.

Or if your data fits in memory you could write some simpler code possibly using keras.preprocessing.image.load_img to load all the images into an array and pass them to model.fit instead.

  • $\begingroup$ Ah, I see. Thanks Imran! However, for the purpose of developing my python skills, is there a way to achieve the task manually? $\endgroup$
    – Programmer
    Feb 2 '18 at 9:39
  • $\begingroup$ OK, I have updated my answer with some ideas. $\endgroup$
    – Imran
    Feb 2 '18 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.