训练YOLOV3报错TypeError: not all arguments converted during string formatting

训练YOLOV3报错TypeError: not all arguments converted during string formatting

问题描述

pytorch下yolov3训练自己的数据集,报错:

Traceback (most recent call last):
  File "train.py", line 431, in <module>
    train(hyp)  # train normally
  File "train.py", line 91, in train
    model = Darknet(cfg).to(device)
  File "C:\Users\pippy\Desktop\yolov3-master\models.py", line 226, in __init__
    self.module_list, self.routs = create_modules(self.module_defs, img_size, cfg)
  File "C:\Users\pippy\Desktop\yolov3-master\models.py", line 33, in create_modules
    bias=not bn))
  File "C:\Users\pippy\AppData\Roaming\Python\Python37\site-packages\torch\nn\modules\conv.py", line 332, in __init__
    False, _pair(0), groups, bias, padding_mode)
  File "C:\Users\pippy\AppData\Roaming\Python\Python37\site-packages\torch\nn\modules\conv.py", line 24, in __init__
    if out_channels % groups != 0:
TypeError: not all arguments converted during string formatting

报错原因是求余符号两边得是数字(if out_channels % groups != 0),不知道别人为什么没有出现这个问题,原程序models.py中也确实没有int我们的groups,所以抱着试一试的心态添加了int,发现竟然可行,models.py中的修改部分如下(大约在源程序21-33行的位置):

 if mdef['type'] == 'convolutional':
            bn = int(mdef['batch_normalize'])
            filters = int(mdef['filters'])
            k = int(mdef['size'])  # kernel size
            stride = int(mdef['stride']) if 'stride' in mdef else (mdef['stride_y'], mdef['stride_x'])
            if isinstance(k, int):  # single-size conv
                modules.add_module('Conv2d',nn.Conv2d(in_channels=output_filters[-1],
                                                       out_channels=filters,
                                                       kernel_size=k,
                                                       stride=stride,
                                                       padding=k // 2 if mdef['pad'] else 0,
                                                       groups=int(mdef['groups']) if 'groups' in mdef else 1,
                                                       bias=not bn))
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值