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

shortened_recipes_accuracy_test.py 2.2 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
  1. import unittest
  2. import shutil
  3. import os
  4. import torch
  5. from super_gradients.common.environment.checkpoints_dir_utils import get_checkpoints_dir_path
  6. class ShortenedRecipesAccuracyTests(unittest.TestCase):
  7. @classmethod
  8. def setUp(cls):
  9. cls.experiment_names = ["shortened_cifar10_resnet_accuracy_test", "shortened_coco2017_yolox_n_map_test", "shortened_cityscapes_regseg48_iou_test"]
  10. def test_shortened_cifar10_resnet_accuracy(self):
  11. self.assertTrue(self._reached_goal_metric(experiment_name="shortened_cifar10_resnet_accuracy_test", metric_value=0.9167, delta=0.05))
  12. def test_convert_shortened_cifar10_resnet(self):
  13. ckpt_dir = get_checkpoints_dir_path(experiment_name="shortened_cifar10_resnet_accuracy_test")
  14. self.assertTrue(os.path.exists(os.path.join(ckpt_dir, "ckpt_best.onnx")))
  15. def test_shortened_coco2017_yolox_n_map(self):
  16. self.assertTrue(self._reached_goal_metric(experiment_name="shortened_coco2017_yolox_n_map_test", metric_value=0.044, delta=0.02))
  17. def test_shortened_cityscapes_regseg48_iou(self):
  18. self.assertTrue(self._reached_goal_metric(experiment_name="shortened_cityscapes_regseg48_iou_test", metric_value=0.263, delta=0.05))
  19. @classmethod
  20. def _reached_goal_metric(cls, experiment_name: str, metric_value: float, delta: float):
  21. checkpoints_dir_path = get_checkpoints_dir_path(experiment_name=experiment_name)
  22. sd = torch.load(os.path.join(checkpoints_dir_path, "ckpt_best.pth"))
  23. metric_val_reached = sd["acc"].cpu().item()
  24. diff = abs(metric_val_reached - metric_value)
  25. print(
  26. "Goal metric value: " + str(metric_value) + ", metric value reached: " + str(metric_val_reached) + ",diff: " + str(diff) + ", delta: " + str(delta)
  27. )
  28. return diff <= delta
  29. @classmethod
  30. def tearDownClass(cls) -> None:
  31. # ERASE ALL THE FOLDERS THAT WERE CREATED DURING THIS TEST
  32. for experiment_name in cls.experiment_names:
  33. checkpoints_dir_path = get_checkpoints_dir_path(experiment_name=experiment_name)
  34. if os.path.isdir(checkpoints_dir_path):
  35. shutil.rmtree(checkpoints_dir_path)
  36. if __name__ == "__main__":
  37. unittest.main()
Tip!

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

Comments

Loading...