“ImageDataGenerator”对象没有“flow”“from”“dataframe”“属性”

2024-09-30 16:27:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为癌症检测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'
                )`

但是,每当我运行它时,都会出现以下错误:

^{pr2}$

我到处找遍了,似乎找不到解决办法。这个方法现在叫什么不同了吗?在


Tags: pathfalsedataframesizemaindirtraincol
2条回答

我在使用keras2.1.4时也遇到了同样的错误。我只是用pip install keras upgrade升级。Keras 2.2.4没有给出相同的错误。现在一切都好了。在

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

卸载当前keras预处理模块:

pip uninstall keras-preprocessing

从以下git链接安装keras预处理模块:

^{2}$

(您可以看到方法是可用的in the source code here

然后导入ImageDataGenerator,如下所示:

from keras_preprocessing.image import ImageDataGenerator

相关问题 更多 >