ImportError: cannot import name 'ImageDataGenerator' from 'keras.preprocessing.image'

2.7k views Asked by At

ImportError: cannot import name 'ImageDataGenerator' from 'keras.preprocessing.image' (/opt/conda/lib/python3.10/site-packages/keras/preprocessing/image/init.py)

Occurred when running in Kaggle. The issue is not present when running in google collab

It should ideally run without throwing any error

2

There are 2 answers

2
Ajay Tom On

Instead of this:

from keras.preprocessing.image import ImageDataGenerator

Tried this and working as expected:

from tensorflow.keras.preprocessing.image import ImageDataGenerator
0
Karti On

Same problem with me and then I change it and its working!

for keras-3.0.5 & tensorflow-2.16.1 the way for importing ImageDataGenerator is

from keras.src.legacy.preprocessing.image import ImageDataGenerator