'ImageDataGenerator'对象没有属性'flow_from_dataframe' [英] 'ImageDataGenerator' object has no attribute 'flow_from_dataframe'

查看:702
本文介绍了'ImageDataGenerator'对象没有属性'flow_from_dataframe'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to build an image classifier for the Cancer Detection Kaggle Challenge. This is the code that I am using.

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

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

However, whenever I run it I get this error:

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

我到处都看过,似乎找不到解决方法.现在调用的方法有所不同吗?

I have looked everywhere and can't seem to find a solution. Is the method called something different now?

推荐答案

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

If you want to make use of the flow_from_dataframe() method I suggest you do the following:

卸载当前的keras预处理模块:

Uninstall the current keras-preprocessing module:

pip uninstall keras-preprocessing

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

Install the keras-preprocessing module from the following git link:

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

(您可以看到该方法可用在源代码中)

(you can see the method is available in the source code here)

,然后按如下所示导入ImageDataGenerator:

and then import the ImageDataGenerator as follows:

from keras_preprocessing.image import ImageDataGenerator

这篇关于'ImageDataGenerator'对象没有属性'flow_from_dataframe'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆