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.
- python3.8
- tensorrt
- matplotlib
- numpy
- opencv
- pytorch 1.12.0
- torchvision
python main.py
The main.py file incude function as following:
- Train the mnist classifier and save the model in .pt file.
- Convert the .pt file to .onnx file.
- Convert the .onnx file to .trt file.
python test_trt.py
Run the test_trt.py to Inference the mnist image prediction result.
python test_pt.py
Run the test_pt.py to check the saved .pt model weight prediction result.