使用involution_cuda.py,发生了错误
Dontfall opened this issue · 9 comments
想yolov5在中使用involution代替conv,使用involution_naive.py 的时候,运行是没问题的。
但是使用involution_cuda.py,在_involution_cuda函数处出现了问题,报出了NotImplementedError。
恳请作者帮忙看看。
Traceback (most recent call last):
File "train.py", line 532, in
train(hyp, opt, device, tb_writer, wandb)
File "train.py", line 87, in train
model = Model(opt.cfg, ch=3, nc=nc).to(device) # create
File "/home/admin/xiewei/yolov5/models/yolo.py", line 88, in init
m.stride = torch.tensor([s / x.shape[-2] for x in self.forward(torch.zeros(1, ch, s, s))]) # forward
File "/home/admin/xiewei/yolov5/models/yolo.py", line 118, in forward
return self.forward_once(x, profile) # single-scale inference, train
File "/home/admin/xiewei/yolov5/models/yolo.py", line 134, in forward_once
x = m(x) # run
File "/home/admin/anaconda3/envs/pytorch1.7.0-gpu/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
File "/home/admin/xiewei/yolov5/models/experimental.py", line 286, in forward
out = _involution_cuda(x, weight, stride=self.stride, padding=(self.kernel_size-1)//2)
File "/home/admin/xiewei/yolov5/models/experimental.py", line 247, in _involution_cuda
raise NotImplementedError
NotImplementedError
It is very likely that you are running on the CPU device instead of GPU. Notice the if-else logic here.
It is very likely that you are running on the CPU device instead of GPU. Notice the if-else logic here.
作者大大,我用的是2080 Ti
Could you pls show your code around "/home/admin/xiewei/yolov5/models/experimental.py" line 247?
Could you pls show your code around "/home/admin/xiewei/yolov5/models/experimental.py" line 247?
您好,谢谢您的回复,
我是完全复制https://github.com/d-li14/involution/blob/main/det/mmdet/models/utils/involution_cuda.py,
return grad_input, grad_weight, None, None, None
def _involution_cuda(input, weight, bias=None, stride=1, padding=0, dilation=1):
""" involution kernel
"""
assert input.size(0) == weight.size(0)
assert input.size(-2)//stride == weight.size(-2)
assert input.size(-1)//stride == weight.size(-1)
if input.is_cuda:
out = _involution.apply(input, weight, _pair(stride), _pair(padding), _pair(dilation))
if bias is not None:
out += bias.view(1,-1,1,1)
else:
raise NotImplementedError
return out
class involution(nn.Module):
If you are using my code without modification, NotImplementedError
means the condition input.is_cuda
is not satisfied.
Could you pls show your code around "/home/admin/xiewei/yolov5/models/experimental.py" line 247?
您好,谢谢您的回复,
我是完全复制https://github.com/d-li14/involution/blob/main/det/mmdet/models/utils/involution_cuda.py,return grad_input, grad_weight, None, None, None
def _involution_cuda(input, weight, bias=None, stride=1, padding=0, dilation=1):
""" involution kernel
"""
assert input.size(0) == weight.size(0)
assert input.size(-2)//stride == weight.size(-2)
assert input.size(-1)//stride == weight.size(-1)
if input.is_cuda:
out = _involution.apply(input, weight, _pair(stride), _pair(padding), _pair(dilation))
if bias is not None:
out += bias.view(1,-1,1,1)
else:
raise NotImplementedErrorreturn out
class involution(nn.Module):
你的报错信息已经很明显了,你输入的tensor不是放在GPU,而是CPU上的。
如果你确定不是用cpu来训练的,就看一看有没有输出网络的信息(例如输出网络多大,有哪些网络层,Flops多少)的这种代码。这种代码有可能是输入一个(1, 3, H, W)的tensor,通过跑一轮网络来获取网络的信息,这个输入的tensor有可能不是放在GPU上的,所以会报错。
我也出现了这个问题,请问您解决了吗?
@Dontfall 我也出现了这个问题,请问您解决了吗?