Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

yolo_nas_pose_integration_test.py 5.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  1. import os
  2. import unittest
  3. from torch.utils.data import DataLoader
  4. from super_gradients.common.environment.cfg_utils import load_dataset_params
  5. from super_gradients.common.object_names import Models
  6. from super_gradients.training import Trainer
  7. from super_gradients.training import models
  8. from super_gradients.training.dataloaders import get_data_loader
  9. from super_gradients.training.datasets import COCOPoseEstimationDataset
  10. from super_gradients.training.metrics import PoseEstimationMetrics
  11. from super_gradients.training.models.pose_estimation_models import YoloNASPose
  12. class YoloNASPoseIntegrationTest(unittest.TestCase):
  13. """
  14. YoloNASPoseIntegrationTest - Integration tests for YoloNASPose models
  15. This test evaluate the performance of trained models on the COCO dataset using
  16. the modified evaluation protocol that is different from the original COCOEval:
  17. In COCOEval all images are not resized and pose predictions are evaluated in the resolution of original image
  18. This is the most accurate and for scientific purposes, this is the way to evaluate the model to report results for publication.
  19. However this protocol is not suitable for training/validation, because all images has different resolutions and
  20. it is impossible to collate them to make a batch. So instead we use the following protocol:
  21. During training/validation, we resize all images to a fixed size (Default is 640x640) using aspect-ratio preserving
  22. resize of the longest size + padding. Our metric evaluate AP/AR in the resolution of the resized & padded images,
  23. **not in the resolution of original image**.
  24. This change has a minor impact on the AP/AR scores while allowing to train/validate the model on a batch of images which
  25. is much faster than processing images one by one and has no dependency on COCOEval.
  26. Model | AP (COCOEval) | AP (Our protocol) |
  27. -----------------|---------------|-------------------|
  28. YOLO-NAS POSE N | 59.68 | 59.68 |
  29. YOLO-NAS POSE S | 64.15 | 64.16 |
  30. YOLO-NAS POSE M | 67.87 | 67.90 |
  31. YOLO-NAS POSE L | 68.24 | 68.28 |
  32. For evaluation using COCOEval protocol please refer to src/super_gradients/examples/pose_coco_eval/pose_coco_eval.ipynb
  33. """
  34. def setUp(self):
  35. # This is for easy testing on local machine - you can set this environment variable to your own COCO dataset location
  36. self.data_dir = os.environ.get("SUPER_GRADIENTS_COCO_DATASET_DIR", "/data/coco")
  37. dataset_params = load_dataset_params("coco_pose_estimation_yolo_nas_dataset_params")
  38. self.sigmas = dataset_params["oks_sigmas"]
  39. self.num_joints = dataset_params["num_joints"]
  40. def _coco2017_val_yolo_nas_pose(self) -> DataLoader:
  41. loader = get_data_loader(
  42. config_name="coco_pose_estimation_yolo_nas_dataset_params",
  43. dataset_cls=COCOPoseEstimationDataset,
  44. train=False,
  45. dataset_params=dict(data_dir=self.data_dir),
  46. dataloader_params=dict(num_workers=0),
  47. )
  48. return loader
  49. def _predict_and_evaluate(self, model, experiment_name):
  50. trainer = Trainer(experiment_name)
  51. metric = PoseEstimationMetrics(
  52. post_prediction_callback=model.get_post_prediction_callback(conf=0.01, iou=0.7, post_nms_max_predictions=30),
  53. num_joints=self.num_joints,
  54. oks_sigmas=self.sigmas,
  55. )
  56. loader = self._coco2017_val_yolo_nas_pose()
  57. metric_values = trainer.test(model=model, test_loader=loader, test_metrics_list=[metric])
  58. print(experiment_name, metric_values)
  59. return metric_values
  60. def test_yolo_nas_pose_n_coco(self):
  61. model: YoloNASPose = models.get(
  62. Models.YOLO_NAS_POSE_N, num_classes=17, checkpoint_path="G:/super-gradients/checkpoints/coco2017_yolo_nas_pose_final/yolo_nas_pose_n_coco_pose.pth"
  63. )
  64. metric_values = self._predict_and_evaluate(model, "test_yolo_nas_n_coco")
  65. self.assertAlmostEqual(metric_values["AP"], 0.5968, delta=0.001)
  66. def test_yolo_nas_s_coco(self):
  67. model = models.get(
  68. Models.YOLO_NAS_POSE_S, num_classes=17, checkpoint_path="G:/super-gradients/checkpoints/coco2017_yolo_nas_pose_final/yolo_nas_pose_s_coco_pose.pth"
  69. )
  70. metric_values = self._predict_and_evaluate(model, "test_yolo_nas_s_coco")
  71. self.assertAlmostEqual(metric_values["AP"], 0.6416, delta=0.001)
  72. def test_yolo_nas_m_coco(self):
  73. model = models.get(
  74. Models.YOLO_NAS_POSE_M, num_classes=17, checkpoint_path="G:/super-gradients/checkpoints/coco2017_yolo_nas_pose_final/yolo_nas_pose_m_coco_pose.pth"
  75. )
  76. metric_values = self._predict_and_evaluate(model, "test_yolo_nas_m_coco")
  77. self.assertAlmostEqual(metric_values["AP"], 0.6790, delta=0.001)
  78. def test_yolo_nas_l_coco(self):
  79. model = models.get(
  80. Models.YOLO_NAS_POSE_L, num_classes=17, checkpoint_path="G:/super-gradients/checkpoints/coco2017_yolo_nas_pose_final/yolo_nas_pose_l_coco_pose.pth"
  81. )
  82. metric_values = self._predict_and_evaluate(model, "test_yolo_nas_l_coco")
  83. self.assertAlmostEqual(metric_values["AP"], 0.6828, delta=0.001)
  84. if __name__ == "__main__":
  85. unittest.main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...