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_convert_recipe_to_code.py 4.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  1. import ast
  2. import tempfile
  3. import pkg_resources
  4. import unittest
  5. from super_gradients.convert_recipe_to_code import convert_recipe_to_code
  6. from pathlib import Path
  7. class TestConvertRecipeToCode(unittest.TestCase):
  8. def setUp(self) -> None:
  9. self.recipes_dir: Path = Path(pkg_resources.resource_filename("super_gradients.recipes", ""))
  10. self.recipes_that_should_work = [
  11. "cifar10_resnet.yaml",
  12. "cityscapes_al_ddrnet.yaml",
  13. "cityscapes_ddrnet.yaml",
  14. "cityscapes_pplite_seg50.yaml",
  15. "cityscapes_pplite_seg75.yaml",
  16. "cityscapes_regseg48.yaml",
  17. "cityscapes_segformer_b0.yaml",
  18. "cityscapes_segformer_b1.yaml",
  19. "cityscapes_segformer_b2.yaml",
  20. "cityscapes_segformer_b3.yaml",
  21. "cityscapes_segformer_b4.yaml",
  22. "cityscapes_segformer_b5.yaml",
  23. "cityscapes_stdc_base.yaml",
  24. "cityscapes_stdc_seg50.yaml",
  25. "cityscapes_stdc_seg75.yaml",
  26. "coco2017_pose_dekr_rescoring.yaml",
  27. "coco2017_pose_dekr_w32_no_dc.yaml",
  28. "coco2017_ppyoloe_l.yaml",
  29. "coco2017_ppyoloe_m.yaml",
  30. "coco2017_ppyoloe_s.yaml",
  31. "coco2017_ppyoloe_x.yaml",
  32. "coco2017_ssd_lite_mobilenet_v2.yaml",
  33. "coco2017_yolo_nas_s.yaml",
  34. "coco2017_yolox.yaml",
  35. "coco_segmentation_shelfnet_lw.yaml",
  36. "imagenet_efficientnet.yaml",
  37. "imagenet_mobilenetv2.yaml",
  38. "imagenet_mobilenetv3_large.yaml",
  39. "imagenet_mobilenetv3_small.yaml",
  40. "imagenet_regnetY.yaml",
  41. "imagenet_repvgg.yaml",
  42. "imagenet_resnet50.yaml",
  43. "imagenet_vit_base.yaml",
  44. "imagenet_vit_large.yaml",
  45. "supervisely_unet.yaml",
  46. "user_recipe_mnist_as_external_dataset_example.yaml",
  47. "user_recipe_mnist_example.yaml",
  48. "coco2017_yolo_nas_pose_m.yaml",
  49. "coco2017_yolo_nas_pose_l.yaml",
  50. "coco2017_yolo_nas_pose_n.yaml",
  51. "coco2017_yolo_nas_pose_s.yaml",
  52. ]
  53. self.recipes_that_does_not_work = [
  54. "cityscapes_kd_base.yaml", # KD recipe not supported
  55. "imagenet_resnet50_kd.yaml", # KD recipe not supported
  56. "imagenet_mobilenetv3_base.yaml", # Base recipe (not complete) for other MobileNetV3 recipes
  57. "cityscapes_segformer.yaml", # Base recipe (not complete) for other SegFormer recipes
  58. "roboflow_ppyoloe.yaml", # Require explicit command line arguments
  59. "roboflow_yolo_nas_m.yaml", # Require explicit command line arguments
  60. "roboflow_yolo_nas_s.yaml", # Require explicit command line arguments
  61. "roboflow_yolo_nas_s_qat.yaml", # Require explicit command line arguments
  62. "roboflow_yolox.yaml", # Require explicit command line arguments
  63. "variable_setup.yaml", # Not a recipe
  64. "script_generate_rescoring_data_dekr_coco2017.yaml", # Not a recipe
  65. ]
  66. def test_all_recipes_are_tested(self):
  67. present_recipes = set(recipe.name for recipe in self.recipes_dir.glob("*.yaml"))
  68. known_recipes = set(self.recipes_that_should_work + self.recipes_that_does_not_work)
  69. new_recipes = present_recipes - known_recipes
  70. removed_recipes = known_recipes - present_recipes
  71. if len(new_recipes):
  72. self.fail(f"New recipes found: {new_recipes}. Please add them to the list of recipes to test.")
  73. if len(removed_recipes):
  74. self.fail(f"Removed recipes found: {removed_recipes}. Please remove them from the list of recipes to test.")
  75. def test_convert_recipes_that_should_work(self):
  76. with tempfile.TemporaryDirectory() as temp_dir:
  77. for recipe in self.recipes_that_should_work:
  78. with self.subTest(recipe=recipe):
  79. output_script_path = Path(temp_dir) / Path(recipe).name
  80. convert_recipe_to_code(recipe, self.recipes_dir, output_script_path)
  81. src = output_script_path.read_text()
  82. try:
  83. ast.parse(src)
  84. except SyntaxError as e:
  85. self.fail(f"Recipe {recipe} failed to convert to python script: {e}")
  86. def test_convert_recipes_that_are_expected_to_fail(self):
  87. with tempfile.TemporaryDirectory() as temp_dir:
  88. for recipe in self.recipes_that_does_not_work:
  89. with self.subTest(recipe=recipe):
  90. output_script_path = Path(temp_dir) / Path(recipe).name
  91. with self.assertRaises(Exception):
  92. convert_recipe_to_code(recipe, self.recipes_dir, output_script_path)
  93. if __name__ == "__main__":
  94. unittest.main()
Tip!

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

Comments

Loading...