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

#875 Feature/sg 761 yolo nas

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-761-yolo-nas
@@ -1,7 +1,7 @@
 import sys
 import sys
 import unittest
 import unittest
 
 
-from tests.integration_tests import EMAIntegrationTest, LRTest, PoseEstimationDatasetIntegrationTest
+from tests.integration_tests import EMAIntegrationTest, LRTest, PoseEstimationDatasetIntegrationTest, YoloNASIntegrationTest
 
 
 
 
 class CoreIntegrationTestSuiteRunner:
 class CoreIntegrationTestSuiteRunner:
@@ -19,6 +19,7 @@ class CoreIntegrationTestSuiteRunner:
         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))
         self.integration_tests_suite.addTest(self.test_loader.loadTestsFromModule(PoseEstimationDatasetIntegrationTest))
+        self.integration_tests_suite.addTest(self.test_loader.loadTestsFromModule(YoloNASIntegrationTest))
 
 
 
 
 if __name__ == "__main__":
 if __name__ == "__main__":
Discard
@@ -34,6 +34,7 @@ from tests.unit_tests.pose_estimation_dataset_test import TestPoseEstimationData
 from tests.unit_tests.preprocessing_unit_test import PreprocessingUnitTest
 from tests.unit_tests.preprocessing_unit_test import PreprocessingUnitTest
 from tests.unit_tests.quantization_utility_tests import QuantizationUtilityTest
 from tests.unit_tests.quantization_utility_tests import QuantizationUtilityTest
 from tests.unit_tests.random_erase_test import RandomEraseTest
 from tests.unit_tests.random_erase_test import RandomEraseTest
+from tests.unit_tests.replace_head_test import ReplaceHeadUnitTest
 from tests.unit_tests.strictload_enum_test import StrictLoadEnumTest
 from tests.unit_tests.strictload_enum_test import StrictLoadEnumTest
 from tests.unit_tests.train_with_intialized_param_args_test import TrainWithInitializedObjectsTest
 from tests.unit_tests.train_with_intialized_param_args_test import TrainWithInitializedObjectsTest
 from tests.unit_tests.pretrained_models_unit_test import PretrainedModelsUnitTest
 from tests.unit_tests.pretrained_models_unit_test import PretrainedModelsUnitTest
@@ -132,6 +133,7 @@ class CoreUnitTestSuiteRunner:
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestPoseEstimationMetrics))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestPoseEstimationMetrics))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestPoseEstimationDataset))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(TestPoseEstimationDataset))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(LoadCheckpointTest))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(LoadCheckpointTest))
+        self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(ReplaceHeadUnitTest))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(PreprocessingUnitTest))
         self.unit_tests_suite.addTest(self.test_loader.loadTestsFromModule(PreprocessingUnitTest))
 
 
     def _add_modules_to_end_to_end_tests_suite(self):
     def _add_modules_to_end_to_end_tests_suite(self):
Discard
@@ -3,5 +3,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
 from tests.integration_tests.pose_estimation_dataset_test import PoseEstimationDatasetIntegrationTest
+from tests.integration_tests.yolo_nas_integration_test import YoloNASIntegrationTest
 
 
-__all__ = ["EMAIntegrationTest", "LRTest", "PoseEstimationDatasetIntegrationTest"]
+__all__ = ["EMAIntegrationTest", "LRTest", "PoseEstimationDatasetIntegrationTest", "YoloNASIntegrationTest"]
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
  1. import unittest
  2. from super_gradients.training import models
  3. from super_gradients.training.dataloaders import coco2017_val_yolo_nas
  4. from super_gradients.training import Trainer
  5. from super_gradients.training.metrics import DetectionMetrics
  6. from super_gradients.training.models.detection_models.pp_yolo_e import PPYoloEPostPredictionCallback
  7. class YoloNASIntegrationTest(unittest.TestCase):
  8. def test_yolo_nas_s_coco(self):
  9. trainer = Trainer("test_yolo_nas_s")
  10. model = models.get("yolo_nas_s", num_classes=80, pretrained_weights="coco")
  11. dl = coco2017_val_yolo_nas()
  12. metric = DetectionMetrics(
  13. normalize_targets=True,
  14. post_prediction_callback=PPYoloEPostPredictionCallback(score_threshold=0.03, nms_top_k=1000, max_predictions=300, nms_threshold=0.65),
  15. num_cls=80,
  16. )
  17. metric_values = trainer.test(model=model, test_loader=dl, test_metrics_list=[metric])
  18. self.assertAlmostEqual(metric_values[metric.map_str], 0.475, delta=0.001)
  19. def test_yolo_nas_m_coco(self):
  20. trainer = Trainer("test_yolo_nas_m")
  21. model = models.get("yolo_nas_m", num_classes=80, pretrained_weights="coco")
  22. dl = coco2017_val_yolo_nas()
  23. metric = DetectionMetrics(
  24. normalize_targets=True,
  25. post_prediction_callback=PPYoloEPostPredictionCallback(score_threshold=0.03, nms_top_k=1000, max_predictions=300, nms_threshold=0.65),
  26. num_cls=80,
  27. )
  28. metric_values = trainer.test(model=model, test_loader=dl, test_metrics_list=[metric])
  29. self.assertAlmostEqual(metric_values[metric.map_str], 0.5155, delta=0.001)
  30. def test_yolo_nas_l_coco(self):
  31. trainer = Trainer("test_yolo_nas_l")
  32. model = models.get("yolo_nas_l", num_classes=80, pretrained_weights="coco")
  33. dl = coco2017_val_yolo_nas()
  34. metric = DetectionMetrics(
  35. normalize_targets=True,
  36. post_prediction_callback=PPYoloEPostPredictionCallback(score_threshold=0.03, nms_top_k=1000, max_predictions=300, nms_threshold=0.65),
  37. num_cls=80,
  38. )
  39. metric_values = trainer.test(model=model, test_loader=dl, test_metrics_list=[metric])
  40. self.assertAlmostEqual(metric_values[metric.map_str], 0.5222, delta=0.001)
  41. if __name__ == "__main__":
  42. unittest.main()
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
  1. import os
  2. import shutil
  3. import unittest
  4. import torch
  5. import super_gradients
  6. from super_gradients.common.object_names import Models
  7. from super_gradients.training import models
  8. class ReplaceHeadUnitTest(unittest.TestCase):
  9. def setUp(self) -> None:
  10. self.device = "cuda" if torch.cuda.is_available() and torch.cuda.device_count() > 0 else "cpu"
  11. super_gradients.init_trainer()
  12. def test_ppyolo_replace_head(self):
  13. input = torch.randn(1, 3, 640, 640).to(self.device)
  14. for model in [Models.PP_YOLOE_S, Models.PP_YOLOE_M, Models.PP_YOLOE_L, Models.PP_YOLOE_X]:
  15. model = models.get(model, pretrained_weights="coco").to(self.device).eval()
  16. model.replace_head(new_num_classes=100)
  17. (_, pred_scores), _ = model.forward(input)
  18. self.assertEqual(pred_scores.size(2), 100)
  19. def test_yolo_nas_replace_head(self):
  20. input = torch.randn(1, 3, 640, 640).to(self.device)
  21. for model in [Models.YOLO_NAS_S, Models.YOLO_NAS_M, Models.YOLO_NAS_L]:
  22. model = models.get(model, pretrained_weights="coco").to(self.device).eval()
  23. model.replace_head(new_num_classes=100)
  24. (_, pred_scores), _ = model.forward(input)
  25. self.assertEqual(pred_scores.size(2), 100)
  26. def tearDown(self) -> None:
  27. if os.path.exists("~/.cache/torch/hub/"):
  28. shutil.rmtree("~/.cache/torch/hub/")
  29. if __name__ == "__main__":
  30. unittest.main()
Discard