fast.ai library has a pretty easy to use yet powerful capabilities for semantic image segmentation. By default all the classes are treated the same. The network is trained to predict all the labels.
Sometimes it’s important to provide non-complete labeling. That means for some areas the label is undefined. The performance of the network should exclude that areas in the loss and accuracy computation. That allows the network predict any other class in those areas.
How to exclude certain class (“unlabeled area”) from the loss function?
The loss for image segmentation is refined as CrossEntropyFlat(axis=1)
with the following classes:
|
|
To exclude some class from the loss function we can follow the advice from the fast ai forum:
hasLabel = (t != UNLABELED).float()
loss = mse(p * hasLabel, t * hasLabel)
More specifically one can create a copy of the FlattenedLoss and patch it:
|
|
Now use that class in your learner:
|
|