“ImageDataGenerator”对象没有属性“flow_from_dataframe”

2024-06-28

我正在尝试为癌症检测 Kaggle 挑战赛构建一个图像分类器。这是我正在使用的代码。

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

但是,每当我运行它时,我都会收到此错误:

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

我到处都找过了,似乎找不到解决方案。现在该方法的名称是否有所不同?


如果您想使用flow_from_dataframe()方法我建议您执行以下操作:

卸载当前的 keras-preprocessing 模块:

pip uninstall keras-preprocessing

从以下 git 链接安装 keras-preprocessing 模块:

pip install git+https://github.com/keras-team/keras-preprocessing.git

(可以看到该方法可用在这里的源代码中 https://github.com/keras-team/keras-preprocessing/blob/master/keras_preprocessing/image/image_data_generator.py)

然后导入ImageDataGenerator如下:

from keras_preprocessing.image import ImageDataGenerator
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“ImageDataGenerator”对象没有属性“flow_from_dataframe” 的相关文章

随机推荐