torch2trt icon indicating copy to clipboard operation
torch2trt copied to clipboard

TypeError: 'module' object is not callable

Open songqi-github opened this issue 4 years ago • 13 comments

hi, when I was running this code:

import torch import os from torch2trt import torch2trt from torchvision.models.resnet import resnet18

os.environ["CUDA_VISIBLE_DEVICES"]="2" model = resnet18(pretrained=True).eval().cuda() x = torch.ones((1, 3, 224, 224)).cuda() model_trt = torch2trt(model, [x]) torch.save(model_trt.state_dict(), 'resnet18_trt.pth')

then, there comes out "TypeError: 'module' object is not callable" how can I fix that?

songqi-github avatar Jul 25 '20 11:07 songqi-github

waiting for your answer! THX!

songqi-github avatar Jul 27 '20 06:07 songqi-github

Hi songqi-github,

Thanks for reaching out!

Do you witness this behavior without os.environ["CUDA_VISIBLE_DEVICES"]="2"?

Also, do you mind sharing

  • PyTorch Version
  • TensorRT version
  • Torchvision Version
  • Platform (ie: Jetson Xavier, etc.)

Best, John

jaybdub avatar Jul 30 '20 09:07 jaybdub

Hi even I am getting the same error any help highly appreciated!!

load net

cfg = widerface_640 num_classes = len(WIDERFace_CLASSES) + 1 # +1 background net = build_ssd('test', cfg['min_dim'], num_classes) # initialize SSD net.load_state_dict(torch.load(args.trained_model))

net.cuda() net.eval()

import tensorrt as trt data = torch.randn((1, 3, 640, 640)) data = torch.cuda.FloatTensor(data) temp = torch2trt(net, [data])

Traceback (most recent call last): File "widerface_val.py", line 249, in temp = torch2trt(net, [data]) TypeError: 'module' object is not callable

yashraj02 avatar Jul 30 '20 15:07 yashraj02

Hi, I got the same error without os.environ["CUDA_VISIBLE_DEVICES"]="2".

PyTorch Version==1.3.0 TensorRT version==6.0.1.5 Torchvision Version==0.4.1

songqi-github avatar Jul 31 '20 02:07 songqi-github

hi @yashraj02 Have you solved this problem?

songqi-github avatar Aug 03 '20 13:08 songqi-github

@songqi-github I get the same error.Do you solve it?

swpucl avatar Sep 10 '20 02:09 swpucl

anyone use 'import torch2trt' replace 'from torch2trt import torch2trt' ?

sjtuherisson avatar Jan 27 '21 08:01 sjtuherisson

Hi, all. I meet the same problem, have anyone alreadly solved this issue?

WeibinDai avatar Feb 07 '21 08:02 WeibinDai

Hi guys, I think what you should write is model_trt = torch2trt.torch2trt(model, [x]) instead of model_trt = torch2trt(model, [x]). Hope this helps!

Tony-Yan2018 avatar Mar 10 '21 05:03 Tony-Yan2018

@Tony-Yan2018 Yes, your answer help me and now it works well! Thanks

OronG13 avatar Apr 20 '21 07:04 OronG13

Hi @jaybdub , I am facing the same error. I tried the above suggestion. It dint work. Any other alternatives?

niranjanravilevelup avatar Jun 29 '21 19:06 niranjanravilevelup

@Tony-Yan2018 appreciate your advice, I tried it but the new error torch2trt has no attribute torch2trt was acquired. could you help me? thanks in advance

Hi guys, I think what you should write is model_trt = torch2trt.torch2trt(model, [x]) instead of model_trt = torch2trt(model, [x]). Hope this helps!

chainfitness avatar Mar 21 '22 02:03 chainfitness

@sjtuherisson I used it replaced. but the 'module' object is not callable was acquired.

anyone use 'import torch2trt' replace 'from torch2trt import torch2trt' ?

chainfitness avatar Mar 21 '22 02:03 chainfitness