test_coco_occluded_metric.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import os.path as osp
  3. from tempfile import TemporaryDirectory
  4. import mmengine
  5. import numpy as np
  6. from mmdet.datasets import CocoDataset
  7. from mmdet.evaluation import CocoOccludedSeparatedMetric
  8. def test_coco_occluded_separated_metric():
  9. ann = [[
  10. 'fake1.jpg', 'person', 8, [219.9, 176.12, 11.14, 34.23], {
  11. 'size': [480, 640],
  12. 'counts': b'nYW31n>2N2FNbA48Kf=?XBDe=m0OM3M4YOPB8_>L4JXao5'
  13. }
  14. ]] * 3
  15. dummy_mask = np.zeros((10, 10), dtype=np.uint8)
  16. dummy_mask[:5, :5] = 1
  17. rle = {
  18. 'size': [480, 640],
  19. 'counts': b'nYW31n>2N2FNbA48Kf=?XBDe=m0OM3M4YOPB8_>L4JXao5'
  20. }
  21. res = [(None,
  22. dict(
  23. img_id=0,
  24. bboxes=np.array([[50, 60, 70, 80]] * 2),
  25. masks=[rle] * 2,
  26. labels=np.array([0, 1], dtype=np.int64),
  27. scores=np.array([0.77, 0.77])))] * 3
  28. tempdir = TemporaryDirectory()
  29. ann_path = osp.join(tempdir.name, 'coco_occluded.pkl')
  30. mmengine.dump(ann, ann_path)
  31. metric = CocoOccludedSeparatedMetric(
  32. ann_file='tests/data/coco_sample.json',
  33. occluded_ann=ann_path,
  34. separated_ann=ann_path,
  35. metric=[])
  36. metric.dataset_meta = CocoDataset.METAINFO
  37. eval_res = metric.compute_metrics(res)
  38. assert isinstance(eval_res, dict)
  39. assert eval_res['occluded_recall'] == 100
  40. assert eval_res['separated_recall'] == 100