Converting .pt to tensorRT (.engine)

I have my own pretrained pytorch model that I want to convert to a TensorRT model (.engine), I run this python script:

import torch
from torch2trt import torch2trt
model = torch.load(‘/home/tto/himangy_mt_server/OpenNMT-py/models/1.pt’, map_location=torch.device(‘cpu’))
x = torch.ones((1, 3, 224, 224)).to(torch.device(‘cpu’))
m = torch2trt(model, )

got this error
Traceback (most recent call last):
File “/home/tto/himangy_mt_server/OpenNMT-py/convert.py”, line 11, in
m = torch2trt(model, )
File “/home/tto/himangy_mt_server/himangy-env/lib/python3.9/site-packages/torch2trt-0.4.0-py3.9.egg/torch2trt/torch2trt.py”, line 694, in torch2trt
outputs = module(*inputs)
TypeError: ‘dict’ object is not callable

when i print the keys of the model i am getting 5 keys
dict[‘model’,‘generator’,‘vocab’,‘opt’,‘optim’]

i tired of taking the model key in the dictionary like this
“”““model = model_dict[‘model’]””“”"

import torch
from torch2trt import torch2trt
model = torch.load(‘/home/tto/himangy_mt_server/OpenNMT-py/models/1.pt’, map_location=torch.device(‘cpu’))
model = model_dict[‘model’]
x = torch.ones((1, 3, 224, 224)).to(torch.device(‘cpu’))
m = torch2trt(model, )

still getting same error, what causes this error??

Hi,

Please refer to the example here.

If you still face the issue, you can also try the Pytorch model → ONNX model → TensorRT conversion.

Thank you.