qubvel / segmentation_models

Segmentation models with pretrained backbones. Keras and TensorFlow Keras.
MIT License
4.67k stars 1.03k forks source link

per class iou, how? #505

Closed pure-rgb closed 2 years ago

pure-rgb commented 2 years ago

I have a segmentation map where the class is defined as an integer. As follows:

class_label = {
    'background' : 0, 
    'cat' : 1,
    'dog' : 2,
    'human' : 3,
    'bench' : 4
}

Before training, I made a one-hot encoded of the integer labels. So, the final label shape is (Batch Size, 5). That makes,

(Batch size, h, w,  0) < bg
(Batch size, h, w, 1) < cat
(Batch size, h, w, 2) < dog
(Batch size, h, w, 3) < human
(Batch size, h, w, 4) < bench

However, in order to get per class iou, I did as follows

metrics = [
           sm.metrics.IOUScore(threshold=0.5, class_indexes=1, name='cat'),
           sm.metrics.IOUScore(threshold=0.5, class_indexes=2, name='dog'),
           sm.metrics.IOUScore(threshold=0.5, class_indexes=3, name='human'),
           sm.metrics.IOUScore(threshold=0.5, class_indexes=4, name='bench'),
          ]

model.compile(..., metrics)

Is it ok? Or am I missing something?

pure-rgb commented 2 years ago

@qubvel

elliestath commented 2 years ago

hey, did you understand if it is ok to do so or not? I have a similar problem and I would like to know if the definition of per-class metrics would influence my training. Thanks!

pure-rgb commented 2 years ago

@elliestath yes, my assumption is right. It's ok.

geogob commented 11 months ago

Hi, did you use TensorFlow or the PyTorch version? I am using PyTorch, and this metrics definition is not executing