Skip to content

This is an mnist example of how to transfer a .pt file to .onnx, then transfer .onnx file to .trt file.

License

Notifications You must be signed in to change notification settings

ycchen218/Pytorch-to-TensorRT-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pytorch-to-TensorRT-example

image

Introduce

All in Python
This is an MNIST example demonstrating how to convert a .pt file to an .ONNX file, and subsequently transform the .ONNX file into a .TRT file. Additionally, it illustrates how to save the .TRT file in FP16 mode, which can reduce memory usage and accelerate computation. Importantly, I also provide TensorRT inference code for reference. This code can assist you in efficiently performing inference using the created .TRT file, thereby enhancing your understanding of the process.

Requirement

  1. python3.8
  2. tensorrt
  3. matplotlib
  4. numpy
  5. opencv
  6. pytorch 1.12.0
  7. torchvision

Execute

python main.py

The main.py file incude function as following:

  1. Train the mnist classifier and save the model in .pt file.
  2. Convert the .pt file to .onnx file.
  3. Convert the .onnx file to .trt file.

Inference the .trt model

python test_trt.py

Run the test_trt.py to Inference the mnist image prediction result.

Test Torch model

python test_pt.py

Run the test_pt.py to check the saved .pt model weight prediction result.

About

This is an mnist example of how to transfer a .pt file to .onnx, then transfer .onnx file to .trt file.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages