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

代码运行问题 #13

Open
Luckycat518 opened this issue Oct 16, 2022 · 8 comments
Open

代码运行问题 #13

Luckycat518 opened this issue Oct 16, 2022 · 8 comments

Comments

@Luckycat518
Copy link

您好,我在将您的代码配置在yolov5-v6.0版本上进行训练时,出现了如下错误,您知道如何解决吗?
line 376, in kaiming_uniform_
std = gain / math.sqrt(fan)
ZeroDivisionError: float division by zero

@AlanLi1997
Copy link
Owner

您好,我在将您的代码配置在yolov5-v6.0版本上进行训练时,出现了如下错误,您知道如何解决吗? line 376, in kaiming_uniform_ std = gain / math.sqrt(fan) ZeroDivisionError: float division by zero

你好,该仓库包含的yolov5代码版本为v6.1,更新您的代码库为v6.1即可,或选择克隆本仓库的yolov5代码到本地或服务器端运行🍺

@Luckycat518
Copy link
Author

好的,谢谢您,现在又遇到一个问题AttributeError: module 'torch.nn' has no attribute 'Mish',这是torch版本的问题还是哪里没设置好呢?我的torch版本是1.8.0

@AlanLi1997
Copy link
Owner

AlanLi1997 commented Oct 16, 2022

好的,谢谢您,现在又遇到一个问题AttributeError: module 'torch.nn' has no attribute 'Mish',这是torch版本的问题还是哪里没设置好呢?我的torch版本是1.8.0

请将以下代码copy至common.py(注意缩进),并将原代码中的 nn.Mish 字段更改为 Mish 字段。

class Mish(nn.Module):
@staticmethod
def forward(x):
return x * torch.nn.functional.softplus(x).tanh()

@Luckycat518
Copy link
Author

好的,解决了,十分感谢您的耐心解答~

@llillei
Copy link

llillei commented Dec 28, 2023

您好,我在将您的代码配置在yolov5-v7.0版本上进行训练时,出现了如下错误,您知道如何解决吗?
TypeError: conv2d() received an invalid combination of arguments - got (Tensor, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:

  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
    didn't match because some of the arguments have invalid types: (Tensor, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (bool, bool)!, int)
  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
    didn't match because some of the arguments have invalid types: (Tensor, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (bool, bool)!, int)

详细报错信息如下
Traceback (most recent call last):
File "E:\PycharmProjects\yolov5-7.0\train_mycar.py", line 635, in
main(opt)
File "E:\PycharmProjects\yolov5-7.0\train_mycar.py", line 529, in main
train(opt.hyp, opt, device, callbacks)
File "E:\PycharmProjects\yolov5-7.0\train_mycar.py", line 125, in train
model = Model(cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device) # create
File "E:\PycharmProjects\yolov5-7.0\models\yolo.py", line 195, in init
m.stride = torch.tensor([s / x.shape[-2] for x in forward(torch.zeros(1, ch, s, s))]) # forward
File "E:\PycharmProjects\yolov5-7.0\models\yolo.py", line 194, in
forward = lambda x: self.forward(x)[0] if isinstance(m, Segment) else self.forward(x)
File "E:\PycharmProjects\yolov5-7.0\models\yolo.py", line 209, in forward
return self._forward_once(x, profile, visualize) # single-scale inference, train
File "E:\PycharmProjects\yolov5-7.0\models\yolo.py", line 121, in _forward_once
x = m(x) # run
File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "E:\PycharmProjects\yolov5-7.0\models\common.py", line 1069, in forward
x1 = self.cv1(x)
File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "E:\PycharmProjects\yolov5-7.0\models\common.py", line 58, in forward
return self.act(self.bn(self.conv(x)))
File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
return forward_call(*args, **kwargs)
File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\conv.py", line 460, in forward
return self._conv_forward(input, self.weight, self.bias)
File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\conv.py", line 456, in _conv_forward
return F.conv2d(input, weight, bias, self.stride,
TypeError: conv2d() received an invalid combination of arguments - got (Tensor, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:

  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
    didn't match because some of the arguments have invalid types: (Tensor, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (bool, bool)!, int)
  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
    didn't match because some of the arguments have invalid types: (Tensor, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (bool, bool)!, int)

@AlanLi1997
Copy link
Owner

您好,我在将您的代码配置在yolov5-v7.0版本上进行训练时,出现了如下错误,您知道如何解决吗? TypeError: conv2d() received an invalid combination of arguments - got (Tensor, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:

  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
    didn't match because some of the arguments have invalid types: (Tensor, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (bool, bool)!, int)
  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
    didn't match because some of the arguments have invalid types: (Tensor, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (bool, bool)!, int)

详细报错信息如下 Traceback (most recent call last): File "E:\PycharmProjects\yolov5-7.0\train_mycar.py", line 635, in main(opt) File "E:\PycharmProjects\yolov5-7.0\train_mycar.py", line 529, in main train(opt.hyp, opt, device, callbacks) File "E:\PycharmProjects\yolov5-7.0\train_mycar.py", line 125, in train model = Model(cfg or ckpt['model'].yaml, ch=3, nc=nc, anchors=hyp.get('anchors')).to(device) # create File "E:\PycharmProjects\yolov5-7.0\models\yolo.py", line 195, in init m.stride = torch.tensor([s / x.shape[-2] for x in forward(torch.zeros(1, ch, s, s))]) # forward File "E:\PycharmProjects\yolov5-7.0\models\yolo.py", line 194, in forward = lambda x: self.forward(x)[0] if isinstance(m, Segment) else self.forward(x) File "E:\PycharmProjects\yolov5-7.0\models\yolo.py", line 209, in forward return self._forward_once(x, profile, visualize) # single-scale inference, train File "E:\PycharmProjects\yolov5-7.0\models\yolo.py", line 121, in _forward_once x = m(x) # run File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl return forward_call(*args, **kwargs) File "E:\PycharmProjects\yolov5-7.0\models\common.py", line 1069, in forward x1 = self.cv1(x) File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl return forward_call(*args, **kwargs) File "E:\PycharmProjects\yolov5-7.0\models\common.py", line 58, in forward return self.act(self.bn(self.conv(x))) File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl return forward_call(*args, **kwargs) File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\conv.py", line 460, in forward return self._conv_forward(input, self.weight, self.bias) File "E:\develop\anaconda\envs\yolov57\lib\site-packages\torch\nn\modules\conv.py", line 456, in _conv_forward return F.conv2d(input, weight, bias, self.stride, TypeError: conv2d() received an invalid combination of arguments - got (Tensor, Parameter, NoneType, tuple, tuple, tuple, int), but expected one of:

  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, tuple of ints padding, tuple of ints dilation, int groups)
    didn't match because some of the arguments have invalid types: (Tensor, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (bool, bool)!, int)
  • (Tensor input, Tensor weight, Tensor bias, tuple of ints stride, str padding, tuple of ints dilation, int groups)
    didn't match because some of the arguments have invalid types: (Tensor, !Parameter!, !NoneType!, !tuple of (int, int)!, !tuple of (int, int)!, !tuple of (bool, bool)!, int)

你好,我猜测可能是7.0版本的基础卷积代码更新导致的,你可以尝试使用下面的GSConv代码:


class GSConv(nn.Module):
    # GSConv https://github.com/AlanLi1997/slim-neck-by-gsconv
    def __init__(self, c1, c2, k=1, s=1, g=1, d=1, act=True):
        super().__init__()
        c_ = c2 // 2
        self.cv1 = Conv(c1, c_, k, s, None, g, d, act)
        self.cv2 = Conv(c_, c_, 5, 1, None, c_, d, act)

    def forward(self, x):
        x1 = self.cv1(x)
        x2 = torch.cat((x1, self.cv2(x1)), 1)
        # shuffle
        y = x2.reshape(x2.shape[0], 2, x2.shape[1] // 2, x2.shape[2], x2.shape[3])
        y = y.permute(0, 2, 1, 3, 4)
        return y.reshape(y.shape[0], -1, y.shape[3], y.shape[4])

请注意,7.0版本新增了参数‘d’ (c1, c2, k, s, g, d, act),你必须让任何调用了‘GSConv’和‘Conv’类的那些类的传入参数的个数正确。

@harryc7
Copy link

harryc7 commented Feb 7, 2024

'ReLU' object has no attribute 'dim',用yolov5-6.1报了这个错误,应该如何解决

@AlanLi1997
Copy link
Owner

'ReLU' object has no attribute 'dim',用yolov5-6.1报了这个错误,应该如何解决

你需要提供完整的报错信息让我更好地帮你定位和修复错误。我猜测你可能使用了GSConvs(使用了ReLU),尝试使用GSConv.

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

4 participants