A simple package that wraps PyTorch models conversion to ONNX and TensorRT
Project description
Convert PyTorch models to ONNX and then to TensorRT
Requirements
- Python 3.6 or 3.8
- PyTorch (1.9 or higher is required)
- TensorRT (tested with 8.0)
- The rest of the requirements are listed in
requirements.txt
and can be installed automatically viapip
installation
The python version restriction is caused by pytorch-quantization package required for the conversion of quantised models
Alternatively, you can skip installation of the requirements and use this docker container
Installation
From pypi
The package can now be installed from pypi using command:
pip3 install torch2onnx2trt==0.1.1
From source
There is setup.py
file in the repo, so the installation is pretty
straightforward
git clone https://github.com/ucLh/torch2onnx2trt.git
cd torch2onnx2trt
pip3 install -e ./
Usage
import torch
from torch2onnx2trt import convert_torch2onnx, convert_onnx2trt
# Load your pretrained model
pretrained_model = YourModelClass()
ckpt = torch.load('ckpt.pth')
pretrained_model.load_state_dict(ckpt['state_dict'])
# You need to pass your model with loaded weights, an output path for onnx model
# and desired input shape to convert_torch2onnx function
convert_torch2onnx(pretrained_model, 'effnetb0_unet_gray_2grass_iou55.onnx', (1, 3, 640, 1280))
# convert_onnx2trt expects a path to onnx model and an output path for resulting
# TensorRT .bin model
convert_onnx2trt('../effnetb0_unet_gray_2grass_iou55.onnx', '../effnetb0_unet_gray_2grass_iou55.bin')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
torch2onnx2trt-0.1.2.tar.gz
(6.1 kB
view details)
Built Distribution
File details
Details for the file torch2onnx2trt-0.1.2.tar.gz
.
File metadata
- Download URL: torch2onnx2trt-0.1.2.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8a9ed3fafcdda83f6e4bc99ed3f56745f477c8b5f9a99b4e28494878e5f25dd |
|
MD5 | ed831b08020f7782d958786ee9af1470 |
|
BLAKE2b-256 | 6687c78afdd25ca89137cfd78cbc55724dbc660a3cba3af9c724f89c3a19666d |
File details
Details for the file torch2onnx2trt-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: torch2onnx2trt-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f00b63bb35704bd63ed46723e4fbb7d23bda616ad2f65542c7e7535a8b16773 |
|
MD5 | 711d682c66e5b3fad6ad47631d21d920 |
|
BLAKE2b-256 | 79e93d154fc76bd965394f9b607ba9551dbfa2eb22134c73229a844e9392a2ec |