5
votes

L'objet 'ImageDataGenerator' n'a pas d'attribut 'flow_from_dataframe'

J'essaie de créer un classificateur d'images pour le défi Kaggle de détection du cancer. C'est le code que j'utilise.

`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'`

Cependant, chaque fois que je l'exécute, j'obtiens cette erreur:

`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'
                )`

J'ai cherché partout et je n'arrive pas à trouver une solution . La méthode s'appelle-t-elle quelque chose de différent maintenant?


1 commentaires

Quelle version de keras-preprocessing avez-vous installée?


3 Réponses :


2
votes

Si vous souhaitez utiliser la méthode flow_from_dataframe () , je vous suggère de faire ce qui suit:

Désinstaller le module de prétraitement keras actuel:

from keras_preprocessing.image import ImageDataGenerator


0 commentaires

2
votes

J'ai eu la même erreur en utilisant Keras 2.1.4. J'ai simplement mis à jour avec pip install keras --upgrade . Keras 2.2.4 ne donne pas la même erreur. Tout fonctionne maintenant.


0 commentaires

0
votes

Cela m'a également donné une erreur avec Keras 2.2.2 et keras-preprocessing 1.0.2. Avec cette configuration, après avoir désinstallé keras-preprocessing (pip uninstall keras-preprocessing) et réinstallé (mise à jour vers 1.1.2), il donnera:

ERROR: keras 2.2.2 has requirement keras_preprocessing==1.0.2, but you'll have keras-preprocessing 1.1.2 which is incompatible.

Il a installé avec succès la version 1.1.2 et le L'erreur "objet n'a pas d'attribut" n'apparaissait plus lors de l'utilisation de flow_from_dataframe.


0 commentaires