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

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

Comments

Loading...