Semantic segmentation- problem with ignoring multiple classes while evaluating accuracy

I am trying semantic segmentation on cityscapes dataset based on lesson-3 knowledge.
In camVid dataset there is only one class called ‘Void’ which should be ignored while calculating accuracy. But in cityscapes dataset, there are multiple classes to be ignored.

classes=['unlabeled', 'ego vehicle', 'rectification border', 'out of roi', 'static', 'dynamic', 'ground', 'road', 'sidewalk', 'parking', 'rail track', 'building', 'wall', 'fence', 'guard rail', 'bridge', 'tunnel', 'pole', 'polegroup', 'traffic light', 'traffic sign', 'vegetation', 'terrain', 'sky', 'person', 'rider', 'car', 'truck', 'bus', 'caravan', 'trailer', 'train', 'motorcycle', 'bicycle', 'license plate']

classes_to_ignore=['unlabeled', 'ego vehicle', 'rectification border', 'out of roi', 'static', 'dynamic', 'ground','polegroup', 'license plate']

I tried defining accuracy matrices like this-

name2id = {v:k for k,v in enumerate(classes)}
unlabeled = name2id['unlabeled']
ego_v = name2id['ego vehicle']
rectification = name2id['rectification border']
roi = name2id['out of roi']
static = name2id['static']
dynamic = name2id['dynamic']
ground = name2id['ground']

    def acc_cityscapes(input, target):
        target = target.squeeze(1)
        mask = (target!=unlabeled and target!= ego_v and target!= rectification and target!=roi and target !=static and target!=dynamic and target!=ground)
        return (input.argmax(dim=1)[mask]==target[mask]).float().mean()

But getting this error

How can I define accuracy ignoring those unwanted classes?

1 Like

You are using a logical and operation of python to do the bit-wise & operation.
I would simply use numpy’s .isin() method to build the mask which is probably way more efficient.

Hey raihan,
I have the same problem… :frowning:

Have you found a solution?