Hi,
My network has two layers; the first one is a cnn layer and the second is a linear layer. Also, I try to use gpu for running it. The linear layer is as following:
Traceback (most recent call last):
File "MyCNNCustomized_v6_based_on_MyCNN13.py", line 576, in <module>
outputs = net(current_image)
File "/home/zahra/.local/lib/python2.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(*input, **kwargs)
File "MyCNNCustomized_v6_based_on_MyCNN13.py", line 281, in forward
x = torch.atan(self.fc1(self.convZ.output_after_pooling.squeeze(0).squeeze(1)))
File "/home/zahra/.local/lib/python2.7/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(*input, **kwargs)
File "/home/zahra/.local/lib/python2.7/site-packages/torch/nn/modules/linear.py", line 92, in forward
return F.linear(input, self.weight, self.bias)
File "/home/zahra/.local/lib/python2.7/site-packages/torch/nn/functional.py", line 1408, in linear
output = input.matmul(weight.t())
RuntimeError: Expected object of backend CPU but got backend CUDA for argument #2 'mat2'
Thanks, you are right, I forgot to set the device for input as ‘cuda’.
Now, I have another problem that I appreciate it if you guide me about it, too:
The backward function of my customized cnn is sth like this:
I customized correlate2d and convovle2d by myself. After that, each run for each sample of data lasts about 15 seconds on CPU. For decreasing the time, I switched to GPU and I changed numpy to tensor. Unfortunately, the time increased to 3 mins.
Do you have any idea about how to improve the time?
@zahra Not sure how you have customised the correlate2d and convolve2d, but this is most likely due to copying back and forth, the tensors between device and host which is a slow process. Difficult to say more without looking at the code.