'What should be the class mode for training a multilabel classification model?
I am working on an image classification task to classify among cars and buses. The problem is that in most car images, there is buses in the background and vice versa so the model gives wrong predictions. I came to know that in these cases we have to use multi-label classification instead on multiclass or binary classifier. So for multi label classifier the loss would be binary cross entropy and the activation will be sigmoid as per my understanding. I am confused regarding the class mode in the generator function.
train_generator = train_datagen.flow_from_directory(TRAIN_DATA_DIR,
target_size=(IMG_WIDTH,
IMG_HEIGHT),
batch_size=BATCH_SIZE,
shuffle=True,
seed=12345,
class_mode='categorical')
What should be the class mode in case of multi-label classification?
Solution 1:[1]
Take a look at using flow_from_dataframe
, for example:
train_generator = datagen.flow_from_dataframe(
df,
directory="/path/to/images",
x_col='Filenames',
y_col='labels',
class_mode='categorical',
shuffle=True,
target_size=(IMAGE_SIZE, IMAGE_SIZE),
batch_size=BATCH_SIZE,
subset='training',
seed=42)
where df is a pandas dataframe like this:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Timbus Calin |