论文题目:Slim-neck by GSConv: A better design paradigm of detector architectures for autonomous vehicles
论文:https://arxiv.org/abs/2206.02424
代码:https://github.com/AlanLi1997/Slim-neck-by-GSConv
目标:为YOLOv5模型构建一个简单高效的Neck模块。考虑了卷积方法、特征融合结构、计算效率、计算成本效益等诸多因素。

class GSConv(nn.Module):
# GSConv https://github.com/AlanLi1997/slim-neck-by-gsconv
def __init__(self, c1, c2, k=1, s=1, g=1, act=True):
super().__init__()
c_ = c2 // 2
self.cv1 = Conv(c1, c_, k, s, None, g, act)
self.cv2 = Conv(c_, c_, 5, 1, None, c_, act)
def forward(self, x):
x1 = self.cv1(x)
x2 = torch.cat((x1, self.cv2(x1)), 1)
# shuffle
b, n, h, w = x2.data.size()
b_n = b * n // 2
y = x2.reshape(b_n, 2, h * w)
y = y.permute(1, 0, 2)
y = y.reshape(2, -1, n // 2, h, w)
return torch.cat((y[0], y[1]), 1)
将YOLOv5s.yaml的Neck模块中的Conv换成GSConv
1、将GSConv代码加入common.py文件中
2、找到yolo.py文件里的parse_model函数,将类名加入进去

3、修改配置文件,将YOLOv5s.yaml的Neck模块中的Conv换成GSConv

~~~此处有一个疑问,官方给出的GSConv代码中为什么没用DWConv呢?希望知道的朋友在评论区指点一下~~~

class GSBottleneck(nn.Module):
# GS Bottleneck https://github.com/AlanLi1997/slim-neck-by-gsconv
def __init__(self, c1, c2, k=3, s=1):
super().__init__()
c_ = c2 // 2
# for lighting
self.conv_lighting = nn.Sequential(
GSConv(c1, c_, 1, 1),
GSConv(c_, c2, 1, 1, act=False))
# for receptive field
self.conv = nn.Sequential(
GSConv(c1, c_, 3, 1),
GSConv(c_, c2, 3, 1, act=False))
self.shortcut = Conv(c1, c2, 3, 1, act=False)
def forward(self, x):
return self.conv_lighting(x) + self.shortcut(x)

class VoVGSCSP(nn.Module):
# VoV-GSCSP https://github.com/AlanLi1997/slim-neck-by-gsconv
def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5):
super().__init__()
c_ = int(c2 * e)
self.cv1 = Conv(c1, c_, 1, 1)
self.cv2 = Conv(2 * c_, c2, 1)
self.m = nn.Sequential(*(GSBottleneck(c_, c_) for _ in range(n)))
def forward(self, x):
x1 = self.cv1(x)
return self.cv2(torch.cat((self.m(x1), x1), dim=1))
将YOLOv5s.yaml的Neck模块中的Conv换成GSConv,C3模块换为VoVGSCSP模块
1、将以下代码加入common.py文件中
class GSConv(nn.Module):
# GSConv https://github.com/AlanLi1997/slim-neck-by-gsconv
def __init__(self, c1, c2, k=1, s=1, g=1, act=True):
super().__init__()
c_ = c2 // 2
self.cv1 = Conv(c1, c_, k, s, None, g, act)
self.cv2 = Conv(c_, c_, 5, 1, None, c_, act)
def forward(self, x):
x1 = self.cv1(x)
x2 = torch.cat((x1, self.cv2(x1)), 1)
# shuffle
b, n, h, w = x2.data.size()
b_n = b * n // 2
y = x2.reshape(b_n, 2, h * w)
y = y.permute(1, 0, 2)
y = y.reshape(2, -1, n // 2, h, w)
return torch.cat((y[0], y[1]), 1)
class GSBottleneck(nn.Module):
# GS Bottleneck https://github.com/AlanLi1997/slim-neck-by-gsconv
def __init__(self, c1, c2, k=3, s=1):
super().__init__()
c_ = c2 // 2
# for lighting
self.conv_lighting = nn.Sequential(
GSConv(c1, c_, 1, 1),
GSConv(c_, c2, 1, 1, act=False))
# for receptive field
self.conv = nn.Sequential(
GSConv(c1, c_, 3, 1),
GSConv(c_, c2, 3, 1, act=False))
self.shortcut = nn.Identity()
def forward(self, x):
return self.conv_lighting(x)
class VoVGSCSP(nn.Module):
# VoV-GSCSP https://github.com/AlanLi1997/slim-neck-by-gsconv
def __init__(self, c1, c2, n=1, shortcut=True, g=1, e=0.5):
super().__init__()
c_ = int(c2 * e)
self.cv1 = Conv(c1, c_, 1, 1)
self.cv2 = Conv(2 * c_, c2, 1)
self.m = nn.Sequential(*(GSBottleneck(c_, c_) for _ in range(n)))
def forward(self, x):
x1 = self.cv1(x)
return self.cv2(torch.cat((self.m(x1), x1), dim=1))
2、找到yolo.py文件里的parse_model函数,将类名加入进去,注意有两处需要添加的地方

3、修改配置文件,将YOLOv5s.yaml的Neck模块中的Conv换成GSConv ,C3模块换为VoVGSCSP

下图是原论文中给出的结构图,个人对照源码后觉得这里多画了一个GSConv模块(红色框里所示),如果有知道的大佬望在评论区指点一下。

希望我没有误解“ducktyping”的含义,但从我读到的内容来看,这意味着我应该根据对象如何响应方法而不是它是什么类型/类来编写代码。代码如下:defconvert_hash(hash)ifhash.keys.all?{|k|k.is_a?(Integer)}returnhashelsifhash.keys.all?{|k|k.is_a?(Property)}new_hash={}hash.each_pair{|k,v|new_hash[k.id]=v}returnnew_hashelseraise"CustomattributekeysshouldbeID'sorPropertyo
关于yolov5训练时参数workers和batch-size的理解yolov5训练命令workers和batch-size参数的理解两个参数的调优总结yolov5训练命令python.\train.py--datamy.yaml--workers8--batch-size32--epochs100yolov5的训练很简单,下载好仓库,装好依赖后,只需自定义一下data目录中的yaml文件就可以了。这里我使用自定义的my.yaml文件,里面就是定义数据集位置和训练种类数和名字。workers和batch-size参数的理解一般训练主要需要调整的参数是这两个:workers指数据装载时cpu所使
我正在用Ruby编写DSL来控制我正在处理的Arduino项目;巴尔迪诺。这是一只酒吧猴子,将由软件控制来提供饮料。Arduino通过串行端口接收命令,告诉Arduino要打开什么泵以及打开多长时间。它目前正在读取一个食谱(见下文)并将其打印出来。串行通信的代码以及我在下面提到的其他一些想法仍然需要改进。这是我的第一个DSL,我正在处理之前的示例,所以它的边缘非常粗糙。任何批评、代码改进(是否有任何关于RubyDSL最佳实践或习语的良好引用?)或任何一般性评论。我目前有DSL的粗略草稿,因此饮料配方如下所示(Githublink):desc"Simpleglassofwater"rec
我正在尝试使用ruby改进来应用Rails钩子(Hook)。我想避免猴子补丁。当猴子修补时它会这样工作ActiveRecord::Base.class_evaldoafter_finddo#dosomethingwithmy_methodenddefmy_method#somethingusefulendend我已经能够通过做这样的事情来拥有类方法:moduleActiveRecordRefinementsrefineActiveRecord::Base.singleton_classdodefmy_method#somethingcoolendendend但我无法运行钩子(Hoo
您可以使用优化您的类(class)moduleRefinedStringrefineStringdodefto_boolean(text)!!(text=~/^(true|t|yes|y|1)$/i)endendend但是如何细化模块方法呢?这:moduleRefinedMathrefineMathdodefPI22/7endendend引发:TypeError:错误的参数类型模块(预期类) 最佳答案 这段代码可以工作:moduleMathdefself.piputs'originalmethod'endendmoduleRefin
我正在使用Rails3.2.2,我想用'引用所有数组元素并返回一个包含所有这些引用和逗号分隔元素的字符串。这时候我在用['a','b','c'].collect{|x|"'#{x}'"}.join(",")#=>"'a','b','c'"但我认为我可以改进上面的代码(也许通过使用一个我不知道的Ruby方法,如果它存在的话)。可能吗? 最佳答案 我用"'#{%w{abc}.join("','")}'"这里是扩展版:'#Startingquote%w{abc}.join("','")#Joinarraywith','delimitert
您希望Ruby(以及更广泛的Ruby社区)改进哪些方面?我读了somewhereRuby是Smalltalk和LISP的私生子,Perl小姐是保姆。我非常尊重Ruby的parent,但我不确定我是否喜欢Perl小姐对child的影响。具体来说,我不喜欢预定义的变量:我需要一个cheatsheet知道他们的意思。你可以说“只是不要使用它们”。好吧,我不...但其他人这样做。当我在网上下载一个插件时,如果我需要去接触源代码,我别无选择,只能获取我的备忘单。我只希望他们能从语言本身中删除这些内容。此外,我认为Ruby是一个移动的目标。我的代码在每次新的Ruby升级时都会出错,即使是次要版本。
我试图了解Ruby的优化功能,但遇到了一个我不了解的场景。以这个示例代码为例:classTravellerdefwhat_are_youputs"I'maBackpacker"enddefself.preferred_accommodationputs"Hostels"endendmoduleRefinementsmoduleMoneydefwhat_are_youputs"I'macashed-uphedonist!"endmoduleClassMethodsdefpreferred_accommodationputs"ExpensiveHotels"endenddefself.in
我正在努力学习RubyKoans以尝试学习Ruby,到目前为止一切顺利。我已经得到了贪婪的公案,在撰写本文时它是183。我有一个可行的解决方案,但我觉得我只是拼凑了一堆if/then逻辑,但我不是拥抱Ruby模式。在下面的代码中,有什么方法可以让我更全面地接受Ruby模式吗?(我的代码包含在“我的代码[BEGINS|ENDS]HERE”注释中。#Greedisadicegamewhereyourolluptofivedicetoaccumulate#points.Thefollowing"score"functionwillbeusedcalculatethe#scoreofasing
Module#refine方法接受一个类和一个block并返回一个细化模块,所以我想我可以定义:classClassdefinclude_refined(klass)_refinement=Module.newdoincluderefine(klass){yieldifblock_given?}endself.send:include,_refinementendend下面的测试通过了classBasedeffoo"foo"endendclassReceiverinclude_refined(Base){deffoo"refined"+superend}enddescribeRecei