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

export_onnx_test.py 1.6 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
  1. import os
  2. import tempfile
  3. import unittest
  4. from torchvision.transforms import Compose, Normalize, Resize
  5. from super_gradients.common.object_names import Models
  6. from super_gradients.training import models
  7. from super_gradients.training.transforms import Standardize
  8. class TestModelsONNXExport(unittest.TestCase):
  9. def test_models_onnx_export_with_deprecated_input_shape(self):
  10. pretrained_model = models.get(Models.RESNET18, num_classes=1000, pretrained_weights="imagenet")
  11. preprocess = Compose([Resize(224), Standardize(), Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])
  12. with tempfile.TemporaryDirectory() as tmpdirname:
  13. out_path = os.path.join(tmpdirname, "resnet18.onnx")
  14. models.convert_to_onnx(model=pretrained_model, out_path=out_path, input_shape=(3, 256, 256), pre_process=preprocess)
  15. self.assertTrue(os.path.exists(out_path))
  16. def test_models_onnx_export(self):
  17. pretrained_model = models.get(Models.RESNET18, num_classes=1000, pretrained_weights="imagenet")
  18. preprocess = Compose([Resize(224), Standardize(), Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])
  19. with tempfile.TemporaryDirectory() as tmpdirname:
  20. out_path = os.path.join(tmpdirname, "resnet18.onnx")
  21. models.convert_to_onnx(
  22. model=pretrained_model, out_path=out_path, pre_process=preprocess, prep_model_for_conversion_kwargs=dict(input_size=(1, 3, 640, 640))
  23. )
  24. self.assertTrue(os.path.exists(out_path))
  25. if __name__ == "__main__":
  26. unittest.main()
Tip!

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

Comments

Loading...