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

RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #2 'weight' #46

Closed
berylyellow opened this issue Dec 17, 2018 · 7 comments

Comments

@berylyellow
Copy link

I run by this:python3 main.py --scaleIn 8 --p 2 --q 8 --onGPU True
then get:
Total network parameters: 344841
/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/loss.py:206: UserWarning: NLLLoss2d has been deprecated. Please use NLLLoss instead as a drop-in replacement and see http://pytorch.org/docs/master/nn.html#torch.nn.NLLLoss for more details.
warnings.warn("NLLLoss2d has been deprecated. "
Data statistics
[103.45756 101.83934 101.728714] [69.51785 67.936035 64.71613 ]
[4.2652993 1.5139731]
Learning rate: 0.0005
Traceback (most recent call last):
File "main.py", line 408, in
trainValidateSegmentation(parser.parse_args())
File "main.py", line 334, in trainValidateSegmentation
train(args, trainLoader_scale1, model, criteria, optimizer, epoch)
File "main.py", line 97, in train
output = model(input_var)
File "/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/home/hh/programs/ESPNet_hh/train/Model.py", line 286, in forward
output0 = self.level1(input)
File "/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/home/hh/programs/ESPNet_hh/train/Model.py", line 33, in forward
output = self.conv(input)
File "/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/conv.py", line 301, in forward
self.padding, self.dilation, self.groups)
RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #2 'weight'
I followed by your code,and there is only one class for my dataset to segment. What happened to this porblem?How to change?

@sacmehta
Copy link
Owner

Seems like you don’t have cuda enabled device

@berylyellow
Copy link
Author

I have cuda V9.0.176,pytorch 0.4.1

@sacmehta
Copy link
Owner

Could you check the value of args.gpu in main.py file?

@sacmehta
Copy link
Owner

Also, this codebase doesn’t support PyTorch 0.4. Check software requirements

@berylyellow
Copy link
Author

Thanks for your help, it works for PyTorch 0.4 anyway. But another thing occurs when I finished training EspNet-C,I want to train ESPNet, but it says:
python3 main.py --scaleIn 1 --p 2 --q 8 --decoder True --pretrained ../pretrained/encoder/espnet_p_2_q_8.pth
Encoder loaded!
Total network parameters: 365109
/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/loss.py:206: UserWarning: NLLLoss2d has been deprecated. Please use NLLLoss instead as a drop-in replacement and see http://pytorch.org/docs/master/nn.html#torch.nn.NLLLoss for more details.
warnings.warn("NLLLoss2d has been deprecated. "
Data statistics
[103.45756 101.83934 101.728714] [69.51785 67.936035 64.71613 ]
[ 4.2652993 10.492059 10.492059 10.492059 10.492059 10.492059
10.492059 10.492059 10.492059 10.492059 10.492059 10.492059
10.492059 10.492059 10.492059 10.492059 10.492059 10.492059
10.492059 1.5139731]
Learning rate: 0.0005
Traceback (most recent call last):
File "main.py", line 415, in
trainValidateSegmentation(parser.parse_args())
File "main.py", line 338, in trainValidateSegmentation
train(args, trainLoader_scale1, model, criteria, optimizer, epoch)
File "main.py", line 98, in train
output = model(input_var)
File "/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/home/hh/programs/ESPNet_hh/train/Model.py", line 387, in forward
comb_l2_l3 = self.up_l2(self.combine_l2_l3(torch.cat([output1_C, output2_c], 1))) #RUM
File "/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/container.py", line 91, in forward
input = module(input)
File "/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/home/hh/.local/lib/python3.5/site-packages/torch/nn/modules/conv.py", line 691, in forward
output_padding, self.groups, self.dilation)
RuntimeError: CUDA error: out of memory
What does it mean? My device is free now.

@sacmehta
Copy link
Owner

What is the batch size? I used 6 for ESPNet

@berylyellow
Copy link
Author

Thanks for your help, it works.

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

2 participants