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

test_without_train_test.py 2.7 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
  1. import shutil
  2. import unittest
  3. import os
  4. from super_gradients import Trainer
  5. from super_gradients.training.dataloaders.dataloaders import classification_test_dataloader, detection_test_dataloader, segmentation_test_dataloader
  6. from super_gradients.training.metrics import Accuracy, Top5
  7. from super_gradients.training import MultiGPUMode, models
  8. from super_gradients.training.metrics.detection_metrics import DetectionMetrics
  9. from super_gradients.training.metrics.segmentation_metrics import PixelAccuracy, IoU
  10. from super_gradients.training.models.detection_models.yolo_base import YoloPostPredictionCallback
  11. class TestWithoutTrainTest(unittest.TestCase):
  12. @classmethod
  13. def setUp(cls):
  14. # NAMES FOR THE EXPERIMENTS TO LATER DELETE
  15. cls.folder_names = ["test_classification_model", "test_detection_model", "test_segmentation_model"]
  16. @classmethod
  17. def tearDownClass(cls) -> None:
  18. # ERASE ALL THE FOLDERS THAT WERE CREATED DURING THIS TEST
  19. for folder in cls.folder_names:
  20. if os.path.isdir(os.path.join("checkpoints", folder)):
  21. shutil.rmtree(os.path.join("checkpoints", folder))
  22. @staticmethod
  23. def get_classification_trainer(name=""):
  24. trainer = Trainer(name)
  25. model = models.get("resnet18", num_classes=5)
  26. return trainer, model
  27. @staticmethod
  28. def get_detection_trainer(name=""):
  29. trainer = Trainer(name, multi_gpu=MultiGPUMode.OFF)
  30. model = models.get("yolox_s", num_classes=5)
  31. return trainer, model
  32. @staticmethod
  33. def get_segmentation_trainer(name=""):
  34. shelfnet_lw_arch_params = {"num_classes": 5}
  35. trainer = Trainer(name)
  36. model = models.get("shelfnet34_lw", arch_params=shelfnet_lw_arch_params)
  37. return trainer, model
  38. def test_test_without_train(self):
  39. trainer, model = self.get_classification_trainer(self.folder_names[0])
  40. assert isinstance(
  41. trainer.test(model=model, silent_mode=True, test_metrics_list=[Accuracy(), Top5()], test_loader=classification_test_dataloader()), tuple
  42. )
  43. trainer, model = self.get_detection_trainer(self.folder_names[1])
  44. test_metrics = [DetectionMetrics(post_prediction_callback=YoloPostPredictionCallback(), num_cls=5)]
  45. assert isinstance(
  46. trainer.test(model=model, silent_mode=True, test_metrics_list=test_metrics, test_loader=detection_test_dataloader(image_size=320)), tuple
  47. )
  48. trainer, model = self.get_segmentation_trainer(self.folder_names[2])
  49. assert isinstance(
  50. trainer.test(model=model, silent_mode=True, test_metrics_list=[IoU(21), PixelAccuracy()], test_loader=segmentation_test_dataloader()), tuple
  51. )
  52. if __name__ == "__main__":
  53. unittest.main()
Tip!

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

Comments

Loading...