NVIDIA-AI-IOT / torch2trt

An easy to use PyTorch to TensorRT converter
MIT License
4.55k stars 671 forks source link

mmsegmentation model error with torch2trt #548

Open hannes09 opened 3 years ago

hannes09 commented 3 years ago

I tried to create a .engine file form my mmsegemetation pytorch model with the following script:

import sys
sys.path.insert(0,'/workspace/torch2trt')
sys.path.insert(1,'/workspace/mmsegmentation')
import torch
from torch2trt import torch2trt
from mmseg.apis import init_segmentor
import os.path

config_file = 'models/hrnet.py'
checkpoint_file = 'models/hrnet.pth'

# build the model from a config file and a checkpoint file
model = init_segmentor(config_file, checkpoint_file, device='cuda:0')
model = model.eval().cuda()

x = torch.ones((1, 3, 960, 1280)).cuda()

model_trt = torch2trt(model,inputs=x,
                                fp16_mode=False,
                                int8_mode=False,
                                max_workspace_size=1 << 28,
                                max_batch_size=1)

engine_path = 'test.engine'
with open(engine_path, "wb") as f:
    f.write(model_trt.engine.serialize())

I see the following error:

Use load_from_local loader
Traceback (most recent call last):
  File "torch2trt.py", line 22, in <module>
    max_batch_size=1)
  File "/workspace/torch2trt/torch2trt/torch2trt.py", line 517, in torch2trt
    outputs = module(*inputs)
  File "/opt/conda/lib/python3.6/site-packages/torch/nn/modules/module.py", line 577, in __call__
    result = self.forward(*input, **kwargs)
  File "/opt/conda/lib/python3.6/site-packages/mmcv/runner/fp16_utils.py", line 84, in new_func
    return old_func(*args, **kwargs)
TypeError: forward() missing 1 required positional argument: 'img_metas'
aftertas-e commented 3 years ago

I'm facing the same problem. Have you solved this problem?

selimceylan commented 2 years ago

Same issue, did you find any solution ?

romil611 commented 2 years ago

If any of you solved this issue then please reply and help us out.

Liufanfanfan commented 2 weeks ago

1