From 414dafa2b9bdcff68980a7b9827de49a34d9033c Mon Sep 17 00:00:00 2001 From: Samuel Date: Tue, 15 Oct 2019 09:20:57 +0200 Subject: [PATCH] Speeds up significantly the computation of IoU --- README.md | 8 ++++---- evaluation/evaluate_mIoU.py | 8 +------- evaluation/idd_lite_evaluate_mIoU.py | 8 +------- 3 files changed, 6 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index dff5e0e..eac3823 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ TODO: Make the color map more sensible. First generate labels masks with level3Ids as described before. Then ```bash -python evaluate/evaluate_mIoU.py --gts $GT --preds $PRED --num-workers $C +python evaluation/evaluate_mIoU.py --gts $GT --preds $PRED --num-workers $C ``` - GT is the folder path of ground truths containing /_gtFine_labellevel3Ids.png @@ -107,7 +107,7 @@ python evaluate/evaluate_mIoU.py --gts $GT --preds $PRED --num-workers $C First generate labels masks with level1Ids as described before. Then ```bash -python evaluate/idd_lite_evaluate_mIoU.py --gts $GT --preds $PRED --num-workers $C +python evaluation/idd_lite_evaluate_mIoU.py --gts $GT --preds $PRED --num-workers $C ``` - GT is the folder path of ground truths containing /_gtFine_labellevel1Ids.png @@ -120,7 +120,7 @@ python evaluate/idd_lite_evaluate_mIoU.py --gts $GT --preds $PRED --num-worker First generate instance label masks with ID_TYPE=id, as described before. Then ```bash -python evaluate/evaluate_instance_segmentation.py --gts $GT --preds $PRED +python evaluation/evaluate_instance_segmentation.py --gts $GT --preds $PRED ``` - GT is the folder path of ground truths containing /_gtFine_labellevel3Ids.png @@ -134,7 +134,7 @@ Please use https://github.com/AutoNUE/panopticapi ### Detection ```bash -python evaluate/evaluate_detection.py --gts $GT --preds $PRED +python evaluation/evaluate_detection.py --gts $GT --preds $PRED ``` - GT is the folder path of ground truths containing Annotations///<>.xml - PRED is the folder path of predictions with generated outputs in idd_det__.txt format. Here image_set can take {train,val,test}, while level3Id for all trainable labels has to present. diff --git a/evaluation/evaluate_mIoU.py b/evaluation/evaluate_mIoU.py index fdeeb82..7c87336 100644 --- a/evaluation/evaluate_mIoU.py +++ b/evaluation/evaluate_mIoU.py @@ -40,13 +40,7 @@ def add_to_confusion_matrix(gt, pred, mat): pred = pred.flatten() gt = gt.flatten() - - for (gtp,predp) in zip(gt, pred): - if gtp == 255 or gtp >26 : - gtp = 26 - if predp == 255 or predp >26: - predp = 26 - mat[gtp, predp] += 1 + np.add.at(mat.reshape(-1),mat.shape[1]*gt.copy().clip(max=26).astype(np.uint16)+pred.copy().clip(max=26).astype(np.uint16),1) return mat diff --git a/evaluation/idd_lite_evaluate_mIoU.py b/evaluation/idd_lite_evaluate_mIoU.py index 8261f50..3a2adbc 100644 --- a/evaluation/idd_lite_evaluate_mIoU.py +++ b/evaluation/idd_lite_evaluate_mIoU.py @@ -40,13 +40,7 @@ def add_to_confusion_matrix(gt, pred, mat): pred = pred.flatten() gt = gt.flatten() - - for (gtp,predp) in zip(gt, pred): - if gtp == 255 or gtp >7 : - gtp = 7 - if predp == 255 or predp >7: - predp = 7 - mat[gtp, predp] += 1 + np.add.at(mat.reshape(-1),mat.shape[1]*gt.copy().clip(max=7).astype(np.uint16)+pred.copy().clip(max=7).astype(np.uint16),1) return mat