• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

YOLOv5+Swin Transformer

武飞扬头像
阿燃定律
帮助1

本科生工科生cv改代码

本来做的7,但是7报错一直解决不了,我就试试5

1、先是第一个报错

TypeError: __init__() missing 1 required positional argument: 'c2'

解决:在yolo.py里

  1.  
    if m in {
  2.  
    Conv, GhostConv, Bottleneck, GhostBottleneck, SPP, SPPF, DWConv, MixConv2d, Focus, CrossConv,
  3.  
    BottleneckCSP, C3, C3TR, C3SPP, C3Ghost, nn.ConvTranspose2d, DWConvTranspose2d, C3x, C3STR}:
  4.  
    # add a C3STR at the end of the sentence(aran)
  5.  
    c1, c2 = ch[f], args[0]
  6.  
    if c2 != no: # if not output
  7.  
    c2 = make_divisible(c2 * gw, 8) # change 8 to 9
  8.  
     
  9.  
    args = [c1, c2, *args[1:]]
  10.  
    if m in {BottleneckCSP, C3, C3TR, C3Ghost, C3x, C3STR}:# add a C3STR at the end of the sentence(aran)
  11.  
    args.insert(2, n) # number of repeats

2、

  1.  
    File "/root/yolov5_master/models/common.py", line 1315, in __init__
  2.  
    super().__init__(c1, c2, c2, n, shortcut, g, e)
  3.  
    TypeError: __init__() takes from 3 to 7 positional arguments but 8 were given

解决:common里删掉一个c2

  1.  
    class C3STR(C3):
  2.  
    # C3 module with SwinTransformerBlock()
  3.  
    def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5):
  4.  
    super().__init__(c1, c2, n, shortcut, g, e) # a c2 was deleted by aran
  5.  
    c_ = int(c2 * e)
  6.  
    num_heads = c_ // 32
  7.  
    self.m = SwinTransformerBlock(c_, c_, num_heads, n)

3、

NameError: name 'window_partition' is not defined

解决:应该加上window_partition 和 window_reverse, 加在common,具体位置是在芒果哥加在common的代码前面

  1.  
    def window_partition(x, window_size):
  2.  
    B, H, W, C = x.shape
  3.  
    x = x.view(B, H // window_size, window_size, W // window_size, window_size, C)
  4.  
    windows = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(-1, window_size, window_size, C)
  5.  
    return windows
  6.  
     
  7.  
     
  8.  
    def window_reverse(windows, window_size, H, W):
  9.  
    B = int(windows.shape[0] / (H * W / window_size / window_size))
  10.  
    x = windows.view(B, H // window_size, W // window_size, window_size, window_size, -1)
  11.  
    x = x.permute(0, 1, 3, 2, 4, 5).contiguous().view(B, H, W, -1)
  12.  
    return x

4、

NameError: name 'F' is not defined

解决:在common里面

import torch.nn.functional as F

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgfkgcc
系列文章
更多 icon
同类精品
更多 icon
继续加载