You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_mean_ap.py 2.3 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import numpy as np
  2. from mmdet.core.evaluation.mean_ap import eval_map, tpfp_default, tpfp_imagenet
  3. det_bboxes = np.array([
  4. [0, 0, 10, 10],
  5. [10, 10, 20, 20],
  6. [32, 32, 38, 42],
  7. ])
  8. gt_bboxes = np.array([[0, 0, 10, 20], [0, 10, 10, 19], [10, 10, 20, 20]])
  9. gt_ignore = np.array([[5, 5, 10, 20], [6, 10, 10, 19]])
  10. def test_tpfp_imagenet():
  11. result = tpfp_imagenet(
  12. det_bboxes,
  13. gt_bboxes,
  14. gt_bboxes_ignore=gt_ignore,
  15. use_legacy_coordinate=True)
  16. tp = result[0]
  17. fp = result[1]
  18. assert tp.shape == (1, 3)
  19. assert fp.shape == (1, 3)
  20. assert (tp == np.array([[1, 1, 0]])).all()
  21. assert (fp == np.array([[0, 0, 1]])).all()
  22. result = tpfp_imagenet(
  23. det_bboxes,
  24. gt_bboxes,
  25. gt_bboxes_ignore=gt_ignore,
  26. use_legacy_coordinate=False)
  27. tp = result[0]
  28. fp = result[1]
  29. assert tp.shape == (1, 3)
  30. assert fp.shape == (1, 3)
  31. assert (tp == np.array([[1, 1, 0]])).all()
  32. assert (fp == np.array([[0, 0, 1]])).all()
  33. def test_tpfp_default():
  34. result = tpfp_default(
  35. det_bboxes,
  36. gt_bboxes,
  37. gt_bboxes_ignore=gt_ignore,
  38. use_legacy_coordinate=True)
  39. tp = result[0]
  40. fp = result[1]
  41. assert tp.shape == (1, 3)
  42. assert fp.shape == (1, 3)
  43. assert (tp == np.array([[1, 1, 0]])).all()
  44. assert (fp == np.array([[0, 0, 1]])).all()
  45. result = tpfp_default(
  46. det_bboxes,
  47. gt_bboxes,
  48. gt_bboxes_ignore=gt_ignore,
  49. use_legacy_coordinate=False)
  50. tp = result[0]
  51. fp = result[1]
  52. assert tp.shape == (1, 3)
  53. assert fp.shape == (1, 3)
  54. assert (tp == np.array([[1, 1, 0]])).all()
  55. assert (fp == np.array([[0, 0, 1]])).all()
  56. def test_eval_map():
  57. # 2 image and 2 classes
  58. det_results = [[det_bboxes, det_bboxes], [det_bboxes, det_bboxes]]
  59. labels = np.array([0, 1, 1])
  60. labels_ignore = np.array([0, 1])
  61. gt_info = {
  62. 'bboxes': gt_bboxes,
  63. 'bboxes_ignore': gt_ignore,
  64. 'labels': labels,
  65. 'labels_ignore': labels_ignore
  66. }
  67. annotations = [gt_info, gt_info]
  68. mean_ap, eval_results = eval_map(
  69. det_results, annotations, use_legacy_coordinate=True)
  70. assert 0.291 < mean_ap < 0.293
  71. eval_map(det_results, annotations, use_legacy_coordinate=False)
  72. assert 0.291 < mean_ap < 0.293

No Description

Contributors (3)