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

notebook_model_to_production.py 1.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
  1. from super_gradients.training import models
  2. import torch
  3. import infery
  4. # TODO:
  5. # There is no "base" notebook so I only wrote the commands and some visualizations that needed to do in Colab.
  6. # I'll be happy filling it all up when possible deploying (due to input problematic issue)
  7. def main():
  8. # TODO: State that all SG models can do that same process
  9. # Load pretrained model
  10. model = models.get("yolox_s", pretrained_weights="coco")
  11. # Prepare model for conversion
  12. model.eval()
  13. model.prep_model_for_conversion(input_size=[1, 3, 640, 640])
  14. # Create dummy input for model tracing, with shape [Batch x Channels x Width x Height]
  15. dummy_input = torch.randn([1, 3, 640, 640])
  16. # TODO: Visualize input (which won't be dummy input, but an image)
  17. # Create output path
  18. onnx_filename = "yolox_s.onnx"
  19. # Convert model to onnx
  20. torch.onnx.export(model, dummy_input, onnx_filename)
  21. # # TODO: Visualize onnx on netron?
  22. # Load model with infery
  23. model = infery.load(model_path=onnx_filename, framework_type='onnx', inference_hardware='gpu')
  24. # Predict
  25. output = model.predict(dummy_input.numpy())
  26. # TODO: Visualize output
  27. if __name__ == '__main__':
  28. main()
Tip!

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

Comments

Loading...