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

#634 Feature/sg 573 pose estimation

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-573-pose-estimation
@@ -1,7 +1,7 @@
 import sys
 import sys
 import unittest
 import unittest
 
 
-from tests.integration_tests import TestDataset, EMAIntegrationTest, LRTest
+from tests.integration_tests import EMAIntegrationTest, LRTest, PoseEstimationDatasetIntegrationTest
 
 
 
 
 class CoreIntegrationTestSuiteRunner:
 class CoreIntegrationTestSuiteRunner:
@@ -16,9 +16,9 @@ class CoreIntegrationTestSuiteRunner:
         _add_modules_to_integration_tests_suite - Adds unit tests to the Unit Tests Test Suite
         _add_modules_to_integration_tests_suite - Adds unit tests to the Unit Tests Test Suite
             :return:
             :return:
         """
         """
-        self.integration_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestDataset))
         self.integration_tests_suite.addTest(self.test_loader.loadTestsFromModule(EMAIntegrationTest))
         self.integration_tests_suite.addTest(self.test_loader.loadTestsFromModule(EMAIntegrationTest))
         self.integration_tests_suite.addTest(self.test_loader.loadTestsFromModule(LRTest))
         self.integration_tests_suite.addTest(self.test_loader.loadTestsFromModule(LRTest))
+        self.integration_tests_suite.addTest(self.test_loader.loadTestsFromModule(PoseEstimationDatasetIntegrationTest))
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
Discard
@@ -20,6 +20,7 @@ from tests.unit_tests import (
     ResumeTrainingTest,
     ResumeTrainingTest,
     CallTrainAfterTestTest,
     CallTrainAfterTestTest,
     CrashTipTest,
     CrashTipTest,
+    TestTransforms,
 )
 )
 from tests.end_to_end_tests import TestTrainer
 from tests.end_to_end_tests import TestTrainer
 from tests.unit_tests.detection_utils_test import TestDetectionUtils
 from tests.unit_tests.detection_utils_test import TestDetectionUtils
@@ -121,6 +122,7 @@ class CoreUnitTestSuiteRunner:
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestModelsONNXExport))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestModelsONNXExport))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(MaxBatchesLoopBreakTest))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(MaxBatchesLoopBreakTest))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestTrainingUtils))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestTrainingUtils))
+        self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestTransforms))
 
 
     def _add_modules_to_end_to_end_tests_suite(self):
     def _add_modules_to_end_to_end_tests_suite(self):
         """
         """
Discard
@@ -2,5 +2,6 @@
 
 
 from tests.integration_tests.ema_train_integration_test import EMAIntegrationTest
 from tests.integration_tests.ema_train_integration_test import EMAIntegrationTest
 from tests.integration_tests.lr_test import LRTest
 from tests.integration_tests.lr_test import LRTest
+from tests.integration_tests.pose_estimation_dataset_test import PoseEstimationDatasetIntegrationTest
 
 
-__all__ = ["EMAIntegrationTest", "LRTest"]
+__all__ = ["EMAIntegrationTest", "LRTest", "PoseEstimationDatasetIntegrationTest"]
Discard
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
  1. import os
  2. import unittest
  3. import pkg_resources
  4. from hydra import initialize_config_dir, compose
  5. from hydra.core.global_hydra import GlobalHydra
  6. from super_gradients.common.environment.path_utils import normalize_path
  7. from super_gradients.training.dataloaders.dataloaders import _process_dataset_params, get_data_loader
  8. from super_gradients.training.datasets.pose_estimation_datasets import COCOKeypointsDataset
  9. class PoseEstimationDatasetIntegrationTest(unittest.TestCase):
  10. def test_datasets_instantiation(self):
  11. GlobalHydra.instance().clear()
  12. sg_recipes_dir = pkg_resources.resource_filename("super_gradients.recipes", "")
  13. dataset_config = os.path.join("dataset_params", "coco_pose_estimation_dekr_dataset_params")
  14. with initialize_config_dir(config_dir=normalize_path(sg_recipes_dir), version_base="1.2"):
  15. # config is relative to a module
  16. cfg = compose(config_name=normalize_path(dataset_config))
  17. train_dataset_params = _process_dataset_params(cfg, dict(), True)
  18. val_dataset_params = _process_dataset_params(cfg, dict(), True)
  19. train_dataset = COCOKeypointsDataset(**train_dataset_params)
  20. assert train_dataset[0] is not None
  21. val_dataset = COCOKeypointsDataset(**val_dataset_params)
  22. assert val_dataset[0] is not None
  23. def test_dataloaders_instantiation(self):
  24. train_loader = get_data_loader("coco_pose_estimation_dekr_dataset_params", COCOKeypointsDataset, train=True, dataloader_params=dict(num_workers=0))
  25. val_loader = get_data_loader("coco_pose_estimation_dekr_dataset_params", COCOKeypointsDataset, train=False, dataloader_params=dict(num_workers=0))
  26. assert next(iter(train_loader)) is not None
  27. assert next(iter(val_loader)) is not None
  28. if __name__ == "__main__":
  29. unittest.main()
Discard
@@ -22,7 +22,7 @@ from tests.unit_tests.conv_bn_relu_test import TestConvBnRelu
 from tests.unit_tests.initialize_with_dataloaders_test import InitializeWithDataloadersTest
 from tests.unit_tests.initialize_with_dataloaders_test import InitializeWithDataloadersTest
 from tests.unit_tests.training_params_factory_test import TrainingParamsTest
 from tests.unit_tests.training_params_factory_test import TrainingParamsTest
 from tests.unit_tests.config_inspector_test import ConfigInspectTest
 from tests.unit_tests.config_inspector_test import ConfigInspectTest
-
+from tests.unit_tests.transforms_test import TestTransforms
 
 
 __all__ = [
 __all__ = [
     "CrashTipTest",
     "CrashTipTest",
@@ -48,4 +48,5 @@ __all__ = [
     "ResumeTrainingTest",
     "ResumeTrainingTest",
     "CallTrainAfterTestTest",
     "CallTrainAfterTestTest",
     "ConfigInspectTest",
     "ConfigInspectTest",
+    "TestTransforms",
 ]
 ]
Discard
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
  1. from super_gradients.training.datasets.pose_estimation_datasets.coco_keypoints import COCOKeypointsDataset
  2. from super_gradients.training.datasets.pose_estimation_datasets.target_generators import DEKRTargetsGenerator
  3. from super_gradients.training.transforms.keypoint_transforms import KeypointsCompose, KeypointsRandomVerticalFlip
  4. def test_dataset():
  5. target_generator = DEKRTargetsGenerator(
  6. output_stride=4,
  7. sigma=2,
  8. center_sigma=4,
  9. bg_weight=0.1,
  10. offset_radius=4,
  11. )
  12. dataset = COCOKeypointsDataset(
  13. data_dir="e:/coco2017",
  14. images_dir="images/train2017",
  15. json_file="annotations/person_keypoints_train2017.json",
  16. include_empty_samples=False,
  17. transforms=KeypointsCompose(
  18. [
  19. KeypointsRandomVerticalFlip(),
  20. ]
  21. ),
  22. target_generator=target_generator,
  23. )
  24. assert dataset is not None
  25. assert dataset[0] is not None
Discard
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
  1. import unittest
  2. import numpy as np
  3. from super_gradients.training.transforms.keypoint_transforms import (
  4. KeypointsRandomHorizontalFlip,
  5. KeypointsRandomVerticalFlip,
  6. KeypointsRandomAffineTransform,
  7. KeypointsPadIfNeeded,
  8. KeypointsLongestMaxSize,
  9. )
  10. class TestTransforms(unittest.TestCase):
  11. def test_keypoints_random_affine(self):
  12. image = np.random.rand(640, 480, 3)
  13. mask = np.random.rand(640, 480)
  14. joints = np.random.randint(0, 480, size=(1, 17, 3))
  15. joints[..., 2] = 2 # all visible
  16. aug = KeypointsRandomAffineTransform(min_scale=0.8, max_scale=1.2, max_rotation=30, max_translate=0.5, prob=1, image_pad_value=0, mask_pad_value=0)
  17. aug_image, aug_mask, aug_joints = aug(image, mask, joints)
  18. joints_outside_image = (
  19. (aug_joints[:, :, 0] < 0) | (aug_joints[:, :, 1] < 0) | (aug_joints[:, :, 0] >= aug_image.shape[1]) | (aug_joints[:, :, 1] >= aug_image.shape[0])
  20. )
  21. # Ensure that keypoints outside the image are not visible
  22. self.assertTrue((aug_joints[joints_outside_image, 2] == 0).all())
  23. self.assertTrue((aug_joints[~joints_outside_image, 2] != 0).all())
  24. def test_keypoints_horizontal_flip(self):
  25. image = np.random.rand(640, 480, 3)
  26. mask = np.random.rand(640, 480)
  27. joints = np.random.randint(0, 100, size=(1, 17, 3))
  28. aug = KeypointsRandomHorizontalFlip(flip_index=[16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], prob=1)
  29. aug_image, aug_mask, aug_joints = aug(image, mask, joints)
  30. np.testing.assert_array_equal(aug_image, image[:, ::-1, :])
  31. np.testing.assert_array_equal(aug_mask, mask[:, ::-1])
  32. np.testing.assert_array_equal(image.shape[1] - aug_joints[:, ::-1, 0] - 1, joints[..., 0])
  33. np.testing.assert_array_equal(aug_joints[:, ::-1, 1], joints[..., 1])
  34. np.testing.assert_array_equal(aug_joints[:, ::-1, 2], joints[..., 2])
  35. def test_keypoints_vertical_flip(self):
  36. image = np.random.rand(640, 480, 3)
  37. mask = np.random.rand(640, 480)
  38. joints = np.random.randint(0, 100, size=(1, 17, 3))
  39. aug = KeypointsRandomVerticalFlip(prob=1)
  40. aug_image, aug_mask, aug_joints = aug(image, mask, joints)
  41. np.testing.assert_array_equal(aug_image, image[::-1, :, :])
  42. np.testing.assert_array_equal(aug_mask, mask[::-1, :])
  43. np.testing.assert_array_equal(aug_joints[..., 0], joints[..., 0])
  44. np.testing.assert_array_equal(image.shape[0] - aug_joints[..., 1] - 1, joints[..., 1])
  45. np.testing.assert_array_equal(aug_joints[..., 2], joints[..., 2])
  46. def test_keypoints_pad_if_needed(self):
  47. image = np.random.rand(640, 480, 3)
  48. mask = np.random.rand(640, 480)
  49. joints = np.random.randint(0, 100, size=(1, 17, 3))
  50. aug = KeypointsPadIfNeeded(min_width=768, min_height=768, image_pad_value=0, mask_pad_value=0)
  51. aug_image, aug_mask, aug_joints = aug(image, mask, joints)
  52. self.assertEqual(aug_image.shape, (768, 768, 3))
  53. self.assertEqual(aug_mask.shape, (768, 768))
  54. np.testing.assert_array_equal(aug_joints, joints)
  55. def test_keypoints_longest_max_size(self):
  56. image = np.random.rand(640, 480, 3)
  57. mask = np.random.rand(640, 480)
  58. joints = np.random.randint(0, 480, size=(1, 17, 3))
  59. aug = KeypointsLongestMaxSize(max_height=512, max_width=512)
  60. aug_image, aug_mask, aug_joints = aug(image, mask, joints)
  61. self.assertEqual(aug_image.shape[:2], aug_mask.shape[:2])
  62. self.assertLessEqual(aug_image.shape[0], 512)
  63. self.assertLessEqual(aug_image.shape[1], 512)
  64. self.assertTrue((aug_joints[..., 0] < aug_image.shape[1]).all())
  65. self.assertTrue((aug_joints[..., 1] < aug_image.shape[0]).all())
  66. if __name__ == "__main__":
  67. unittest.main()
Discard