使用flow_from_dataframe,什么是正确的“值"?为y_col [英] Using flow_from_dataframe what is the correct "value" for y_col

查看:337
本文介绍了使用flow_from_dataframe,什么是正确的“值"?为y_col的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用熊猫读取一个csv文件,并给出存储在colname

I am reading in a csv file with pandas, and give the column names stored in colname

colnames=['file', 'label'] 
# Read data from file 
data = pd.read_csv('./Hand_Annotations_2.csv',names=colnames, header=None)
# Preview the first 5 lines of the loaded data 
data.head()

然后,我使用ImageDataGenerator()flow_fromdataframe()来获取批量数据

Then, I use ImageDataGenerator() and flow_fromdataframe() to get batches of data

train_generator=datagen.flow_from_dataframe(dataframe=data,
                                            directory=None, 
                                            x_col=colnames[0], 
                                            y_col=colnames[1],
                                            class_indices=IDmap,
                                            class_mode="categorical", target_size=(224,224), batch_size=32)

但是我得到一个错误,如下:

But I get an error, as below:

TypeError:如果class_mode ="categorical",则y_col ="label"列值 必须为字符串,列表或元组.

TypeError: If class_mode="categorical", y_col="label" column values must be type string, list or tuple.

但是我的y_col是一个字符串.如果我只输入"label",则会收到相同的错误.它似乎也可以与x_col一起使用.

But my y_col is a string. I get the same error if I just enter "label". It also seems to work with x_col.

有人可以指出我的错误吗?

Can someone point me to my mistake?

谢谢

解决方案

读取具有dtype的csv,例如str:

read csv with dtype e.g. str:

data = pd.read_csv('./Hand_Annotations_2.csv',dtype=str,names=colnames, header=None)

推荐答案

您可以检查github中的代码以查看其实际检查内容,特别是

You can check the code in github for what it is actually being checked, specially here. Keras preprocessing is checking that all the values have allowed types (str, list or tuple), so the check is failing, you have to check that all values of the y_col column have the right type.

这篇关于使用flow_from_dataframe,什么是正确的“值"?为y_col的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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