flow_from_dataframe() error: If class_mode="categorical", y_col column values must be type string, list or tuple

Viewed 559

I'm trying to use flow_from_dataframe() to train my model from a .csv in which each image belong to just one category. You can check a sample picture of the .csv here.

I think class_mode should be set to categorical, since Keras documentation says the following:

"categorical": 2D NumPy array of one-hot encoded labels. Supports multi-label output.

The problem is that, although the .csv is read as string, the following error appears when using categorical:

If class_mode="categorical", y_col="['MEL', 'NV', 'BCC', 'AK', 'BKL', 'DF', 'VASC', 'SCC', 'UNK']" column values must be type string, list or tuple.

It works fine when setting class_mode = 'raw', but isn't categorical the most appropiate according to the documentation? I've also tried this solution but doesn't work for me.

Here is my code:

    df_train = pd.read_csv('/content/truth.csv',dtype=str)

    train_generator = datagen_train.flow_from_dataframe(
        dataframe = df_train,
        directory = "/content/ISIC_2019_Training_Input",
        x_col = 'image',
        y_col = ['MEL','NV','BCC','AK','BKL','DF','VASC','SCC','UNK'],
        batch_size = 32,
        shuffle = True,
        class_mode = "categorical",
        target_size = (224,224)
    )

Thanks in advance!

0 Answers
Related