Jelajahi Sumber

modify yolov4 pred

yjh0410 1 tahun lalu
induk
melakukan
954afb7fb5
3 mengubah file dengan 7 tambahan dan 1 penghapusan
  1. 1 1
      engine.py
  2. 4 0
      models/yolov3/yolov3_fpn.py
  3. 2 0
      models/yolov4/yolov4_pafpn.py

+ 1 - 1
engine.py

@@ -214,8 +214,8 @@ class YoloTrainer(object):
                 # Compute loss
                 loss_dict = self.criterion(outputs=outputs, targets=targets)
                 losses = loss_dict['losses']
-                losses /= self.cfg.grad_accumulate
                 loss_dict_reduced = distributed_utils.reduce_dict(loss_dict)
+                losses /= self.cfg.grad_accumulate
 
             # Backward
             self.scaler.scale(losses).backward()

+ 4 - 0
models/yolov3/yolov3_fpn.py

@@ -19,6 +19,7 @@ class Yolov3FPN(nn.Module):
         self.top_down_layer_1 = ResBlock(in_dim     = c5,
                                          out_dim    = round(512*cfg.width),
                                          num_blocks = round(3*cfg.depth),
+                                         expansion  = 0.5,
                                          shortcut   = False,
                                          act_type   = cfg.fpn_act,
                                          norm_type  = cfg.fpn_norm,
@@ -29,6 +30,7 @@ class Yolov3FPN(nn.Module):
         self.top_down_layer_2 = ResBlock(in_dim     = c4 + round(256*cfg.width),
                                          out_dim    = round(256*cfg.width),
                                          num_blocks = round(3*cfg.depth),
+                                         expansion  = 0.5,
                                          shortcut   = False,
                                          act_type   = cfg.fpn_act,
                                          norm_type  = cfg.fpn_norm,
@@ -39,6 +41,7 @@ class Yolov3FPN(nn.Module):
         self.top_down_layer_3 = ResBlock(in_dim     = c3 + round(128*cfg.width),
                                          out_dim    = round(128*cfg.width),
                                          num_blocks = round(3*cfg.depth),
+                                         expansion  = 0.5,
                                          shortcut   = False,
                                          act_type   = cfg.fpn_act,
                                          norm_type  = cfg.fpn_norm,
@@ -72,4 +75,5 @@ class Yolov3FPN(nn.Module):
         out_feats_proj = []
         for feat, layer in zip(out_feats, self.out_layers):
             out_feats_proj.append(layer(feat))
+
         return out_feats_proj

+ 2 - 0
models/yolov4/yolov4_pafpn.py

@@ -45,6 +45,7 @@ class Yolov4PaFPN(nn.Module):
         self.bottom_up_layer_1  = CSPBlock(in_dim     = round(256*cfg.width) + round(256*cfg.width),
                                            out_dim    = round(512*cfg.width),
                                            num_blocks = round(3*cfg.depth),
+                                           expansion  = 0.5,
                                            shortcut   = False,
                                            act_type   = cfg.fpn_act,
                                            norm_type  = cfg.fpn_norm,
@@ -56,6 +57,7 @@ class Yolov4PaFPN(nn.Module):
         self.bottom_up_layer_2  = CSPBlock(in_dim     = round(512*cfg.width) + round(512*cfg.width),
                                            out_dim    = round(1024*cfg.width),
                                            num_blocks = round(3*cfg.depth),
+                                           expansion  = 0.5,
                                            shortcut   = False,
                                            act_type   = cfg.fpn_act,
                                            norm_type  = cfg.fpn_norm,