This function takes the prediction and label of a single image, returns intersection and union areas for each class To compute over many images do: for i in range(Nimages): (area_intersection[:,i], area_union[:,i]) = intersectionAndUnion(imPred[i], imLab[i]) IoU = 1.0 *
(imPred, imLab, numClass)
| 129 | |
| 130 | |
| 131 | def intersectionAndUnion(imPred, imLab, numClass): |
| 132 | """ |
| 133 | This function takes the prediction and label of a single image, |
| 134 | returns intersection and union areas for each class |
| 135 | To compute over many images do: |
| 136 | for i in range(Nimages): |
| 137 | (area_intersection[:,i], area_union[:,i]) = intersectionAndUnion(imPred[i], imLab[i]) |
| 138 | IoU = 1.0 * np.sum(area_intersection, axis=1) / np.sum(np.spacing(1)+area_union, axis=1) |
| 139 | """ |
| 140 | # Remove classes from unlabeled pixels in gt image. |
| 141 | # We should not penalize detections in unlabeled portions of the image. |
| 142 | imPred = imPred * (imLab >= 0) |
| 143 | |
| 144 | # Compute area intersection: |
| 145 | intersection = imPred * (imPred == imLab) |
| 146 | (area_intersection, _) = np.histogram(intersection, bins=numClass, range=(1, numClass)) |
| 147 | |
| 148 | # Compute area union: |
| 149 | (area_pred, _) = np.histogram(imPred, bins=numClass, range=(1, numClass)) |
| 150 | (area_lab, _) = np.histogram(imLab, bins=numClass, range=(1, numClass)) |
| 151 | area_union = area_pred + area_lab - area_intersection |
| 152 | return (area_intersection, area_union) |
| 153 | |
| 154 | |
| 155 | def hist_info(pred, label, num_cls): |
nothing calls this directly
no outgoing calls
no test coverage detected