question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is the calculation of mean IoU reasonable?

See original GitHub issue

❓ Questions & Help

in the function of mean_iou, I mean the code “iou[torch.isnan(iou)] = 1”, is it reasonable,? when I test my model, some type has a bad segmentation, like board on s3dis dataset, it should get a very low score, but get a high score(0.95), in IOU, there are many ‘nan’ value,the code change them to 1, so it’s very high score. so is it reasonable to change ‘nan’ to 1?

def mean_iou(pred, target, num_classes, batch=None): r""“Computes the mean intersection over union score of predictions. Args: pred (LongTensor): The predictions. target (LongTensor): The targets. num_classes (int): The number of classes. batch (LongTensor): The assignment vector which maps each pred-target pair to an example. :rtype: :class:Tensor “”” i, u = intersection_and_union(pred, target, num_classes, batch) iou = i.to(torch.float) / u.to(torch.float) iou[torch.isnan(iou)] = 1 //in multiple class segmentation task, some types are not include in the test data iou = iou.mean(dim=-1) return iou

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
GericoVicommented, Nov 9, 2021

Yes I could do that. If the below is acceptable, I will do a pull request.

def mean_iou(pred, target, num_classes, batch=None, omitnans=False):
    r"""Computes the mean intersection over union score of predictions.

    Args:
        pred (LongTensor): The predictions.
        target (LongTensor): The targets.
        num_classes (int): The number of classes.
        batch (LongTensor): The assignment vector which maps each pred-target
            pair to an example.

    :rtype: :class:`Tensor`
    """
    i, u = intersection_and_union(pred, target, num_classes, batch)
    iou = i.to(torch.float) / u.to(torch.float)

    if omitnans:
        iou = iou[~iou.isnan()].mean()
    else:
        iou[torch.isnan(iou)] = 1
        iou = iou.mean(dim=-1)
    
    return iou

For reference, on a trained PointNet++ segmentation model, an example from the airplane class of ShapeNet gives an mIoU of 0.85191 with omitnans = True and 0.98815 with omitnans = False. The former agrees with published results better.

1reaction
rusty1scommented, Nov 9, 2021

How about we add a flag to let the user decide on how to incorporate NaN values? How are other libraries handling thise use-case? Adding support for torch.nanmean() sounds great IMO.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is the calculation of mean IoU reasonable? #1982 - GitHub
when I test my model, some type has a bad segmentation, like board on s3dis dataset, it should get a very low score,...
Read more >
Calculate average Intersection over Union
The mean IoU (approach 1) wil be 0.3929 and the second approach will be 5/13 = 0.3846. What method do you think will...
Read more >
Intersection over Union (IoU) - Hasty.ai
Intersection over Union formula​​ IoU is calculated by dividing the overlap between the predicted and ground truth annotation by the union of these....
Read more >
Mean IoU - a Hugging Face Space by evaluate-metric
Limitations and Bias. Mean IOU is an average metric, so it will not show you where model predictions differ from the ground truth...
Read more >
Mean Average Precision (mAP) in Object Detection
We will explain how mean Average Precision (mAP) is calculated and why mAP has become the preferred metric for object detection models.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found