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

pose_estimation_models_test.py 5.5 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
  1. import unittest
  2. import torch
  3. from tqdm import tqdm
  4. from super_gradients.training import models
  5. from super_gradients.training.dataloaders.dataloaders import get_data_loader
  6. from super_gradients.training.datasets.pose_estimation_datasets import COCOKeypointsDataset
  7. from super_gradients.training.metrics import PoseEstimationMetrics
  8. from super_gradients.training.models.pose_estimation_models.dekr_hrnet import DEKRWrapper, DEKRHorisontalFlipWrapper
  9. from super_gradients.training.utils import DEKRPoseEstimationDecodeCallback
  10. from super_gradients.training.utils.pose_estimation import RescoringPoseEstimationDecodeCallback
  11. class PoseEstimationModelsIntegrationTest(unittest.TestCase):
  12. def setUp(self):
  13. self.oks_sigmas = [0.026, 0.025, 0.025, 0.035, 0.035, 0.079, 0.079, 0.072, 0.072, 0.062, 0.062, 1.007, 1.007, 0.087, 0.087, 0.089, 0.089]
  14. self.flip_indexes_heatmap = [0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15, 17]
  15. self.flip_indexes_offset = [
  16. 0,
  17. 2,
  18. 1,
  19. 4,
  20. 3,
  21. 6,
  22. 5,
  23. 8,
  24. 7,
  25. 10,
  26. 9,
  27. 12,
  28. 11,
  29. 14,
  30. 13,
  31. 16,
  32. 15,
  33. ]
  34. def test_dekr_model(self):
  35. val_loader = get_data_loader(
  36. "coco_pose_estimation_dekr_dataset_params",
  37. COCOKeypointsDataset,
  38. train=False,
  39. dataloader_params=dict(num_workers=0),
  40. )
  41. model = models.get("dekr_w32_no_dc", pretrained_weights="coco_pose")
  42. model = DEKRWrapper(model, apply_sigmoid=True).cuda().eval()
  43. post_prediction_callback = DEKRPoseEstimationDecodeCallback(
  44. output_stride=4, max_num_people=30, apply_sigmoid=False, keypoint_threshold=0.05, nms_threshold=0.05, nms_num_threshold=8
  45. )
  46. post_prediction_callback.apply_sigmoid = False
  47. metric = PoseEstimationMetrics(
  48. post_prediction_callback=post_prediction_callback,
  49. max_objects_per_image=post_prediction_callback.max_num_people,
  50. num_joints=val_loader.dataset.num_joints,
  51. oks_sigmas=self.oks_sigmas,
  52. )
  53. for inputs, targets, extras in tqdm(val_loader):
  54. with torch.no_grad(), torch.cuda.amp.autocast(True):
  55. predictions = model(inputs.cuda(non_blocking=True))
  56. metric.update(predictions, targets, **extras)
  57. stats = metric.compute()
  58. self.assertAlmostEqual(stats["AP"], 0.6308, delta=0.05)
  59. def test_dekr_model_with_tta(self):
  60. val_loader = get_data_loader(
  61. "coco_pose_estimation_dekr_dataset_params",
  62. COCOKeypointsDataset,
  63. train=False,
  64. dataloader_params=dict(num_workers=0),
  65. )
  66. model = models.get("dekr_w32_no_dc", pretrained_weights="coco_pose")
  67. model = DEKRHorisontalFlipWrapper(model, self.flip_indexes_heatmap, self.flip_indexes_offset, apply_sigmoid=True).cuda().eval()
  68. post_prediction_callback = DEKRPoseEstimationDecodeCallback(
  69. output_stride=4, max_num_people=30, apply_sigmoid=False, keypoint_threshold=0.05, nms_threshold=0.05, nms_num_threshold=8
  70. )
  71. metric = PoseEstimationMetrics(
  72. post_prediction_callback=post_prediction_callback,
  73. max_objects_per_image=post_prediction_callback.max_num_people,
  74. num_joints=val_loader.dataset.num_joints,
  75. oks_sigmas=self.oks_sigmas,
  76. )
  77. for inputs, targets, extras in tqdm(val_loader):
  78. with torch.no_grad(), torch.cuda.amp.autocast(True):
  79. predictions = model(inputs.cuda(non_blocking=True))
  80. metric.update(predictions, targets, **extras)
  81. stats = metric.compute()
  82. self.assertAlmostEqual(stats["AP"], 0.6490, delta=0.05)
  83. def test_dekr_model_with_rescoring(self):
  84. val_loader = get_data_loader(
  85. "coco_pose_estimation_dekr_dataset_params",
  86. COCOKeypointsDataset,
  87. train=False,
  88. dataloader_params=dict(batch_size=1, num_workers=0),
  89. )
  90. model = models.get("dekr_w32_no_dc", pretrained_weights="coco_pose")
  91. model = DEKRHorisontalFlipWrapper(model, self.flip_indexes_heatmap, self.flip_indexes_offset, apply_sigmoid=True).cuda().eval()
  92. rescoring = models.get("pose_rescoring_coco", pretrained_weights="coco_pose").cuda().eval()
  93. post_prediction_callback = DEKRPoseEstimationDecodeCallback(
  94. output_stride=4, max_num_people=30, apply_sigmoid=False, keypoint_threshold=0.05, nms_threshold=0.05, nms_num_threshold=8
  95. )
  96. metric = PoseEstimationMetrics(
  97. post_prediction_callback=RescoringPoseEstimationDecodeCallback(apply_sigmoid=True),
  98. max_objects_per_image=post_prediction_callback.max_num_people,
  99. num_joints=val_loader.dataset.num_joints,
  100. oks_sigmas=self.oks_sigmas,
  101. )
  102. for inputs, targets, extras in tqdm(val_loader):
  103. with torch.no_grad(), torch.cuda.amp.autocast(True):
  104. predictions = model(inputs.cuda(non_blocking=True))
  105. [all_poses], _ = post_prediction_callback(predictions)
  106. all_poses, new_scores = rescoring(torch.tensor(all_poses).cuda())
  107. metric.update(preds=(all_poses.unsqueeze(0), new_scores.unsqueeze(0)), target=targets, **extras)
  108. stats = metric.compute()
  109. self.assertAlmostEqual(stats["AP"], 0.6734, delta=0.05)
  110. if __name__ == "__main__":
  111. unittest.main()
Tip!

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

Comments

Loading...