1.找到yolov7的utils中的activation.py,在最后面输入以下代码
# 原理:对局部卷积后的输出与原始数据进行一个max的比对
class FReLU(nn.Module):
def __init__(self, c1, k=3): # ch_in, kernel
super().__init__()
# 可分离卷积,不改变hw与channels
self.conv = nn.Conv2d(c1, c1, k, 1, 1, groups=c1, bias=False)
self.bn = nn.BatchNorm2d(c1)
def forward(self, x):
# 卷积处理后的特征图与原来的x是相同的shape的
return torch.max(x, self.bn(self.conv(x)))
2.在modules中的common.py中将Conv模块改为以下代码
class Conv(nn.Module):
# Standard convolution
def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups
super(Conv, self).__init__()
self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p), groups=g, bias=False)
self.bn = nn.BatchNorm2d(c2)
self.act = FReLU(c2) if act is True else (act if isinstance(act, nn.Module) else nn.Identity())
def forward(self, x):
return self.act(self.bn(self.conv(x)))
def fuseforward(self, x):
return self.act(self.conv(x))
3.把原来的Conv模块注释掉
4.再train就可以了
标签:YOLOv7,__,conv,nn,self,添加,act,FReLU,c1 From: https://blog.51cto.com/u_16055951/7394642