torch2trt icon indicating copy to clipboard operation
torch2trt copied to clipboard

mmsegmentation model error with torch2trt

Open hannes09 opened this issue 4 years ago • 4 comments

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'

hannes09 avatar Apr 24 '21 11:04 hannes09

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

aftertas-e avatar Jul 13 '21 18:07 aftertas-e

Same issue, did you find any solution ?

selimceylan avatar Nov 25 '21 18:11 selimceylan

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

romil611 avatar Mar 28 '22 18:03 romil611