yjh0410 1 rok temu
rodzic
commit
2a538df6df
3 zmienionych plików z 23 dodań i 13 usunięć
  1. 9 8
      config/yolov8_config.py
  2. 1 1
      models/yolov1/README.md
  3. 13 4
      models/yolov8/yolov8_pafpn.py

+ 9 - 8
config/yolov8_config.py

@@ -38,6 +38,7 @@ class Yolov8BaseConfig(object):
         self.head_act  = 'silu'
         self.head_norm = 'BN'
         self.head_depthwise = False
+        self.head_dim       = 256
         self.num_cls_head   = 2
         self.num_reg_head   = 2
 
@@ -52,13 +53,13 @@ class Yolov8BaseConfig(object):
 
         # ---------------- Assignment config ----------------
         ## Matcher
-        self.tal_topk_candidates = 10
-        self.tal_alpha = 0.5
+        self.tal_topk_candidates = 13
+        self.tal_alpha = 1.0
         self.tal_beta  = 6.0
         ## Loss weight
-        self.loss_cls = 0.5
-        self.loss_box = 7.5
-        self.loss_dfl = 1.5
+        self.loss_cls = 1.0
+        self.loss_box = 2.5
+        self.loss_dfl = 0.5
 
         # ---------------- ModelEMA config ----------------
         self.use_ema = True
@@ -80,7 +81,7 @@ class Yolov8BaseConfig(object):
         # ---------------- Lr Scheduler config ----------------
         self.warmup_epoch = 3
         self.lr_scheduler = "cosine"
-        self.max_epoch    = 500
+        self.max_epoch    = 300
         self.eval_epoch   = 10
         self.no_aug_epoch = 20
 
@@ -90,8 +91,8 @@ class Yolov8BaseConfig(object):
         self.normalize_coords = False
         self.mosaic_prob = 1.0
         self.mixup_prob  = 0.15
-        self.copy_paste  = 0.0          # approximated by the YOLOX's mixup
-        self.multi_scale = [0.5, 1.25]   # multi scale: [img_size * 0.5, img_size * 1.5]
+        self.copy_paste  = 0.0           # approximated by the YOLOX's mixup
+        self.multi_scale = [0.5, 1.25]   # multi scale: [img_size * 0.5, img_size * 1.25]
         ## Pixel mean & std
         self.pixel_mean = [0., 0., 0.]
         self.pixel_std  = [255., 255., 255.]

+ 1 - 1
models/yolov1/README.md

@@ -12,7 +12,7 @@
 |--------|------------|-------|-------|------------------------|-------------------|-------------------|--------------------|--------|
 | YOLOv1 | ResNet-18  | 1xb16 |  640  |                    |               |   37.8            |   21.3             | [ckpt](https://github.com/yjh0410/RT-ODLab/releases/download/yolo_tutorial_ckpt/yolov1_coco.pth) |
 
-- For training, we train redesigned YOLOv1 with 150 epochs on COCO.
+- For training, we train redesigned YOLOv1 with 150 epochs on COCO. We also gradient accumulate.
 - For data augmentation, we only use the large scale jitter (LSJ), no Mosaic or Mixup augmentation.
 - For optimizer, we use SGD with momentum 0.937, weight decay 0.0005 and base lr 0.01.
 - For learning rate scheduler, we use linear decay scheduler.

+ 13 - 4
models/yolov8/yolov8_pafpn.py

@@ -6,7 +6,7 @@ from typing import List
 from .yolov8_basic import BasicConv, ELANLayer
 
 
-# PaFPN-ELAN
+# Modified YOLOv8's PaFPN
 class Yolov8PaFPN(nn.Module):
     def __init__(self,
                  cfg,
@@ -17,7 +17,7 @@ class Yolov8PaFPN(nn.Module):
         print('FPN: {}'.format("Yolo PaFPN"))
         # --------------------------- Basic Parameters ---------------------------
         self.in_dims = in_dims[::-1]
-        self.out_dims = [round(256*cfg.width), round(512*cfg.width), round(512*cfg.width*cfg.ratio)]
+        self.out_dims = [round(cfg.head_dim * cfg.width)] * 3
 
         # ---------------- Top dwon ----------------
         ## P5 -> P4
@@ -67,7 +67,11 @@ class Yolov8PaFPN(nn.Module):
                                            norm_type  = cfg.fpn_norm,
                                            depthwise  = cfg.fpn_depthwise,
                                            )
-        
+        self.out_layers = nn.ModuleList([
+            BasicConv(feat_dim, self.out_dims[i], kernel_size=1, act_type=cfg.fpn_act, norm_type=cfg.fpn_norm)
+            for i, feat_dim in enumerate([round(256*cfg.width), round(512*cfg.width), round(512*cfg.width*cfg.ratio)])
+            ])
+
         self.init_weights()
         
     def init_weights(self):
@@ -101,4 +105,9 @@ class Yolov8PaFPN(nn.Module):
 
         out_feats = [p3, p4, p5] # [P3, P4, P5]
         
-        return out_feats
+        # output proj layers
+        out_feats_proj = []
+        for feat, layer in zip(out_feats, self.out_layers):
+            out_feats_proj.append(layer(feat))
+        
+        return out_feats_proj