I am trying to build an image classifier for the Cancer Detection Kaggle Challenge. This is the code that I am using.
`train_datagen = ImageDataGenerator(rescale=1./255,
validation_split=0.15
)
test_datagen = ImageDataGenerator(rescale=1./255)
train_path = MAIN_DIR + '/CancerTrain'
valid_path = MAIN_DIR + '/CancerTrain'
train_generator = train_datagen.flow_from_dataframe(
dataframe = train_labels,
directory=train_path,
x_col = 'id',
y_col = 'label',
has_ext=False,
subset='training',
target_size=(96, 96),
batch_size=64,
class_mode='binary'
)
validation_generator = train_datagen.flow_from_dataframe(
dataframe=df,
directory=valid_path,
x_col = 'id',
y_col = 'label',
has_ext=False,
subset='validation', # This is the trick to properly separate train and validation dataset
target_size=(96, 96),
batch_size=64,
shuffle=False,
class_mode='binary'
)`
However, whenever I run it I get this error:
`AttributeError Traceback (most recent call last)
<ipython-input-22-eb9c70d0ad1c> in <module>()
15 )
16
---> 17 train_generator = train_datagen.flow_from_dataframe(
18 dataframe = train_labels,
19 directory=train_path,
AttributeError: 'ImageDataGenerator' object has no attribute 'flow_from_dataframe'`
I have looked everywhere and can't seem to find a solution. Is the method called something different now?
If you want to make use of the flow_from_dataframe()
method I suggest you do the following:
Uninstall the current keras-preprocessing module:
pip uninstall keras-preprocessing
Install the keras-preprocessing module from the following git link:
pip install git+https://github.com/keras-team/keras-preprocessing.git
(you can see the method is available in the source code here)
and then import the ImageDataGenerator
as follows:
from keras_preprocessing.image import ImageDataGenerator
I had the same error using Keras 2.1.4. I simply upgraded with pip install keras --upgrade
. Keras 2.2.4 does not give the same error. It all works now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With