python - “ImageDataGenerator”对象没有属性“flow_from_dataframe”
问题描述
我正在尝试为 Cancer Detection Kaggle Challenge 构建一个图像分类器。这是我正在使用的代码。
`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
(您可以在此处的源代码中看到该方法)
然后导入ImageDataGenerator
如下:
from keras_preprocessing.image import ImageDataGenerator
推荐阅读
- javascript - 如何从 Redux/react 中的数组状态中删除对象
- javascript - 如何在 chrome 上查看我在亚马逊 as3 上上传的 zip 文件?
- express - 在没有提示的情况下登录用户
- python - 如何通过 Python 运行 C# 控制台应用程序?
- android - TransitionSet - Outgoing Activity 在不指定的情况下淡出
- c++ - 如何从 C/C++ 中的 MAC 地址获取供应商 OUI 和设备名称
- android - 在房间数据库中存储多个图像
- nginx - Keycloak AdminURL 无限重定向循环(nginx 代理)
- sql - 如何在 postgresql 中旋转 2 行的简单表?
- visual-studio - Visual Studio 安装程序 - 如何恢复丢失的组件