Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'module' object is not callable #370

Open
songqi-github opened this issue Jul 25, 2020 · 13 comments
Open

TypeError: 'module' object is not callable #370

songqi-github opened this issue Jul 25, 2020 · 13 comments

Comments

@songqi-github
Copy link

songqi-github commented Jul 25, 2020

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
Copy link
Author

waiting for your answer! THX!

@jaybdub
Copy link
Contributor

jaybdub commented Jul 30, 2020

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

@yashraj02
Copy link

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

@songqi-github
Copy link
Author

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
Copy link
Author

hi @yashraj02 Have you solved this problem?

@swpucl
Copy link

swpucl commented Sep 10, 2020

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

@sjtuherisson
Copy link

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

@WeibinDai
Copy link

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

@Tony-Yan2018
Copy link

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!

@OronG13
Copy link

OronG13 commented Apr 20, 2021

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

@niranjanravilevelup
Copy link

niranjanravilevelup commented Jun 29, 2021

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

@chainfitness
Copy link

@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
Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants