我正在尝试为癌症检测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'`我已经到处找了,但似乎找不到解决方案。这个方法现在是不是有什么不同了?
发布于 2019-02-13 07:55:31
如果您想使用flow_from_dataframe()方法,我建议您执行以下操作:
卸载当前keras预处理模块:
pip uninstall keras-preprocessing从以下git链接安装keras-preprocessing模块:
pip install git+https://github.com/keras-team/keras-preprocessing.git(你可以在in the source code here上看到这个方法)
然后按如下方式导入ImageDataGenerator:
from keras_preprocessing.image import ImageDataGenerator发布于 2019-07-02 17:17:35
我在使用Keras 2.1.4时也遇到了同样的错误。我只是简单地升级了pip install keras --upgrade。Keras 2.2.4没有给出相同的错误。现在都能用了。
发布于 2020-07-29 13:39:43
这也给了我一个关于Keras 2.2.2和keras-preprocessing 1.0.2的错误。使用该配置,在卸载keras-preprocessing (pip uninstall keras-preprocessing)并重新安装(更新到1.1.2)之后,它将提供:
ERROR: keras 2.2.2 has requirement keras_preprocessing==1.0.2, but you'll have keras-preprocessing 1.1.2 which is incompatible.它成功安装了1.1.2版本,使用flow_from_dataframe时不再出现"object has no attribute“错误。
https://stackoverflow.com/questions/54660448
复制相似问题