Skip to content

Commit

Permalink
add evaluator unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
RangiLyu committed Jul 10, 2021
1 parent aa82901 commit a8a9bbd
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/data/dummy_coco.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"score": 1.0,
"category_id": 1,
"id": 1,
"iscrowd": 0,
"image_id": 0
},
{
Expand All @@ -44,6 +45,7 @@
"score": 1.0,
"category_id": 2,
"id": 2,
"iscrowd": 0,
"image_id": 0
},
{
Expand All @@ -57,6 +59,7 @@
"score": 1.0,
"category_id": 1,
"id": 3,
"iscrowd": 0,
"image_id": 1
}
],
Expand Down
30 changes: 30 additions & 0 deletions tests/test_evaluator/test_coco_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import tempfile

from nanodet.data.dataset import build_dataset
from nanodet.evaluator import build_evaluator


def test_coco_detection():
dummy_results = {
0: {0: [[0, 0, 20, 20, 1]], 1: [[0, 0, 20, 20, 1]]},
1: {0: [[0, 0, 20, 20, 1]]},
}

cfg = dict(
name="CocoDataset",
img_path="./tests/data",
ann_path="./tests/data/dummy_coco.json",
input_size=[320, 320], # [w,h]
keep_ratio=True,
pipeline=dict(normalize=[[103.53, 116.28, 123.675], [57.375, 57.12, 58.395]]),
)
dataset = build_dataset(cfg, "train")

eval_cfg = dict(name="CocoDetectionEvaluator", save_key="mAP")

evaluator = build_evaluator(eval_cfg, dataset)
tmp_dir = tempfile.TemporaryDirectory()
eval_results = evaluator.evaluate(
results=dummy_results, save_dir=tmp_dir.name, rank=-1
)
assert eval_results["mAP"] == 1

0 comments on commit a8a9bbd

Please sign in to comment.