yjh0410 il y a 1 an
Parent
commit
0be5b85fb7

+ 6 - 2
models/yolov3/yolov3_fpn.py

@@ -27,7 +27,9 @@ class Yolov3FPN(nn.Module):
                                          act_type   = cfg.fpn_act,
                                          norm_type  = cfg.fpn_norm,
                                          depthwise  = cfg.fpn_depthwise)
-        self.reduce_layer_1   = BasicConv(round(512*cfg.width), round(256*cfg.width), kernel_size=1, act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
+        self.reduce_layer_1   = BasicConv(round(512*cfg.width), round(256*cfg.width),
+                                          kernel_size=1, padding=0, stride=1,
+                                          act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
 
         ## P4 -> P3
         self.top_down_layer_2 = ResBlock(in_dim     = c4 + round(256*cfg.width),
@@ -38,7 +40,9 @@ class Yolov3FPN(nn.Module):
                                          act_type   = cfg.fpn_act,
                                          norm_type  = cfg.fpn_norm,
                                          depthwise  = cfg.fpn_depthwise)
-        self.reduce_layer_2   = BasicConv(round(256*cfg.width), round(128*cfg.width), kernel_size=1, act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
+        self.reduce_layer_2   = BasicConv(round(256*cfg.width), round(128*cfg.width),
+                                          kernel_size=1, padding=0, stride=1,
+                                          act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
         
         ## P3
         self.top_down_layer_3 = ResBlock(in_dim     = c3 + round(128*cfg.width),

+ 12 - 6
models/yolov5/yolov5_pafpn.py

@@ -15,7 +15,9 @@ class Yolov5PaFPN(nn.Module):
 
         # ---------------------- Yolov5's Top down FPN ----------------------
         ## P5 -> P4
-        self.reduce_layer_1   = BasicConv(c5, round(512*cfg.width), kernel_size=1, act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
+        self.reduce_layer_1   = BasicConv(c5, round(512*cfg.width),
+                                          kernel_size=1, padding=0, stride=1,
+                                          act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
         self.top_down_layer_1 = CSPBlock(in_dim     = c4 + round(512*cfg.width),
                                          out_dim    = round(512*cfg.width),
                                          num_blocks = round(3*cfg.depth),
@@ -26,7 +28,9 @@ class Yolov5PaFPN(nn.Module):
                                          depthwise  = cfg.fpn_depthwise)
 
         ## P4 -> P3
-        self.reduce_layer_2   = BasicConv(round(512*cfg.width), round(256*cfg.width), kernel_size=1, act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
+        self.reduce_layer_2   = BasicConv(round(512*cfg.width), round(256*cfg.width),
+                                          kernel_size=1, padding=0, stride=1,
+                                          act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
         self.top_down_layer_2 = CSPBlock(in_dim     = c3 + round(256*cfg.width),
                                          out_dim    = round(256*cfg.width),
                                          num_blocks = round(3*cfg.depth),
@@ -73,21 +77,23 @@ class Yolov5PaFPN(nn.Module):
     def forward(self, features):
         c3, c4, c5 = features
         
-        # P5 -> P4
+        # ------------------ Top down FPN ------------------
+        ## P5 -> P4
         p5 = self.reduce_layer_1(c5)
         p5_up = F.interpolate(p5, scale_factor=2.0)
         p4 = self.top_down_layer_1(torch.cat([c4, p5_up], dim=1))
 
-        # P4 -> P3
+        ## P4 -> P3
         p4 = self.reduce_layer_2(p4)
         p4_up = F.interpolate(p4, scale_factor=2.0)
         p3 = self.top_down_layer_2(torch.cat([c3, p4_up], dim=1))
 
-        # P3 -> P4
+        # ------------------ Bottom up PAN ------------------
+        ## P3 -> P4
         p3_ds = self.downsample_layer_1(p3)
         p4 = self.bottom_up_layer_1(torch.cat([p4, p3_ds], dim=1))
 
-        # P4 -> P5
+        ## P4 -> P5
         p4_ds = self.downsample_layer_2(p4)
         p5 = self.bottom_up_layer_2(torch.cat([p5, p4_ds], dim=1))
 

+ 4 - 2
models/yolov7/yolov7_pafpn.py

@@ -15,7 +15,7 @@ class Yolov7PaFPN(nn.Module):
         self.out_dims = [round(256*cfg.width), round(512*cfg.width), round(1024*cfg.width)]
         c3, c4, c5 = in_dims
 
-        # ----------------------------- Top-down FPN -----------------------------
+        # ----------------------------- Yolov7's Top-down FPN -----------------------------
         ## P5 -> P4
         self.reduce_layer_1 = BasicConv(c5, round(256*cfg.width),
                                         kernel_size=1, act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
@@ -44,7 +44,7 @@ class Yolov7PaFPN(nn.Module):
                                              norm_type  = cfg.fpn_norm,
                                              depthwise  = cfg.fpn_depthwise,
                                              )
-        # ----------------------------- Bottom-up FPN -----------------------------
+        # ----------------------------- Yolov7's Bottom-up PAN -----------------------------
         ## P3 -> P4
         self.downsample_layer_1 = MDown(round(128*cfg.width), round(256*cfg.width),
                                         act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
@@ -85,6 +85,7 @@ class Yolov7PaFPN(nn.Module):
     def forward(self, features):
         c3, c4, c5 = features
 
+        # ------------------ Top down FPN ------------------
         ## P5 -> P4
         p5 = self.reduce_layer_1(c5)
         p5_up = F.interpolate(p5, scale_factor=2.0)
@@ -97,6 +98,7 @@ class Yolov7PaFPN(nn.Module):
         p3 = self.reduce_layer_4(c3)
         p3 = self.top_down_layer_2(torch.cat([p4_up, p3], dim=1))
 
+        # ------------------ Bottom up PAN ------------------
         ## P3 -> P4
         p3_ds = self.downsample_layer_1(p3)
         p4 = torch.cat([p3_ds, p4], dim=1)

+ 2 - 2
models/yolov8/yolov8_pafpn.py

@@ -19,7 +19,7 @@ class Yolov8PaFPN(nn.Module):
         self.in_dims = in_dims[::-1]
         self.out_dims = [round(256*cfg.width), round(512*cfg.width), round(512*cfg.width*cfg.ratio)]
 
-        # ---------------- Top dwon ----------------
+        # ----------------------------- Yolov8's Top-down FPN -----------------------------
         ## P5 -> P4
         self.top_down_layer_1 = ELANLayer(in_dim     = self.in_dims[0] + self.in_dims[1],
                                           out_dim    = round(512*cfg.width),
@@ -40,7 +40,7 @@ class Yolov8PaFPN(nn.Module):
                                           norm_type  = cfg.fpn_norm,
                                           depthwise  = cfg.fpn_depthwise,
                                           )
-        # ---------------- Bottom up ----------------
+        # ----------------------------- Yolov8's Bottom-up PAN -----------------------------
         ## P3 -> P4
         self.dowmsample_layer_1 = BasicConv(round(256*cfg.width), round(256*cfg.width),
                                             kernel_size=3, padding=1, stride=2,

+ 12 - 6
models/yolox/yolox_pafpn.py

@@ -16,7 +16,9 @@ class YoloxPaFPN(nn.Module):
 
         # ---------------------- Yolox's Top down FPN ----------------------
         ## P5 -> P4
-        self.reduce_layer_1   = BasicConv(c5, round(512*cfg.width), kernel_size=1, act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
+        self.reduce_layer_1   = BasicConv(c5, round(512*cfg.width),
+                                          kernel_size=1, padding=0, stride=1,
+                                          act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
         self.top_down_layer_1 = CSPBlock(in_dim     = c4 + round(512*cfg.width),
                                          out_dim    = round(512*cfg.width),
                                          num_blocks = round(3*cfg.depth),
@@ -27,7 +29,9 @@ class YoloxPaFPN(nn.Module):
                                          depthwise  = cfg.fpn_depthwise)
 
         ## P4 -> P3
-        self.reduce_layer_2   = BasicConv(round(512*cfg.width), round(256*cfg.width), kernel_size=1, act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
+        self.reduce_layer_2   = BasicConv(round(512*cfg.width), round(256*cfg.width),
+                                          kernel_size=1, padding=0, stride=1,
+                                          act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
         self.top_down_layer_2 = CSPBlock(in_dim     = c3 + round(256*cfg.width),
                                          out_dim    = round(256*cfg.width),
                                          num_blocks = round(3*cfg.depth),
@@ -74,21 +78,23 @@ class YoloxPaFPN(nn.Module):
     def forward(self, features):
         c3, c4, c5 = features
         
-        # P5 -> P4
+        # ------------------ Top down FPN ------------------
+        ## P5 -> P4
         p5 = self.reduce_layer_1(c5)
         p5_up = F.interpolate(p5, scale_factor=2.0)
         p4 = self.top_down_layer_1(torch.cat([c4, p5_up], dim=1))
 
-        # P4 -> P3
+        ## P4 -> P3
         p4 = self.reduce_layer_2(p4)
         p4_up = F.interpolate(p4, scale_factor=2.0)
         p3 = self.top_down_layer_2(torch.cat([c3, p4_up], dim=1))
 
-        # P3 -> P4
+        # ------------------ Bottom up PAN ------------------
+        ## P3 -> P4
         p3_ds = self.downsample_layer_1(p3)
         p4 = self.bottom_up_layer_1(torch.cat([p4, p3_ds], dim=1))
 
-        # P4 -> P5
+        ## P4 -> P5
         p4_ds = self.downsample_layer_2(p4)
         p5 = self.bottom_up_layer_2(torch.cat([p5, p4_ds], dim=1))