Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find IoU from segmentation masks?

I am doing an image segmentation task and I am using a dataset that only has ground truths but no bounding boxes or polygons.

I have 2 classes( ignoring 0 for background) and the outputs and ground truth labels are in an array like

Predicted--/---Labels

0|0|0|1|2 0|0|0|1|2 0|2|1|0|0 0|2|1|0|0 0|0|1|1|1 0|0|1|1|1 0|0|0|0|1 0|0|0|0|1

How do I calculate IoU from these ?

PS: I am using python3 with pytorch api

like image 200
Farshid Rayhan Avatar asked Jun 30 '18 14:06

Farshid Rayhan


People also ask

How is IoU value calculated?

IoU is calculated by dividing the overlap between the predicted and ground truth annotation by the union of these.

How do you calculate IoU for multiclass segmentation?

IoU is the area of overlap between the predicted segmentation and the ground truth divided by the area of union between the predicted segmentation and the ground truth. For binary (two classes) or multi-class segmentation, the mean IoU of the image is calculated by taking the IoU of each class and averaging them.

What is IoU in segmentation?

The Intersection over Union (IoU) metric, also referred to as the Jaccard index, is essentially a method to quantify the percent overlap between the target mask and our prediction output. This metric is closely related to the Dice coefficient which is often used as a loss function during training.

How does Python calculate IoU?

Coding a function for IOU in python: The function IOU takes in 2 boxes, box1 and box2 as input. The data in each box is a list containing[x1, y1, x2, y2], which is the top left, and bottom right coordinates. We find the area of the intersection, followed by the area of the union, as described earlier.


1 Answers

So I just found out that jaccard_similarity_score is regarded as IoU.

So the solution is very simple,

from sklearn.metrics import jaccard_similarity_score jac = jaccard_similarity_score(predictions, label, Normalize = True/False)

Source link: https://scikit-learn.org/stable/modules/generated/sklearn.metrics.jaccard_score.html#sklearn.metrics.jaccard_score

like image 81
Farshid Rayhan Avatar answered Oct 20 '22 10:10

Farshid Rayhan