From 8ea945cc8e3ecbd466dde73f89ae018b3d7079f1 Mon Sep 17 00:00:00 2001 From: Laughing <61612323+Laughing-q@users.noreply.github.com> Date: Tue, 18 Jun 2024 00:53:19 +0800 Subject: [PATCH] `ultralytics 8.2.35` add YOLOv9t/s/m models (#13504) Co-authored-by: UltralyticsAssistant Co-authored-by: Glenn Jocher --- docs/en/models/yolov9.md | 14 +++++----- docs/en/reference/nn/modules/block.md | 8 ++++++ tests/test_cuda.py | 1 + ultralytics/__init__.py | 2 +- ultralytics/cfg/models/v9/yolov9m.yaml | 38 ++++++++++++++++++++++++++ ultralytics/cfg/models/v9/yolov9s.yaml | 38 ++++++++++++++++++++++++++ ultralytics/cfg/models/v9/yolov9t.yaml | 38 ++++++++++++++++++++++++++ ultralytics/nn/modules/__init__.py | 4 +++ ultralytics/nn/modules/block.py | 29 ++++++++++++++++++++ ultralytics/nn/tasks.py | 4 +++ 10 files changed, 168 insertions(+), 8 deletions(-) create mode 100644 ultralytics/cfg/models/v9/yolov9m.yaml create mode 100644 ultralytics/cfg/models/v9/yolov9s.yaml create mode 100644 ultralytics/cfg/models/v9/yolov9t.yaml diff --git a/docs/en/models/yolov9.md b/docs/en/models/yolov9.md index 14c44929..09d116b1 100644 --- a/docs/en/models/yolov9.md +++ b/docs/en/models/yolov9.md @@ -79,9 +79,9 @@ The performance of YOLOv9 on the [COCO dataset](../datasets/detect/coco.md) exem | Model | size
(pixels) | mAPval
50-95 | mAPval
50 | params
(M) | FLOPs
(B) | |---------------------------------------------------------------------------------------|-----------------------|----------------------|-------------------|--------------------|-------------------| - | YOLOv9t | 640 | 38.3 | 53.1 | 2.0 | 7.7 | - | YOLOv9s | 640 | 46.8 | 63.4 | 7.2 | 26.7 | - | YOLOv9m | 640 | 51.4 | 68.1 | 20.1 | 76.8 | + | [YOLOv9t](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov9t.pt) | 640 | 38.3 | 53.1 | 2.0 | 7.7 | + | [YOLOv9s](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov9s.pt) | 640 | 46.8 | 63.4 | 7.2 | 26.7 | + | [YOLOv9m](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov9m.pt) | 640 | 51.4 | 68.1 | 20.1 | 76.8 | | [YOLOv9c](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov9c.pt) | 640 | 53.0 | 70.2 | 25.5 | 102.8 | | [YOLOv9e](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov9e.pt) | 640 | 55.6 | 72.8 | 58.1 | 192.5 | @@ -152,10 +152,10 @@ This example provides simple YOLOv9 training and inference examples. For full do The YOLOv9 series offers a range of models, each optimized for high-performance [Object Detection](../tasks/detect.md). These models cater to varying computational needs and accuracy requirements, making them versatile for a wide array of applications. -| Model | Filenames | Tasks | Inference | Validation | Training | Export | -| ---------- | --------------------------------- | -------------------------------------------- | --------- | ---------- | -------- | ------ | -| YOLOv9 | `yolov9c.pt` `yolov9e.pt` | [Object Detection](../tasks/detect.md) | ✅ | ✅ | ✅ | ✅ | -| YOLOv9-seg | `yolov9c-seg.pt` `yolov9e-seg.pt` | [Instance Segmentation](../tasks/segment.md) | ✅ | ✅ | ✅ | ✅ | +| Model | Filenames | Tasks | Inference | Validation | Training | Export | +|------------|---------------------------------------------------------|----------------------------------------------|-----------|------------|----------|--------| +| YOLOv9 | `yolov9t` `yolov9s` `yolov9m` `yolov9c.pt` `yolov9e.pt` | [Object Detection](../tasks/detect.md) | ✅ | ✅ | ✅ | ✅ | +| YOLOv9-seg | `yolov9c-seg.pt` `yolov9e-seg.pt` | [Instance Segmentation](../tasks/segment.md) | ✅ | ✅ | ✅ | ✅ | This table provides a detailed overview of the YOLOv9 model variants, highlighting their capabilities in object detection tasks and their compatibility with various operational modes such as [Inference](../modes/predict.md), [Validation](../modes/val.md), [Training](../modes/train.md), and [Export](../modes/export.md). This comprehensive support ensures that users can fully leverage the capabilities of YOLOv9 models in a broad range of object detection scenarios. diff --git a/docs/en/reference/nn/modules/block.md b/docs/en/reference/nn/modules/block.md index 5679a4cc..7d6061ab 100644 --- a/docs/en/reference/nn/modules/block.md +++ b/docs/en/reference/nn/modules/block.md @@ -119,6 +119,14 @@ keywords: Ultralytics, YOLO, neural networks, block modules, DFL, Proto, HGStem,

+## ::: ultralytics.nn.modules.block.ELAN1 + +

+ +## ::: ultralytics.nn.modules.block.AConv + +

+ ## ::: ultralytics.nn.modules.block.ADown

diff --git a/tests/test_cuda.py b/tests/test_cuda.py index eb5435c0..64330d76 100644 --- a/tests/test_cuda.py +++ b/tests/test_cuda.py @@ -19,6 +19,7 @@ def test_checks(): @pytest.mark.slow +@pytest.mark.skipif(True, reason="CUDA export tests disabled pending additional Ultralytics GPU server availability") @pytest.mark.skipif(not CUDA_IS_AVAILABLE, reason="CUDA is not available") @pytest.mark.parametrize( "task, dynamic, int8, half, batch", diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index c851108c..935d97f9 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, AGPL-3.0 license -__version__ = "8.2.34" +__version__ = "8.2.35" import os diff --git a/ultralytics/cfg/models/v9/yolov9m.yaml b/ultralytics/cfg/models/v9/yolov9m.yaml new file mode 100644 index 00000000..bdd74886 --- /dev/null +++ b/ultralytics/cfg/models/v9/yolov9m.yaml @@ -0,0 +1,38 @@ +# Ultralytics YOLO 🚀, AGPL-3.0 license +# YOLOv9t +# 603 layers, 20216160 parameters, 77.9 GFLOPs + +# parameters +nc: 80 # number of classes + +# gelan backbone +backbone: + - [-1, 1, Conv, [32, 3, 2]] # 0-P1/2 + - [-1, 1, Conv, [64, 3, 2]] # 1-P2/4 + - [-1, 1, RepNCSPELAN4, [128, 128, 64, 1]] # 2 + - [-1, 1, AConv, [240]] # 3-P3/8 + - [-1, 1, RepNCSPELAN4, [240, 240, 120, 1]] # 4 + - [-1, 1, AConv, [360]] # 5-P4/16 + - [-1, 1, RepNCSPELAN4, [360, 360, 180, 1]] # 6 + - [-1, 1, AConv, [480]] # 7-P5/32 + - [-1, 1, RepNCSPELAN4, [480, 480, 240, 1]] # 8 + - [-1, 1, SPPELAN, [480, 240]] # 9 + +head: + - [-1, 1, nn.Upsample, [None, 2, "nearest"]] + - [[-1, 6], 1, Concat, [1]] # cat backbone P4 + - [-1, 1, RepNCSPELAN4, [360, 360, 180, 1]] # 12 + + - [-1, 1, nn.Upsample, [None, 2, "nearest"]] + - [[-1, 4], 1, Concat, [1]] # cat backbone P3 + - [-1, 1, RepNCSPELAN4, [240, 240, 120, 1]] # 15 + + - [-1, 1, AConv, [180]] + - [[-1, 12], 1, Concat, [1]] # cat head P4 + - [-1, 1, RepNCSPELAN4, [360, 360, 180, 1]] # 18 (P4/16-medium) + + - [-1, 1, AConv, [240]] + - [[-1, 9], 1, Concat, [1]] # cat head P5 + - [-1, 1, RepNCSPELAN4, [480, 480, 240, 1]] # 21 (P5/32-large) + + - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) diff --git a/ultralytics/cfg/models/v9/yolov9s.yaml b/ultralytics/cfg/models/v9/yolov9s.yaml new file mode 100644 index 00000000..4f2f4f32 --- /dev/null +++ b/ultralytics/cfg/models/v9/yolov9s.yaml @@ -0,0 +1,38 @@ +# Ultralytics YOLO 🚀, AGPL-3.0 license +# YOLOv9s +# 917 layers, 7318368 parameters, 27.6 GFLOPs + +# parameters +nc: 80 # number of classes + +# gelan backbone +backbone: + - [-1, 1, Conv, [32, 3, 2]] # 0-P1/2 + - [-1, 1, Conv, [64, 3, 2]] # 1-P2/4 + - [-1, 1, ELAN1, [64, 64, 32]] # 2 + - [-1, 1, AConv, [128]] # 3-P3/8 + - [-1, 1, RepNCSPELAN4, [128, 128, 64, 3]] # 4 + - [-1, 1, AConv, [192]] # 5-P4/16 + - [-1, 1, RepNCSPELAN4, [192, 192, 96, 3]] # 6 + - [-1, 1, AConv, [256]] # 7-P5/32 + - [-1, 1, RepNCSPELAN4, [256, 256, 128, 3]] # 8 + - [-1, 1, SPPELAN, [256, 128]] # 9 + +head: + - [-1, 1, nn.Upsample, [None, 2, "nearest"]] + - [[-1, 6], 1, Concat, [1]] # cat backbone P4 + - [-1, 1, RepNCSPELAN4, [192, 192, 96, 3]] # 12 + + - [-1, 1, nn.Upsample, [None, 2, "nearest"]] + - [[-1, 4], 1, Concat, [1]] # cat backbone P3 + - [-1, 1, RepNCSPELAN4, [128, 128, 64, 3]] # 15 + + - [-1, 1, AConv, [96]] + - [[-1, 12], 1, Concat, [1]] # cat head P4 + - [-1, 1, RepNCSPELAN4, [192, 192, 96, 3]] # 18 (P4/16-medium) + + - [-1, 1, AConv, [128]] + - [[-1, 9], 1, Concat, [1]] # cat head P5 + - [-1, 1, RepNCSPELAN4, [256, 256, 128, 3]] # 21 (P5/32-large) + + - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4 P5) diff --git a/ultralytics/cfg/models/v9/yolov9t.yaml b/ultralytics/cfg/models/v9/yolov9t.yaml new file mode 100644 index 00000000..2f3a6e42 --- /dev/null +++ b/ultralytics/cfg/models/v9/yolov9t.yaml @@ -0,0 +1,38 @@ +# Ultralytics YOLO 🚀, AGPL-3.0 license +# YOLOv9t +# 917 layers, 2128720 parameters, 8.5 GFLOPs + +# parameters +nc: 80 # number of classes + +# gelan backbone +backbone: + - [-1, 1, Conv, [16, 3, 2]] # 0-P1/2 + - [-1, 1, Conv, [32, 3, 2]] # 1-P2/4 + - [-1, 1, ELAN1, [32, 32, 16]] # 2 + - [-1, 1, AConv, [64]] # 3-P3/8 + - [-1, 1, RepNCSPELAN4, [64, 64, 32, 3]] # 4 + - [-1, 1, AConv, [96]] # 5-P4/16 + - [-1, 1, RepNCSPELAN4, [96, 96, 48, 3]] # 6 + - [-1, 1, AConv, [128]] # 7-P5/32 + - [-1, 1, RepNCSPELAN4, [128, 128, 64, 3]] # 8 + - [-1, 1, SPPELAN, [128, 64]] # 9 + +head: + - [-1, 1, nn.Upsample, [None, 2, "nearest"]] + - [[-1, 6], 1, Concat, [1]] # cat backbone P4 + - [-1, 1, RepNCSPELAN4, [96, 96, 48, 3]] # 12 + + - [-1, 1, nn.Upsample, [None, 2, "nearest"]] + - [[-1, 4], 1, Concat, [1]] # cat backbone P3 + - [-1, 1, RepNCSPELAN4, [64, 64, 32, 3]] # 15 + + - [-1, 1, AConv, [48]] + - [[-1, 12], 1, Concat, [1]] # cat head P4 + - [-1, 1, RepNCSPELAN4, [96, 96, 48, 3]] # 18 (P4/16-medium) + + - [-1, 1, AConv, [64]] + - [[-1, 9], 1, Concat, [1]] # cat head P5 + - [-1, 1, RepNCSPELAN4, [128, 128, 64, 3]] # 21 (P5/32-large) + + - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) diff --git a/ultralytics/nn/modules/__init__.py b/ultralytics/nn/modules/__init__.py index 1b1fe5f6..b9e9ace3 100644 --- a/ultralytics/nn/modules/__init__.py +++ b/ultralytics/nn/modules/__init__.py @@ -23,9 +23,11 @@ from .block import ( C3, C3TR, DFL, + ELAN1, SPP, SPPELAN, SPPF, + AConv, ADown, BNContrastiveHead, Bottleneck, @@ -133,4 +135,6 @@ __all__ = ( "SPPELAN", "CBFuse", "CBLinear", + "AConv", + "ELAN1", ) diff --git a/ultralytics/nn/modules/block.py b/ultralytics/nn/modules/block.py index 5f6d1c0a..4c864dbe 100644 --- a/ultralytics/nn/modules/block.py +++ b/ultralytics/nn/modules/block.py @@ -32,7 +32,9 @@ __all__ = ( "RepC3", "ResNetLayer", "RepNCSPELAN4", + "ELAN1", "ADown", + "AConv", "SPPELAN", "CBFuse", "CBLinear", @@ -603,6 +605,33 @@ class RepNCSPELAN4(nn.Module): return self.cv4(torch.cat(y, 1)) +class ELAN1(RepNCSPELAN4): + """ELAN1 module with 4 convolutions.""" + + def __init__(self, c1, c2, c3, c4): + """Initializes ELAN1 layer with specified channel sizes.""" + super().__init__(c1, c2, c3, c4) + self.c = c3 // 2 + self.cv1 = Conv(c1, c3, 1, 1) + self.cv2 = Conv(c3 // 2, c4, 3, 1) + self.cv3 = Conv(c4, c4, 3, 1) + self.cv4 = Conv(c3 + (2 * c4), c2, 1, 1) + + +class AConv(nn.Module): + """AConv.""" + + def __init__(self, c1, c2): + """Initializes AConv module with convolution layers.""" + super().__init__() + self.cv1 = Conv(c1, c2, 3, 2, 1) + + def forward(self, x): + """Forward pass through AConv layer.""" + x = torch.nn.functional.avg_pool2d(x, 2, 1, 0, False, True) + return self.cv1(x) + + class ADown(nn.Module): """ADown.""" diff --git a/ultralytics/nn/tasks.py b/ultralytics/nn/tasks.py index 020f873b..cd4c790d 100644 --- a/ultralytics/nn/tasks.py +++ b/ultralytics/nn/tasks.py @@ -13,10 +13,12 @@ from ultralytics.nn.modules import ( C2, C3, C3TR, + ELAN1, OBB, SPP, SPPELAN, SPPF, + AConv, ADown, Bottleneck, BottleneckCSP, @@ -878,7 +880,9 @@ def parse_model(d, ch, verbose=True): # model_dict, input_channels(3) C2, C2f, RepNCSPELAN4, + ELAN1, ADown, + AConv, SPPELAN, C2fAttn, C3,