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

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

Comments

Loading...