From 6ffbd8ba15a4c351bb836d5bcbc72a32d9df6e1b Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Thu, 5 Aug 2021 11:06:52 +0900 Subject: [PATCH 1/3] more simpler code for DWConvClass more simpler code for DWConvClass --- models/common.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/models/common.py b/models/common.py index 30e7319f98a0..7cc779cbc886 100644 --- a/models/common.py +++ b/models/common.py @@ -52,8 +52,7 @@ def forward_fuse(self, x): class DWConvClass(Conv): # Depth-wise convolution class def __init__(self, c1, c2, k=1, s=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups - super().__init__(c1, c2, k, s, act) - self.conv = nn.Conv2d(c1, c2, k, s, autopad(k), groups=math.gcd(c1, c2), bias=False) + super().__init__(c1, c2, k, s, g=math.gcd(c1, c2), act=act) class TransformerLayer(nn.Module): From b5817b7effd8af45aa9453a9fa8ce34d096db43b Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Thu, 5 Aug 2021 11:22:02 +0900 Subject: [PATCH 2/3] remove DWConv function --- models/common.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/models/common.py b/models/common.py index 7cc779cbc886..2d24672a6b44 100644 --- a/models/common.py +++ b/models/common.py @@ -29,11 +29,6 @@ def autopad(k, p=None): # kernel, padding return p -def DWConv(c1, c2, k=1, s=1, act=True): - # Depth-wise convolution function - return Conv(c1, c2, k, s, g=math.gcd(c1, c2), act=act) - - 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 @@ -49,7 +44,7 @@ def forward_fuse(self, x): return self.act(self.conv(x)) -class DWConvClass(Conv): +class DWConv(Conv): # Depth-wise convolution class def __init__(self, c1, c2, k=1, s=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups super().__init__(c1, c2, k, s, g=math.gcd(c1, c2), act=act) From 9a4fe2e067dfa577a9e42618f2b9f2c084d962c8 Mon Sep 17 00:00:00 2001 From: Yonghye Kwon Date: Thu, 5 Aug 2021 11:23:25 +0900 Subject: [PATCH 3/3] Replace DWConvClass with DWConv --- models/yolo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/yolo.py b/models/yolo.py index 9f05c8329f38..380f3401e5b9 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -202,7 +202,7 @@ def _print_biases(self): def fuse(self): # fuse model Conv2d() + BatchNorm2d() layers LOGGER.info('Fusing layers... ') for m in self.model.modules(): - if isinstance(m, (Conv, DWConvClass)) and hasattr(m, 'bn'): + if isinstance(m, (Conv, DWConv)) and hasattr(m, 'bn'): m.conv = fuse_conv_and_bn(m.conv, m.bn) # update conv delattr(m, 'bn') # remove batchnorm m.forward = m.forward_fuse # update forward