ouyanghaodong / DEYO

Implementation of paper - DEYO: DETR with YOLO for End-to-End Object Detection
GNU Affero General Public License v3.0
72 stars 5 forks source link

如何调整不同DEYO的模型尺寸? #8

Open LittleRain626 opened 7 months ago

LittleRain626 commented 7 months ago

您好,很感谢您的优秀工作,我在使用您的代码的时候遇到了一些问题,希望能得到您的解答。

希望能尽快得到您的回复,非常感谢!

ouyanghaodong commented 7 months ago

我们将您的问题分为以下几点逐一回答:

  1. readme里面四舍五入了,没有写精确参数,我们提供的代码默认是DEYO-tiny模型。
  2. 加载不同权重确实不会报错,但是权重实际上没有被加载到DEYO上。
  3. 您需要保证DEYO的的尺度与YOLOv8的尺度一致才能被正确加载。您可以通过在yolov8-rtdetr.yaml中简单的注释来选择不用尺寸,下面是选择尺度M的例子:
    # Parameters
    nc: 80  # number of classes
    scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'
    # [depth, width, max_channels]
    # n: [0.33, 0.25, 1024]  # YOLOv8n summary: 225 layers,  3157200 parameters,  3157184 gradients,   8.9 GFLOPs
    # s: [0.33, 0.50, 1024]  # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients,  28.8 GFLOPs
    m: [0.67, 0.75, 768]   # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients,  79.3 GFLOPs
    # l: [1.00, 1.00, 512]   # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs
    # x: [1.00, 1.25, 512]   # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs
  4. 关闭CDN您可以简单修改 ultralytics/nn/modules/head.py 中的 RTDETRDecoder。首先您需要在forward中找到 Prepare denoising training, 然后按照下面的方式修改:
    
    dn_embed, dn_bbox, attn_mask, dn_meta = get_cdn_group(
                        batch,
                        self.nc,
                        self.num_queries,
                        self.denoising_class_embed.weight,
                        self.num_denoising,
                        self.label_noise_ratio,
                        self.box_noise_scale,
                        False,
                )
ouyanghaodong commented 7 months ago

此外,对于尺度调整,您还需要根据我们readme中提供的参数配置RTDETRDecoder:


# Open ultralytics/nn/modules/head.py 
# Find RTDETRDecoder
# DEYO-tiny nq=100 hd=64  o2m: yolov8n
# DEYO-N    nq=300 hd=128 o2m: yolov8n
# DEYO-S    nq=300 hd=128 o2m: yolov8s
# DEYO-M    nq=300 hd=256 o2m: yolov8m
# DEYO-L    nq=300 hd=256 o2m: yolov8l
# DEYO-X    nq=300 hd=320 o2m: yolov8x
def __init__(
   self,
   nc=80,
   ch=(512, 1024, 2048),
   hd=64,  # hidden dim
   nq=100,  # num queries
   ndp=4,  # num decoder points
   nh=8,  # num head
   ndl=6,  # num decoder layers
   d_ffn=1024,  # dim of feedforward
   dropout=0.0,
   act=nn.ReLU(),
   eval_idx=-1,
   # Training args
   nd=100,  # num denoising
   label_noise_ratio=0.5,
   box_noise_scale=1.0,
   learnt_init_query=False,
):
LittleRain626 commented 7 months ago

我们将您的问题分为以下几点逐一回答:

  1. readme里面四舍五入了,没有写精确参数,我们提供的代码默认是DEYO-tiny模型。
  2. 加载不同权重确实不会报错,但是权重实际上没有被加载到DEYO上。
  3. 您需要保证DEYO的的尺度与YOLOv8的尺度一致才能被正确加载。您可以通过在yolov8-rtdetr.yaml中简单的注释来选择不用尺寸,下面是选择尺度M的例子:
# Parameters
nc: 80  # number of classes
scales: # model compound scaling constants, i.e. 'model=yolov8n.yaml' will call yolov8.yaml with scale 'n'
  # [depth, width, max_channels]
  # n: [0.33, 0.25, 1024]  # YOLOv8n summary: 225 layers,  3157200 parameters,  3157184 gradients,   8.9 GFLOPs
  # s: [0.33, 0.50, 1024]  # YOLOv8s summary: 225 layers, 11166560 parameters, 11166544 gradients,  28.8 GFLOPs
  m: [0.67, 0.75, 768]   # YOLOv8m summary: 295 layers, 25902640 parameters, 25902624 gradients,  79.3 GFLOPs
  # l: [1.00, 1.00, 512]   # YOLOv8l summary: 365 layers, 43691520 parameters, 43691504 gradients, 165.7 GFLOPs
  # x: [1.00, 1.25, 512]   # YOLOv8x summary: 365 layers, 68229648 parameters, 68229632 gradients, 258.5 GFLOPs
  1. 关闭CDN您可以简单修改 ultralytics/nn/modules/head.py 中的 RTDETRDecoder。首先您需要在forward中找到 Prepare denoising training, 然后按照下面的方式修改:
dn_embed, dn_bbox, attn_mask, dn_meta = get_cdn_group(
                      batch,
                      self.nc,
                      self.num_queries,
                      self.denoising_class_embed.weight,
                      self.num_denoising,
                      self.label_noise_ratio,
                      self.box_noise_scale,
                      False,
              )

非常感谢您的回复!