0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ハマクラAdvent Calendar 2024

Day 18

PyTorch→ONNX→TensorRTの変換

Posted at

研究室でTensorRTのモデルをC++で動かして推論をしているのですが、毎回変換の細かい手順を忘れるので書き残しておきます。
特にONNX→TensorRTの変換に癖があって、私の経験上だと入力テンソルの大きさが可変だとだいたいうまくいきません。

PyTorch→ONNX

convert.py
import torch
import torch.onnx

model = MyModel()
model.load_state_dict(torch.load('hoge.pth'))

torch.onnx.export(model, torch.randn((1,3,720,1280)), 'hoge.onnx')

ONNX→TensorRT

trtexecを使います

trtexec --onnx=hoge.onnx --saveEngine=hoge.trt
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?