Search code examples
python-3.xkeras

ImageDataGenerator is not defined


I am new to Keras and DL. I got this code from a keras document. wanted to run it on my system.

train_datagen = ImageDataGenerator(
    rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True)

test_datagen = ImageDataGenerator(rescale=1./255)

 train_generator = train_datagen.flow_from_directory('C:\\Users\\kashy\\Desktop\\Data\\train',target_size=(200,200),batch_size=batch_size,class_mode='binary')

 validation_generator = test_datagen.flow_from_directory('C:\\Users\\kashy\\Desktop\\Data\\validation',target_size=(200,200),batch_size=batch_size,class_mode='binary')

this is snippet of the code i was working on..

when i tried to run this on my system... i got the following error

Traceback (most recent call last):
 File "C:\Users\kashy\Desktop\trial1.py", line 29, in <module>
train_datagen = ImageDataGenerator(
NameError: name 'ImageDataGenerator' is not defined

can somebody help me ??

thanks !!!


Solution

  • ImageDataGenerator is a utility function defined within Keras. If you haven't imported it import it using

    from keras.preprocessing.image import ImageDataGenerator