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()
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: If class_mode="categorical", y_col="label" column values must be type string, list or tuple.
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?
Thanks
Solution
read csv with dtype e.g. str:
data = pd.read_csv('./Hand_Annotations_2.csv',dtype=str,names=colnames, header=None)