Skip to main content

A simple package that wraps PyTorch models conversion to ONNX and TensorRT

Project description

Convert PyTorch models to ONNX and then to TensorRT

Build Status

Requirements

  1. Python 3.6 or 3.8
  2. PyTorch (1.9 or higher is required)
  3. TensorRT (tested with 8.0)
  4. The rest of the requirements are listed in requirements.txt and can be installed automatically via pip 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

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


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.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

torch2onnx2trt-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file torch2onnx2trt-0.1.1.tar.gz.

File metadata

  • Download URL: torch2onnx2trt-0.1.1.tar.gz
  • Upload date:
  • Size: 5.9 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

Hashes for torch2onnx2trt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e7eb43a2b72891d8aa363f7e6d2fdd47f825c1f12a6d061e5cc3a077c2d051b9
MD5 ba6e1a61794fa16163aeb106c933da57
BLAKE2b-256 ad58c75decd74bf816ef28753a796f822300b8a6f4e7319a5aa5923a7eab5dce

See more details on using hashes here.

File details

Details for the file torch2onnx2trt-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: torch2onnx2trt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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

Hashes for torch2onnx2trt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 57ae0f5df4beccc0bf135011f53a5fcb0a280492d1b2ec29aa9bd7826365a2f6
MD5 32de792e62dfe0d74bb36cd57ca73ff3
BLAKE2b-256 cb9d993f4ad1bcf45e9fd9ae51b82bb492d83989aa9a6fe9837bc36e9e0b72d5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page