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

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

Comments

Loading...