gpt4 book ai didi

python - “ImageDataGenerator”对象没有属性 'flow_from_dataframe'

转载 作者:行者123 更新时间:2023-11-30 08:34:38 25 4
gpt4 key购买 nike

我正在尝试为癌症检测 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

(可以看到该方法可用 in the source code here )

然后导入ImageDataGenerator,如下所示:

from keras_preprocessing.image import ImageDataGenerator

关于python - “ImageDataGenerator”对象没有属性 'flow_from_dataframe',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54660448/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com