Browse Source

modify init

yjh0410 1 year ago
parent
commit
87d5a72477

+ 2 - 2
yolo/models/gelan/gelan_basic.py

@@ -64,9 +64,9 @@ class BasicConv(nn.Module):
             return self.act(self.norm(self.conv(x)))
         else:
             # Depthwise conv
-            x = self.norm1(self.conv1(x))
+            x = self.act(self.norm1(self.conv1(x)))
             # Pointwise conv
-            x = self.norm2(self.conv2(x))
+            x = self.act(self.norm2(self.conv2(x)))
             return x
 
 

+ 22 - 0
yolo/models/gelan/gelan_neck.py

@@ -25,6 +25,17 @@ class SPPF(nn.Module):
                               stride=1,
                               padding=cfg.spp_pooling_size // 2)
 
+        # Initialize all layers
+        self.init_weights()
+
+    def init_weights(self):
+        """Initialize the parameters."""
+        for m in self.modules():
+            if isinstance(m, torch.nn.Conv2d):
+                # In order to be consistent with the source code,
+                # reset the Conv2d initialization parameters
+                m.reset_parameters()
+
     def forward(self, x):
         x = self.cv1(x)
         y1 = self.m(x)
@@ -46,6 +57,17 @@ class SPPElan(nn.Module):
         self.conv_layer_2 = BasicConv(self.inter_dim * 4, self.out_dim, kernel_size=1, act_type=cfg.neck_act, norm_type=cfg.neck_norm)
         self.pool_layer   = nn.MaxPool2d(kernel_size=cfg.spp_pooling_size, stride=1, padding=cfg.spp_pooling_size // 2)
 
+        # Initialize all layers
+        self.init_weights()
+
+    def init_weights(self):
+        """Initialize the parameters."""
+        for m in self.modules():
+            if isinstance(m, torch.nn.Conv2d):
+                # In order to be consistent with the source code,
+                # reset the Conv2d initialization parameters
+                m.reset_parameters()
+
     def forward(self, x):
         y = [self.conv_layer_1(x)]
         y.extend(self.pool_layer(y[-1]) for _ in range(3))

+ 2 - 2
yolo/models/yolov1/yolov1_basic.py

@@ -63,9 +63,9 @@ class BasicConv(nn.Module):
             return self.act(self.norm(self.conv(x)))
         else:
             # Depthwise conv
-            x = self.norm1(self.conv1(x))
+            x = self.act(self.norm1(self.conv1(x)))
             # Pointwise conv
-            x = self.norm2(self.conv2(x))
+            x = self.act(self.norm2(self.conv2(x)))
             return x
 
 

+ 11 - 0
yolo/models/yolov1/yolov1_neck.py

@@ -28,6 +28,17 @@ class SPPF(nn.Module):
                               stride=1,
                               padding=cfg.spp_pooling_size // 2)
 
+        # Initialize all layers
+        self.init_weights()
+
+    def init_weights(self):
+        """Initialize the parameters."""
+        for m in self.modules():
+            if isinstance(m, torch.nn.Conv2d):
+                # In order to be consistent with the source code,
+                # reset the Conv2d initialization parameters
+                m.reset_parameters()
+
     def forward(self, x):
         x = self.cv1(x)
         y1 = self.m(x)

+ 2 - 2
yolo/models/yolov2/yolov2_basic.py

@@ -63,9 +63,9 @@ class BasicConv(nn.Module):
             return self.act(self.norm(self.conv(x)))
         else:
             # Depthwise conv
-            x = self.norm1(self.conv1(x))
+            x = self.act(self.norm1(self.conv1(x)))
             # Pointwise conv
-            x = self.norm2(self.conv2(x))
+            x = self.act(self.norm2(self.conv2(x)))
             return x
 
 

+ 11 - 0
yolo/models/yolov2/yolov2_neck.py

@@ -28,6 +28,17 @@ class SPPF(nn.Module):
                               stride=1,
                               padding=cfg.spp_pooling_size // 2)
 
+        # Initialize all layers
+        self.init_weights()
+
+    def init_weights(self):
+        """Initialize the parameters."""
+        for m in self.modules():
+            if isinstance(m, torch.nn.Conv2d):
+                # In order to be consistent with the source code,
+                # reset the Conv2d initialization parameters
+                m.reset_parameters()
+
     def forward(self, x):
         x = self.cv1(x)
         y1 = self.m(x)

+ 2 - 2
yolo/models/yolov7_af/yolov7_af_basic.py

@@ -63,9 +63,9 @@ class BasicConv(nn.Module):
             return self.act(self.norm(self.conv(x)))
         else:
             # Depthwise conv
-            x = self.norm1(self.conv1(x))
+            x = self.act(self.norm1(self.conv1(x)))
             # Pointwise conv
-            x = self.norm2(self.conv2(x))
+            x = self.act(self.norm2(self.conv2(x)))
             return x
 
 

+ 2 - 2
yolo/models/yolov8/yolov8_basic.py

@@ -63,9 +63,9 @@ class BasicConv(nn.Module):
             return self.act(self.norm(self.conv(x)))
         else:
             # Depthwise conv
-            x = self.norm1(self.conv1(x))
+            x = self.act(self.norm1(self.conv1(x)))
             # Pointwise conv
-            x = self.norm2(self.conv2(x))
+            x = self.act(self.norm2(self.conv2(x)))
             return x