当前位置: 移动技术网 > IT编程>脚本编程>Python > 训练YOLOV3报错TypeError: not all arguments converted during string formatting

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

2020年07月05日  | 移动技术网IT编程  | 我要评论

训练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))

本文地址:https://blog.csdn.net/Pippy03/article/details/107105994

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网