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.8 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
  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, \
  6. detection_test_dataloader, segmentation_test_dataloader
  7. from super_gradients.training.metrics import Accuracy, Top5
  8. from super_gradients.training import MultiGPUMode, models
  9. from super_gradients.training.metrics.detection_metrics import DetectionMetrics
  10. from super_gradients.training.metrics.segmentation_metrics import PixelAccuracy, IoU
  11. from super_gradients.training.models.detection_models.yolo_base import YoloPostPredictionCallback
  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("resnet18", num_classes=5)
  27. return trainer, model
  28. @staticmethod
  29. def get_detection_trainer(name=''):
  30. trainer = Trainer(name,
  31. multi_gpu=MultiGPUMode.OFF)
  32. model = models.get("yolox_s", num_classes=5)
  33. return trainer, model
  34. @staticmethod
  35. def get_segmentation_trainer(name=''):
  36. shelfnet_lw_arch_params = {"num_classes": 5}
  37. trainer = Trainer(name)
  38. model = models.get('shelfnet34_lw', arch_params=shelfnet_lw_arch_params)
  39. return trainer, model
  40. def test_test_without_train(self):
  41. trainer, model = self.get_classification_trainer(self.folder_names[0])
  42. assert isinstance(trainer.test(model=model, silent_mode=True,
  43. test_metrics_list=[Accuracy(), Top5()], test_loader=classification_test_dataloader()), tuple)
  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(trainer.test(model=model, silent_mode=True,
  47. test_metrics_list=test_metrics, test_loader=detection_test_dataloader(image_size=320)), tuple)
  48. trainer, model = self.get_segmentation_trainer(self.folder_names[2])
  49. assert isinstance(trainer.test(model=model, silent_mode=True,
  50. test_metrics_list=[IoU(21), PixelAccuracy()], test_loader=segmentation_test_dataloader()), tuple)
  51. if __name__ == '__main__':
  52. unittest.main()
Tip!

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

Comments

Loading...