diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml index 271ee36c..ea9d0bcb 100644 --- a/.github/workflows/greetings.yml +++ b/.github/workflows/greetings.yml @@ -52,4 +52,4 @@ jobs: Ultralytics CI - If this badge is green, all [Ultralytics CI](https://github.com/ultralytics/ultralytics/actions/workflows/ci.yaml?query=event%3Aschedule) tests are currently passing. CI tests verify correct operation of all YOLOv8 modes and tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit. + If this badge is green, all [Ultralytics CI](https://github.com/ultralytics/ultralytics/actions/workflows/ci.yaml?query=event%3Aschedule) tests are currently passing. CI tests verify correct operation of all YOLOv8 [Modes](https://docs.ultralytics.com/modes/) and [Tasks](https://docs.ultralytics.com/tasks/) on macOS, Windows, and Ubuntu every 24 hours and on every commit. diff --git a/docs/tasks/classify.md b/docs/tasks/classify.md index 9c25a4bb..73a4ae95 100644 --- a/docs/tasks/classify.md +++ b/docs/tasks/classify.md @@ -26,16 +26,25 @@ see the [Configuration](../usage/cfg.md) page. from ultralytics import YOLO # Load a model - model = YOLO('yolov8n-cls.yaml') # build a new model from scratch + model = YOLO('yolov8n-cls.yaml') # build a new model from YAML model = YOLO('yolov8n-cls.pt') # load a pretrained model (recommended for training) + model = YOLO('yolov8n-cls.yaml').load('yolov8n-cls.pt') # build from YAML and transfer weights # Train the model model.train(data='mnist160', epochs=100, imgsz=64) ``` + === "CLI" - + ```bash + # Build a new model from YAML and start training from scratch + yolo classify train data=mnist160 model=yolov8n-cls.yaml epochs=100 imgsz=64 + + # Start training from a pretrained *.pt model yolo classify train data=mnist160 model=yolov8n-cls.pt epochs=100 imgsz=64 + + # Build a new model from YAML, transfer pretrained weights to it and start training + yolo classify train data=mnist160 model=yolov8n-cls.yaml pretrained=yolov8n-cls.pt epochs=100 imgsz=64 ``` ## Val diff --git a/docs/tasks/detect.md b/docs/tasks/detect.md index cf13b232..72020104 100644 --- a/docs/tasks/detect.md +++ b/docs/tasks/detect.md @@ -26,8 +26,9 @@ the [Configuration](../usage/cfg.md) page. from ultralytics import YOLO # Load a model - model = YOLO('yolov8n.yaml') # build a new model from scratch + model = YOLO('yolov8n.yaml') # build a new model from YAML model = YOLO('yolov8n.pt') # load a pretrained model (recommended for training) + model = YOLO('yolov8n.yaml').load('yolov8n.pt') # build from YAML and transfer weights # Train the model model.train(data='coco128.yaml', epochs=100, imgsz=640) @@ -35,7 +36,14 @@ the [Configuration](../usage/cfg.md) page. === "CLI" ```bash + # Build a new model from YAML and start training from scratch + yolo detect train data=coco128.yaml model=yolov8n.yaml epochs=100 imgsz=640 + + # Start training from a pretrained *.pt model yolo detect train data=coco128.yaml model=yolov8n.pt epochs=100 imgsz=640 + + # Build a new model from YAML, transfer pretrained weights to it and start training + yolo detect train data=coco128.yaml model=yolov8n.yaml pretrained=yolov8n.pt epochs=100 imgsz=640 ``` ## Val diff --git a/docs/tasks/keypoints.md b/docs/tasks/keypoints.md index 60a688f0..d9f24846 100644 --- a/docs/tasks/keypoints.md +++ b/docs/tasks/keypoints.md @@ -28,8 +28,9 @@ train an OpenPose model on a custom dataset, see the OpenPose Training page. from ultralytics import YOLO # Load a model - model = YOLO('yolov8n.yaml') # build a new model from scratch + model = YOLO('yolov8n.yaml') # build a new model from YAML model = YOLO('yolov8n.pt') # load a pretrained model (recommended for training) + model = YOLO('yolov8n.yaml').load('yolov8n.pt') # build from YAML and transfer weights # Train the model model.train(data='coco128.yaml', epochs=100, imgsz=640) @@ -37,7 +38,14 @@ train an OpenPose model on a custom dataset, see the OpenPose Training page. === "CLI" ```bash + # Build a new model from YAML and start training from scratch + yolo detect train data=coco128.yaml model=yolov8n.yaml epochs=100 imgsz=640 + + # Start training from a pretrained *.pt model yolo detect train data=coco128.yaml model=yolov8n.pt epochs=100 imgsz=640 + + # Build a new model from YAML, transfer pretrained weights to it and start training + yolo detect train data=coco128.yaml model=yolov8n.yaml pretrained=yolov8n.pt epochs=100 imgsz=640 ``` ## Val TODO diff --git a/docs/tasks/segment.md b/docs/tasks/segment.md index f89c3feb..c8391a1d 100644 --- a/docs/tasks/segment.md +++ b/docs/tasks/segment.md @@ -26,8 +26,9 @@ arguments see the [Configuration](../usage/cfg.md) page. from ultralytics import YOLO # Load a model - model = YOLO('yolov8n-seg.yaml') # build a new model from scratch + model = YOLO('yolov8n-seg.yaml') # build a new model from YAML model = YOLO('yolov8n-seg.pt') # load a pretrained model (recommended for training) + model = YOLO('yolov8n-seg.yaml').load('yolov8n.pt') # build from YAML and transfer weights # Train the model model.train(data='coco128-seg.yaml', epochs=100, imgsz=640) @@ -35,7 +36,14 @@ arguments see the [Configuration](../usage/cfg.md) page. === "CLI" ```bash + # Build a new model from YAML and start training from scratch + yolo segment train data=coco128-seg.yaml model=yolov8n-seg.yaml epochs=100 imgsz=640 + + # Start training from a pretrained *.pt model yolo segment train data=coco128-seg.yaml model=yolov8n-seg.pt epochs=100 imgsz=640 + + # Build a new model from YAML, transfer pretrained weights to it and start training + yolo segment train data=coco128-seg.yaml model=yolov8n-seg.yaml pretrained=yolov8n-seg.pt epochs=100 imgsz=640 ``` ## Val diff --git a/docs/usage/cfg.md b/docs/usage/cfg.md index 763b8921..df6fbceb 100644 --- a/docs/usage/cfg.md +++ b/docs/usage/cfg.md @@ -143,7 +143,7 @@ given task. | `agnostic_nms` | `False` | class-agnostic NMS | | `retina_masks` | `False` | use high-resolution segmentation masks | | `classes` | `None` | filter results by class, i.e. class=0, or class=[0,2,3] | -| `box` | `True` | Show boxes in segmentation predictions | +| `boxes` | `True` | Show boxes in segmentation predictions | ### Validation diff --git a/tests/test_engine.py b/tests/test_engine.py index e842bddb..c20edc10 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -74,16 +74,9 @@ def test_segment(): def test_classify(): - overrides = { - 'data': 'imagenet10', - 'model': 'yolov8n-cls.yaml', - 'imgsz': 32, - 'epochs': 1, - 'batch': 64, - 'save': False} + overrides = {'data': 'imagenet10', 'model': 'yolov8n-cls.yaml', 'imgsz': 32, 'epochs': 1, 'save': False} CFG.data = 'imagenet10' CFG.imgsz = 32 - CFG.batch = 64 # YOLO(CFG_SEG).train(**overrides) # works # Trainer diff --git a/ultralytics/__init__.py b/ultralytics/__init__.py index aceaf5df..45ce04cc 100644 --- a/ultralytics/__init__.py +++ b/ultralytics/__init__.py @@ -1,6 +1,6 @@ # Ultralytics YOLO 🚀, GPL-3.0 license -__version__ = '8.0.54' +__version__ = '8.0.55' from ultralytics.yolo.engine.model import YOLO from ultralytics.yolo.utils.checks import check_yolo as checks diff --git a/ultralytics/models/v3/yolov3-sppu.yaml b/ultralytics/models/v3/yolov3-spp.yaml similarity index 100% rename from ultralytics/models/v3/yolov3-sppu.yaml rename to ultralytics/models/v3/yolov3-spp.yaml diff --git a/ultralytics/models/v3/yolov3-tinyu.yaml b/ultralytics/models/v3/yolov3-tiny.yaml similarity index 100% rename from ultralytics/models/v3/yolov3-tinyu.yaml rename to ultralytics/models/v3/yolov3-tiny.yaml diff --git a/ultralytics/models/v3/yolov3u.yaml b/ultralytics/models/v3/yolov3.yaml similarity index 100% rename from ultralytics/models/v3/yolov3u.yaml rename to ultralytics/models/v3/yolov3.yaml diff --git a/ultralytics/models/v5/yolov5l6u.yaml b/ultralytics/models/v5/yolov5-p6.yaml similarity index 85% rename from ultralytics/models/v5/yolov5l6u.yaml rename to ultralytics/models/v5/yolov5-p6.yaml index 76da02ac..ce9d3544 100644 --- a/ultralytics/models/v5/yolov5l6u.yaml +++ b/ultralytics/models/v5/yolov5-p6.yaml @@ -2,8 +2,13 @@ # Parameters nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple +scales: # model compound scaling constants, i.e. 'model=yolov5n-p6.yaml' will call yolov5-p6.yaml with scale 'n' + # [depth, width, max_channels] + n: [0.33, 0.25, 1024] + s: [0.33, 0.50, 1024] + m: [0.67, 0.75, 1024] + l: [1.00, 1.00, 1024] + x: [1.33, 1.25, 1024] # YOLOv5 v6.0 backbone backbone: diff --git a/ultralytics/models/v5/yolov5su.yaml b/ultralytics/models/v5/yolov5.yaml similarity index 81% rename from ultralytics/models/v5/yolov5su.yaml rename to ultralytics/models/v5/yolov5.yaml index 8cd3c5b9..c9d6f3e1 100644 --- a/ultralytics/models/v5/yolov5su.yaml +++ b/ultralytics/models/v5/yolov5.yaml @@ -2,8 +2,13 @@ # Parameters nc: 80 # number of classes -depth_multiple: 0.33 # model depth multiple -width_multiple: 0.50 # layer channel multiple +scales: # model compound scaling constants, i.e. 'model=yolov5n.yaml' will call yolov5.yaml with scale 'n' + # [depth, width, max_channels] + n: [0.33, 0.25, 1024] + s: [0.33, 0.50, 1024] + m: [0.67, 0.75, 1024] + l: [1.00, 1.00, 1024] + x: [1.33, 1.25, 1024] # YOLOv5 v6.0 backbone backbone: diff --git a/ultralytics/models/v5/yolov5lu.yaml b/ultralytics/models/v5/yolov5lu.yaml deleted file mode 100644 index dc3e4b36..00000000 --- a/ultralytics/models/v5/yolov5lu.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 1.0 # model depth multiple -width_multiple: 1.0 # layer channel multiple - -# YOLOv5 v6.0 backbone -backbone: - # [from, number, module, args] - [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 - [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, C3, [128]], - [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 6, C3, [256]], - [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, C3, [512]], - [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 - [-1, 3, C3, [1024]], - [-1, 1, SPPF, [1024, 5]], # 9 - ] - -# YOLOv5 v6.0 head -head: - [[-1, 1, Conv, [512, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, C3, [512, False]], # 13 - - [-1, 1, Conv, [256, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 4], 1, Concat, [1]], # cat backbone P3 - [-1, 3, C3, [256, False]], # 17 (P3/8-small) - - [-1, 1, Conv, [256, 3, 2]], - [[-1, 14], 1, Concat, [1]], # cat head P4 - [-1, 3, C3, [512, False]], # 20 (P4/16-medium) - - [-1, 1, Conv, [512, 3, 2]], - [[-1, 10], 1, Concat, [1]], # cat head P5 - [-1, 3, C3, [1024, False]], # 23 (P5/32-large) - - [[17, 20, 23], 1, Detect, [nc]], # Detect(P3, P4, P5) - ] diff --git a/ultralytics/models/v5/yolov5m6u.yaml b/ultralytics/models/v5/yolov5m6u.yaml deleted file mode 100644 index 84274ea0..00000000 --- a/ultralytics/models/v5/yolov5m6u.yaml +++ /dev/null @@ -1,55 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 0.67 # model depth multiple -width_multiple: 0.75 # layer channel multiple - -# YOLOv5 v6.0 backbone -backbone: - # [from, number, module, args] - [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 - [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, C3, [128]], - [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 6, C3, [256]], - [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, C3, [512]], - [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 - [-1, 3, C3, [768]], - [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 - [-1, 3, C3, [1024]], - [-1, 1, SPPF, [1024, 5]], # 11 - ] - -# YOLOv5 v6.0 head -head: - [[-1, 1, Conv, [768, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 8], 1, Concat, [1]], # cat backbone P5 - [-1, 3, C3, [768, False]], # 15 - - [-1, 1, Conv, [512, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, C3, [512, False]], # 19 - - [-1, 1, Conv, [256, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 4], 1, Concat, [1]], # cat backbone P3 - [-1, 3, C3, [256, False]], # 23 (P3/8-small) - - [-1, 1, Conv, [256, 3, 2]], - [[-1, 20], 1, Concat, [1]], # cat head P4 - [-1, 3, C3, [512, False]], # 26 (P4/16-medium) - - [-1, 1, Conv, [512, 3, 2]], - [[-1, 16], 1, Concat, [1]], # cat head P5 - [-1, 3, C3, [768, False]], # 29 (P5/32-large) - - [-1, 1, Conv, [768, 3, 2]], - [[-1, 12], 1, Concat, [1]], # cat head P6 - [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) - - [[23, 26, 29, 32], 1, Detect, [nc]], # Detect(P3, P4, P5, P6) - ] diff --git a/ultralytics/models/v5/yolov5mu.yaml b/ultralytics/models/v5/yolov5mu.yaml deleted file mode 100644 index 3703a1bb..00000000 --- a/ultralytics/models/v5/yolov5mu.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 0.67 # model depth multiple -width_multiple: 0.75 # layer channel multiple - -# YOLOv5 v6.0 backbone -backbone: - # [from, number, module, args] - [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 - [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, C3, [128]], - [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 6, C3, [256]], - [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, C3, [512]], - [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 - [-1, 3, C3, [1024]], - [-1, 1, SPPF, [1024, 5]], # 9 - ] - -# YOLOv5 v6.0 head -head: - [[-1, 1, Conv, [512, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, C3, [512, False]], # 13 - - [-1, 1, Conv, [256, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 4], 1, Concat, [1]], # cat backbone P3 - [-1, 3, C3, [256, False]], # 17 (P3/8-small) - - [-1, 1, Conv, [256, 3, 2]], - [[-1, 14], 1, Concat, [1]], # cat head P4 - [-1, 3, C3, [512, False]], # 20 (P4/16-medium) - - [-1, 1, Conv, [512, 3, 2]], - [[-1, 10], 1, Concat, [1]], # cat head P5 - [-1, 3, C3, [1024, False]], # 23 (P5/32-large) - - [[17, 20, 23], 1, Detect, [nc]], # Detect(P3, P4, P5) - ] diff --git a/ultralytics/models/v5/yolov5n6u.yaml b/ultralytics/models/v5/yolov5n6u.yaml deleted file mode 100644 index 5776879d..00000000 --- a/ultralytics/models/v5/yolov5n6u.yaml +++ /dev/null @@ -1,55 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 0.33 # model depth multiple -width_multiple: 0.25 # layer channel multiple - -# YOLOv5 v6.0 backbone -backbone: - # [from, number, module, args] - [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 - [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, C3, [128]], - [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 6, C3, [256]], - [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, C3, [512]], - [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 - [-1, 3, C3, [768]], - [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 - [-1, 3, C3, [1024]], - [-1, 1, SPPF, [1024, 5]], # 11 - ] - -# YOLOv5 v6.0 head -head: - [[-1, 1, Conv, [768, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 8], 1, Concat, [1]], # cat backbone P5 - [-1, 3, C3, [768, False]], # 15 - - [-1, 1, Conv, [512, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, C3, [512, False]], # 19 - - [-1, 1, Conv, [256, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 4], 1, Concat, [1]], # cat backbone P3 - [-1, 3, C3, [256, False]], # 23 (P3/8-small) - - [-1, 1, Conv, [256, 3, 2]], - [[-1, 20], 1, Concat, [1]], # cat head P4 - [-1, 3, C3, [512, False]], # 26 (P4/16-medium) - - [-1, 1, Conv, [512, 3, 2]], - [[-1, 16], 1, Concat, [1]], # cat head P5 - [-1, 3, C3, [768, False]], # 29 (P5/32-large) - - [-1, 1, Conv, [768, 3, 2]], - [[-1, 12], 1, Concat, [1]], # cat head P6 - [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) - - [[23, 26, 29, 32], 1, Detect, [nc]], # Detect(P3, P4, P5, P6) - ] diff --git a/ultralytics/models/v5/yolov5nu.yaml b/ultralytics/models/v5/yolov5nu.yaml deleted file mode 100644 index 76489250..00000000 --- a/ultralytics/models/v5/yolov5nu.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 0.33 # model depth multiple -width_multiple: 0.25 # layer channel multiple - -# YOLOv5 v6.0 backbone -backbone: - # [from, number, module, args] - [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 - [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, C3, [128]], - [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 6, C3, [256]], - [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, C3, [512]], - [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 - [-1, 3, C3, [1024]], - [-1, 1, SPPF, [1024, 5]], # 9 - ] - -# YOLOv5 v6.0 head -head: - [[-1, 1, Conv, [512, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, C3, [512, False]], # 13 - - [-1, 1, Conv, [256, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 4], 1, Concat, [1]], # cat backbone P3 - [-1, 3, C3, [256, False]], # 17 (P3/8-small) - - [-1, 1, Conv, [256, 3, 2]], - [[-1, 14], 1, Concat, [1]], # cat head P4 - [-1, 3, C3, [512, False]], # 20 (P4/16-medium) - - [-1, 1, Conv, [512, 3, 2]], - [[-1, 10], 1, Concat, [1]], # cat head P5 - [-1, 3, C3, [1024, False]], # 23 (P5/32-large) - - [[17, 20, 23], 1, Detect, [nc]], # Detect(P3, P4, P5) - ] diff --git a/ultralytics/models/v5/yolov5s6u.yaml b/ultralytics/models/v5/yolov5s6u.yaml deleted file mode 100644 index 90a39c0b..00000000 --- a/ultralytics/models/v5/yolov5s6u.yaml +++ /dev/null @@ -1,55 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 0.33 # model depth multiple -width_multiple: 0.50 # layer channel multiple - -# YOLOv5 v6.0 backbone -backbone: - # [from, number, module, args] - [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 - [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, C3, [128]], - [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 6, C3, [256]], - [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, C3, [512]], - [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 - [-1, 3, C3, [768]], - [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 - [-1, 3, C3, [1024]], - [-1, 1, SPPF, [1024, 5]], # 11 - ] - -# YOLOv5 v6.0 head -head: - [[-1, 1, Conv, [768, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 8], 1, Concat, [1]], # cat backbone P5 - [-1, 3, C3, [768, False]], # 15 - - [-1, 1, Conv, [512, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, C3, [512, False]], # 19 - - [-1, 1, Conv, [256, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 4], 1, Concat, [1]], # cat backbone P3 - [-1, 3, C3, [256, False]], # 23 (P3/8-small) - - [-1, 1, Conv, [256, 3, 2]], - [[-1, 20], 1, Concat, [1]], # cat head P4 - [-1, 3, C3, [512, False]], # 26 (P4/16-medium) - - [-1, 1, Conv, [512, 3, 2]], - [[-1, 16], 1, Concat, [1]], # cat head P5 - [-1, 3, C3, [768, False]], # 29 (P5/32-large) - - [-1, 1, Conv, [768, 3, 2]], - [[-1, 12], 1, Concat, [1]], # cat head P6 - [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) - - [[23, 26, 29, 32], 1, Detect, [nc]], # Detect(P3, P4, P5, P6) - ] diff --git a/ultralytics/models/v5/yolov5x6u.yaml b/ultralytics/models/v5/yolov5x6u.yaml deleted file mode 100644 index 31cd9c9e..00000000 --- a/ultralytics/models/v5/yolov5x6u.yaml +++ /dev/null @@ -1,55 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 1.33 # model depth multiple -width_multiple: 1.25 # layer channel multiple - -# YOLOv5 v6.0 backbone -backbone: - # [from, number, module, args] - [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 - [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, C3, [128]], - [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 6, C3, [256]], - [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, C3, [512]], - [-1, 1, Conv, [768, 3, 2]], # 7-P5/32 - [-1, 3, C3, [768]], - [-1, 1, Conv, [1024, 3, 2]], # 9-P6/64 - [-1, 3, C3, [1024]], - [-1, 1, SPPF, [1024, 5]], # 11 - ] - -# YOLOv5 v6.0 head -head: - [[-1, 1, Conv, [768, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 8], 1, Concat, [1]], # cat backbone P5 - [-1, 3, C3, [768, False]], # 15 - - [-1, 1, Conv, [512, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, C3, [512, False]], # 19 - - [-1, 1, Conv, [256, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 4], 1, Concat, [1]], # cat backbone P3 - [-1, 3, C3, [256, False]], # 23 (P3/8-small) - - [-1, 1, Conv, [256, 3, 2]], - [[-1, 20], 1, Concat, [1]], # cat head P4 - [-1, 3, C3, [512, False]], # 26 (P4/16-medium) - - [-1, 1, Conv, [512, 3, 2]], - [[-1, 16], 1, Concat, [1]], # cat head P5 - [-1, 3, C3, [768, False]], # 29 (P5/32-large) - - [-1, 1, Conv, [768, 3, 2]], - [[-1, 12], 1, Concat, [1]], # cat head P6 - [-1, 3, C3, [1024, False]], # 32 (P6/64-xlarge) - - [[23, 26, 29, 32], 1, Detect, [nc]], # Detect(P3, P4, P5, P6) - ] diff --git a/ultralytics/models/v5/yolov5xu.yaml b/ultralytics/models/v5/yolov5xu.yaml deleted file mode 100644 index e3275ab5..00000000 --- a/ultralytics/models/v5/yolov5xu.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 1.33 # model depth multiple -width_multiple: 1.25 # layer channel multiple - -# YOLOv5 v6.0 backbone -backbone: - # [from, number, module, args] - [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 - [-1, 1, Conv, [128, 3, 2]], # 1-P2/4 - [-1, 3, C3, [128]], - [-1, 1, Conv, [256, 3, 2]], # 3-P3/8 - [-1, 6, C3, [256]], - [-1, 1, Conv, [512, 3, 2]], # 5-P4/16 - [-1, 9, C3, [512]], - [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32 - [-1, 3, C3, [1024]], - [-1, 1, SPPF, [1024, 5]], # 9 - ] - -# YOLOv5 v6.0 head -head: - [[-1, 1, Conv, [512, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 6], 1, Concat, [1]], # cat backbone P4 - [-1, 3, C3, [512, False]], # 13 - - [-1, 1, Conv, [256, 1, 1]], - [-1, 1, nn.Upsample, [None, 2, 'nearest']], - [[-1, 4], 1, Concat, [1]], # cat backbone P3 - [-1, 3, C3, [256, False]], # 17 (P3/8-small) - - [-1, 1, Conv, [256, 3, 2]], - [[-1, 14], 1, Concat, [1]], # cat head P4 - [-1, 3, C3, [512, False]], # 20 (P4/16-medium) - - [-1, 1, Conv, [512, 3, 2]], - [[-1, 10], 1, Concat, [1]], # cat head P5 - [-1, 3, C3, [1024, False]], # 23 (P5/32-large) - - [[17, 20, 23], 1, Detect, [nc]], # Detect(P3, P4, P5) - ] diff --git a/ultralytics/models/v8/cls/yolov8m-cls.yaml b/ultralytics/models/v8/cls/yolov8m-cls.yaml deleted file mode 100644 index 7e91894c..00000000 --- a/ultralytics/models/v8/cls/yolov8m-cls.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 1000 # number of classes -depth_multiple: 0.67 # scales module repeats -width_multiple: 0.75 # scales convolution channels - -# YOLOv8.0n backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [1024, True]] - -# YOLOv8.0n head -head: - - [-1, 1, Classify, [nc]] diff --git a/ultralytics/models/v8/cls/yolov8n-cls.yaml b/ultralytics/models/v8/cls/yolov8n-cls.yaml deleted file mode 100644 index 29be2264..00000000 --- a/ultralytics/models/v8/cls/yolov8n-cls.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 1000 # number of classes -depth_multiple: 0.33 # scales module repeats -width_multiple: 0.25 # scales convolution channels - -# YOLOv8.0n backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [1024, True]] - -# YOLOv8.0n head -head: - - [-1, 1, Classify, [nc]] diff --git a/ultralytics/models/v8/cls/yolov8s-cls.yaml b/ultralytics/models/v8/cls/yolov8s-cls.yaml deleted file mode 100644 index 00ddc55a..00000000 --- a/ultralytics/models/v8/cls/yolov8s-cls.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 1000 # number of classes -depth_multiple: 0.33 # scales module repeats -width_multiple: 0.50 # scales convolution channels - -# YOLOv8.0n backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [1024, True]] - -# YOLOv8.0n head -head: - - [-1, 1, Classify, [nc]] diff --git a/ultralytics/models/v8/cls/yolov8x-cls.yaml b/ultralytics/models/v8/cls/yolov8x-cls.yaml deleted file mode 100644 index 46c75d5a..00000000 --- a/ultralytics/models/v8/cls/yolov8x-cls.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 1000 # number of classes -depth_multiple: 1.00 # scales module repeats -width_multiple: 1.25 # scales convolution channels - -# YOLOv8.0n backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [1024, True]] - -# YOLOv8.0n head -head: - - [-1, 1, Classify, [nc]] diff --git a/ultralytics/models/v8/seg/yolov8l-seg.yaml b/ultralytics/models/v8/seg/yolov8l-seg.yaml deleted file mode 100644 index 72bf0088..00000000 --- a/ultralytics/models/v8/seg/yolov8l-seg.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 1.00 # scales module repeats -width_multiple: 1.00 # scales convolution channels - -# YOLOv8.0l backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [512, True]] - - [-1, 1, SPPF, [512, 5]] # 9 - -# YOLOv8.0l head -head: - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 6], 1, Concat, [1]] # cat backbone P4 - - [-1, 3, C2f, [512]] # 12 - - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 4], 1, Concat, [1]] # cat backbone P3 - - [-1, 3, C2f, [256]] # 15 (P3/8-small) - - - [-1, 1, Conv, [256, 3, 2]] - - [[-1, 12], 1, Concat, [1]] # cat head P4 - - [-1, 3, C2f, [512]] # 18 (P4/16-medium) - - - [-1, 1, Conv, [512, 3, 2]] - - [[-1, 9], 1, Concat, [1]] # cat head P5 - - [-1, 3, C2f, [512]] # 21 (P5/32-large) - - - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) diff --git a/ultralytics/models/v8/seg/yolov8m-seg.yaml b/ultralytics/models/v8/seg/yolov8m-seg.yaml deleted file mode 100644 index 7e742275..00000000 --- a/ultralytics/models/v8/seg/yolov8m-seg.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 0.67 # scales module repeats -width_multiple: 0.75 # scales convolution channels - -# YOLOv8.0m backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [768, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [768, True]] - - [-1, 1, SPPF, [768, 5]] # 9 - -# YOLOv8.0m head -head: - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 6], 1, Concat, [1]] # cat backbone P4 - - [-1, 3, C2f, [512]] # 12 - - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 4], 1, Concat, [1]] # cat backbone P3 - - [-1, 3, C2f, [256]] # 15 (P3/8-small) - - - [-1, 1, Conv, [256, 3, 2]] - - [[-1, 12], 1, Concat, [1]] # cat head P4 - - [-1, 3, C2f, [512]] # 18 (P4/16-medium) - - - [-1, 1, Conv, [512, 3, 2]] - - [[-1, 9], 1, Concat, [1]] # cat head P5 - - [-1, 3, C2f, [768]] # 21 (P5/32-large) - - - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) diff --git a/ultralytics/models/v8/seg/yolov8n-seg.yaml b/ultralytics/models/v8/seg/yolov8n-seg.yaml deleted file mode 100644 index 5f39e101..00000000 --- a/ultralytics/models/v8/seg/yolov8n-seg.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 0.33 # scales module repeats -width_multiple: 0.25 # scales convolution channels - -# YOLOv8.0n backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [1024, True]] - - [-1, 1, SPPF, [1024, 5]] # 9 - -# YOLOv8.0n head -head: - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 6], 1, Concat, [1]] # cat backbone P4 - - [-1, 3, C2f, [512]] # 12 - - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 4], 1, Concat, [1]] # cat backbone P3 - - [-1, 3, C2f, [256]] # 15 (P3/8-small) - - - [-1, 1, Conv, [256, 3, 2]] - - [[-1, 12], 1, Concat, [1]] # cat head P4 - - [-1, 3, C2f, [512]] # 18 (P4/16-medium) - - - [-1, 1, Conv, [512, 3, 2]] - - [[-1, 9], 1, Concat, [1]] # cat head P5 - - [-1, 3, C2f, [1024]] # 21 (P5/32-large) - - - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) diff --git a/ultralytics/models/v8/seg/yolov8s-seg.yaml b/ultralytics/models/v8/seg/yolov8s-seg.yaml deleted file mode 100644 index 27946164..00000000 --- a/ultralytics/models/v8/seg/yolov8s-seg.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 0.33 # scales module repeats -width_multiple: 0.50 # scales convolution channels - -# YOLOv8.0s backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [1024, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [1024, True]] - - [-1, 1, SPPF, [1024, 5]] # 9 - -# YOLOv8.0s head -head: - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 6], 1, Concat, [1]] # cat backbone P4 - - [-1, 3, C2f, [512]] # 12 - - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 4], 1, Concat, [1]] # cat backbone P3 - - [-1, 3, C2f, [256]] # 15 (P3/8-small) - - - [-1, 1, Conv, [256, 3, 2]] - - [[-1, 12], 1, Concat, [1]] # cat head P4 - - [-1, 3, C2f, [512]] # 18 (P4/16-medium) - - - [-1, 1, Conv, [512, 3, 2]] - - [[-1, 9], 1, Concat, [1]] # cat head P5 - - [-1, 3, C2f, [1024]] # 21 (P5/32-large) - - - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) diff --git a/ultralytics/models/v8/seg/yolov8x-seg.yaml b/ultralytics/models/v8/seg/yolov8x-seg.yaml deleted file mode 100644 index 3edb030b..00000000 --- a/ultralytics/models/v8/seg/yolov8x-seg.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 1.00 # scales module repeats -width_multiple: 1.25 # scales convolution channels - -# YOLOv8.0x backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [512, True]] - - [-1, 1, SPPF, [512, 5]] # 9 - -# YOLOv8.0x head -head: - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 6], 1, Concat, [1]] # cat backbone P4 - - [-1, 3, C2f, [512]] # 12 - - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 4], 1, Concat, [1]] # cat backbone P3 - - [-1, 3, C2f, [256]] # 15 (P3/8-small) - - - [-1, 1, Conv, [256, 3, 2]] - - [[-1, 12], 1, Concat, [1]] # cat head P4 - - [-1, 3, C2f, [512]] # 18 (P4/16-medium) - - - [-1, 1, Conv, [512, 3, 2]] - - [[-1, 9], 1, Concat, [1]] # cat head P5 - - [-1, 3, C2f, [512]] # 21 (P5/32-large) - - - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Detect(P3, P4, P5) diff --git a/ultralytics/models/v8/cls/yolov8l-cls.yaml b/ultralytics/models/v8/yolov8-cls.yaml similarity index 54% rename from ultralytics/models/v8/cls/yolov8l-cls.yaml rename to ultralytics/models/v8/yolov8-cls.yaml index bf981a84..0847ed1c 100644 --- a/ultralytics/models/v8/cls/yolov8l-cls.yaml +++ b/ultralytics/models/v8/yolov8-cls.yaml @@ -1,9 +1,15 @@ # Ultralytics YOLO 🚀, GPL-3.0 license +# YOLOv8-cls image classification model. For Usage examples see https://docs.ultralytics.com/tasks/classify # Parameters nc: 1000 # number of classes -depth_multiple: 1.00 # scales module repeats -width_multiple: 1.00 # scales convolution channels +scales: # model compound scaling constants, i.e. 'model=yolov8n-cls.yaml' will call yolov8-cls.yaml with scale 'n' + # [depth, width, max_channels] + n: [0.33, 0.25, 1024] + s: [0.33, 0.50, 1024] + m: [0.67, 0.75, 1024] + l: [1.00, 1.00, 1024] + x: [1.00, 1.25, 1024] # YOLOv8.0n backbone backbone: @@ -20,4 +26,4 @@ backbone: # YOLOv8.0n head head: - - [-1, 1, Classify, [nc]] + - [-1, 1, Classify, [nc]] # Classify diff --git a/ultralytics/models/v8/yolov8x6.yaml b/ultralytics/models/v8/yolov8-p6.yaml similarity index 60% rename from ultralytics/models/v8/yolov8x6.yaml rename to ultralytics/models/v8/yolov8-p6.yaml index 8ffcdeae..ab8a68ed 100644 --- a/ultralytics/models/v8/yolov8x6.yaml +++ b/ultralytics/models/v8/yolov8-p6.yaml @@ -1,9 +1,15 @@ # Ultralytics YOLO 🚀, GPL-3.0 license +# YOLOv8 object detection model with P3-P6 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect # Parameters nc: 80 # number of classes -depth_multiple: 1.00 # scales module repeats -width_multiple: 1.25 # scales convolution channels +scales: # model compound scaling constants, i.e. 'model=yolov8n-p6.yaml' will call yolov8-p6.yaml with scale 'n' + # [depth, width, max_channels] + n: [0.33, 0.25, 1024] + s: [0.33, 0.50, 1024] + m: [0.67, 0.75, 768] + l: [1.00, 1.00, 512] + x: [1.00, 1.25, 512] # YOLOv8.0x6 backbone backbone: @@ -15,17 +21,17 @@ backbone: - [-1, 6, C2f, [256, True]] - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [512, True]] - - [-1, 1, Conv, [512, 3, 2]] # 9-P6/64 - - [-1, 3, C2f, [512, True]] - - [-1, 1, SPPF, [512, 5]] # 11 + - [-1, 1, Conv, [768, 3, 2]] # 7-P5/32 + - [-1, 3, C2f, [768, True]] + - [-1, 1, Conv, [1024, 3, 2]] # 9-P6/64 + - [-1, 3, C2f, [1024, True]] + - [-1, 1, SPPF, [1024, 5]] # 11 # YOLOv8.0x6 head head: - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - [[-1, 8], 1, Concat, [1]] # cat backbone P5 - - [-1, 3, C2, [512, False]] # 14 + - [-1, 3, C2, [768, False]] # 14 - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - [[-1, 6], 1, Concat, [1]] # cat backbone P4 @@ -41,10 +47,10 @@ head: - [-1, 1, Conv, [512, 3, 2]] - [[-1, 14], 1, Concat, [1]] # cat head P5 - - [-1, 3, C2, [512, False]] # 26 (P5/32-large) + - [-1, 3, C2, [768, False]] # 26 (P5/32-large) - - [-1, 1, Conv, [512, 3, 2]] + - [-1, 1, Conv, [768, 3, 2]] - [[-1, 11], 1, Concat, [1]] # cat head P6 - - [-1, 3, C2, [512, False]] # 29 (P6/64-xlarge) + - [-1, 3, C2, [1024, False]] # 29 (P6/64-xlarge) - [[20, 23, 26, 29], 1, Detect, [nc]] # Detect(P3, P4, P5, P6) diff --git a/ultralytics/models/v8/yolov8n.yaml b/ultralytics/models/v8/yolov8-seg.yaml similarity index 70% rename from ultralytics/models/v8/yolov8n.yaml rename to ultralytics/models/v8/yolov8-seg.yaml index 2519b402..23a52a9d 100644 --- a/ultralytics/models/v8/yolov8n.yaml +++ b/ultralytics/models/v8/yolov8-seg.yaml @@ -1,9 +1,15 @@ # Ultralytics YOLO 🚀, GPL-3.0 license +# YOLOv8-seg instance segmentation model. For Usage examples see https://docs.ultralytics.com/tasks/segment # Parameters nc: 80 # number of classes -depth_multiple: 0.33 # scales module repeats -width_multiple: 0.25 # scales convolution channels +scales: # model compound scaling constants, i.e. 'model=yolov8n-seg.yaml' will call yolov8-seg.yaml with scale 'n' + # [depth, width, max_channels] + n: [0.33, 0.25, 1024] + s: [0.33, 0.50, 1024] + m: [0.67, 0.75, 768] + l: [1.00, 1.00, 512] + x: [1.00, 1.25, 512] # YOLOv8.0n backbone backbone: @@ -37,4 +43,4 @@ head: - [[-1, 9], 1, Concat, [1]] # cat head P5 - [-1, 3, C2f, [1024]] # 21 (P5/32-large) - - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) + - [[15, 18, 21], 1, Segment, [nc, 32, 256]] # Segment(P3, P4, P5) diff --git a/ultralytics/models/v8/yolov8s.yaml b/ultralytics/models/v8/yolov8.yaml similarity index 55% rename from ultralytics/models/v8/yolov8s.yaml rename to ultralytics/models/v8/yolov8.yaml index 79056545..addaa4e9 100644 --- a/ultralytics/models/v8/yolov8s.yaml +++ b/ultralytics/models/v8/yolov8.yaml @@ -1,11 +1,17 @@ # Ultralytics YOLO 🚀, GPL-3.0 license +# YOLOv8 object detection model with P3-P5 outputs. For Usage examples see https://docs.ultralytics.com/tasks/detect # Parameters nc: 80 # number of classes -depth_multiple: 0.33 # scales module repeats -width_multiple: 0.50 # scales convolution channels +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 -# YOLOv8.0s backbone +# YOLOv8.0n backbone backbone: # [from, repeats, module, args] - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 @@ -19,7 +25,7 @@ backbone: - [-1, 3, C2f, [1024, True]] - [-1, 1, SPPF, [1024, 5]] # 9 -# YOLOv8.0s head +# YOLOv8.0n head head: - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - [[-1, 6], 1, Concat, [1]] # cat backbone P4 diff --git a/ultralytics/models/v8/yolov8l.yaml b/ultralytics/models/v8/yolov8l.yaml deleted file mode 100644 index afbe4c69..00000000 --- a/ultralytics/models/v8/yolov8l.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 1.00 # scales module repeats -width_multiple: 1.00 # scales convolution channels - -# YOLOv8.0l backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [512, True]] - - [-1, 1, SPPF, [512, 5]] # 9 - -# YOLOv8.0l head -head: - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 6], 1, Concat, [1]] # cat backbone P4 - - [-1, 3, C2f, [512]] # 12 - - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 4], 1, Concat, [1]] # cat backbone P3 - - [-1, 3, C2f, [256]] # 15 (P3/8-small) - - - [-1, 1, Conv, [256, 3, 2]] - - [[-1, 12], 1, Concat, [1]] # cat head P4 - - [-1, 3, C2f, [512]] # 18 (P4/16-medium) - - - [-1, 1, Conv, [512, 3, 2]] - - [[-1, 9], 1, Concat, [1]] # cat head P5 - - [-1, 3, C2f, [512]] # 21 (P5/32-large) - - - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) diff --git a/ultralytics/models/v8/yolov8m.yaml b/ultralytics/models/v8/yolov8m.yaml deleted file mode 100644 index a17763c6..00000000 --- a/ultralytics/models/v8/yolov8m.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 0.67 # scales module repeats -width_multiple: 0.75 # scales convolution channels - -# YOLOv8.0m backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [768, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [768, True]] - - [-1, 1, SPPF, [768, 5]] # 9 - -# YOLOv8.0m head -head: - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 6], 1, Concat, [1]] # cat backbone P4 - - [-1, 3, C2f, [512]] # 12 - - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 4], 1, Concat, [1]] # cat backbone P3 - - [-1, 3, C2f, [256]] # 15 (P3/8-small) - - - [-1, 1, Conv, [256, 3, 2]] - - [[-1, 12], 1, Concat, [1]] # cat head P4 - - [-1, 3, C2f, [512]] # 18 (P4/16-medium) - - - [-1, 1, Conv, [512, 3, 2]] - - [[-1, 9], 1, Concat, [1]] # cat head P5 - - [-1, 3, C2f, [768]] # 21 (P5/32-large) - - - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) diff --git a/ultralytics/models/v8/yolov8x.yaml b/ultralytics/models/v8/yolov8x.yaml deleted file mode 100644 index d254523c..00000000 --- a/ultralytics/models/v8/yolov8x.yaml +++ /dev/null @@ -1,40 +0,0 @@ -# Ultralytics YOLO 🚀, GPL-3.0 license - -# Parameters -nc: 80 # number of classes -depth_multiple: 1.00 # scales module repeats -width_multiple: 1.25 # scales convolution channels - -# YOLOv8.0x backbone -backbone: - # [from, repeats, module, args] - - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - - [-1, 1, Conv, [128, 3, 2]] # 1-P2/4 - - [-1, 3, C2f, [128, True]] - - [-1, 1, Conv, [256, 3, 2]] # 3-P3/8 - - [-1, 6, C2f, [256, True]] - - [-1, 1, Conv, [512, 3, 2]] # 5-P4/16 - - [-1, 6, C2f, [512, True]] - - [-1, 1, Conv, [512, 3, 2]] # 7-P5/32 - - [-1, 3, C2f, [512, True]] - - [-1, 1, SPPF, [512, 5]] # 9 - -# YOLOv8.0x head -head: - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 6], 1, Concat, [1]] # cat backbone P4 - - [-1, 3, C2f, [512]] # 12 - - - [-1, 1, nn.Upsample, [None, 2, 'nearest']] - - [[-1, 4], 1, Concat, [1]] # cat backbone P3 - - [-1, 3, C2f, [256]] # 15 (P3/8-small) - - - [-1, 1, Conv, [256, 3, 2]] - - [[-1, 12], 1, Concat, [1]] # cat head P4 - - [-1, 3, C2f, [512]] # 18 (P4/16-medium) - - - [-1, 1, Conv, [512, 3, 2]] - - [[-1, 9], 1, Concat, [1]] # cat head P5 - - [-1, 3, C2f, [512]] # 21 (P5/32-large) - - - [[15, 18, 21], 1, Detect, [nc]] # Detect(P3, P4, P5) diff --git a/ultralytics/nn/tasks.py b/ultralytics/nn/tasks.py index d7af6e9a..2c03083d 100644 --- a/ultralytics/nn/tasks.py +++ b/ultralytics/nn/tasks.py @@ -170,7 +170,7 @@ class DetectionModel(BaseModel): # YOLOv8 detection model def __init__(self, cfg='yolov8n.yaml', ch=3, nc=None, verbose=True): # model, input channels, number of classes super().__init__() - self.yaml = cfg if isinstance(cfg, dict) else yaml_load(check_yaml(cfg), append_filename=True) # cfg dict + self.yaml = cfg if isinstance(cfg, dict) else yaml_model_load(cfg) # cfg dict # Define model ch = self.yaml['ch'] = self.yaml.get('ch', ch) # input channels @@ -277,7 +277,8 @@ class ClassificationModel(BaseModel): self.nc = nc def _from_yaml(self, cfg, ch, nc, verbose): - self.yaml = cfg if isinstance(cfg, dict) else yaml_load(check_yaml(cfg), append_filename=True) # cfg dict + self.yaml = cfg if isinstance(cfg, dict) else yaml_model_load(cfg) # cfg dict + # Define model ch = self.yaml['ch'] = self.yaml.get('ch', ch) # input channels if nc and nc != self.yaml['nc']: @@ -418,30 +419,42 @@ def attempt_load_one_weight(weight, device=None, inplace=True, fuse=False): def parse_model(d, ch, verbose=True): # model_dict, input_channels(3) - # Parse a YOLO model.yaml dictionary - if verbose: - LOGGER.info(f"\n{'':>3}{'from':>20}{'n':>3}{'params':>10} {'module':<45}{'arguments':<30}") - nc, gd, gw, act = d['nc'], d['depth_multiple'], d['width_multiple'], d.get('activation') + # Parse a YOLO model.yaml dictionary into a PyTorch model + import ast + + # Args + max_channels = float('inf') + nc, act, scales = (d.get(x) for x in ('nc', 'act', 'scales')) + depth, width = (d.get(x, 1.0) for x in ('depth_multiple', 'width_multiple')) + if scales: + scale = d.get('scale') + if not scale: + scale = tuple(scales.keys())[0] + LOGGER.warning(f"WARNING ⚠️ no model scale passed. Assuming scale='{scale}'.") + depth, width, max_channels = scales[scale] + if act: Conv.default_act = eval(act) # redefine default activation, i.e. Conv.default_act = nn.SiLU() if verbose: LOGGER.info(f"{colorstr('activation:')} {act}") # print + + if verbose: + LOGGER.info(f"\n{'':>3}{'from':>20}{'n':>3}{'params':>10} {'module':<45}{'arguments':<30}") ch = [ch] layers, save, c2 = [], [], ch[-1] # layers, savelist, ch out for i, (f, n, m, args) in enumerate(d['backbone'] + d['head']): # from, number, module, args m = getattr(torch.nn, m[3:]) if 'nn.' in m else globals()[m] # get module for j, a in enumerate(args): - # TODO: re-implement with eval() removal if possible - # args[j] = (locals()[a] if a in locals() else ast.literal_eval(a)) if isinstance(a, str) else a - with contextlib.suppress(NameError): - args[j] = eval(a) if isinstance(a, str) else a # eval strings + if isinstance(a, str): + with contextlib.suppress(ValueError): + args[j] = locals()[a] if a in locals() else ast.literal_eval(a) - n = n_ = max(round(n * gd), 1) if n > 1 else n # depth gain + n = n_ = max(round(n * depth), 1) if n > 1 else n # depth gain if m in (Classify, Conv, ConvTranspose, GhostConv, Bottleneck, GhostBottleneck, SPP, SPPF, DWConv, Focus, BottleneckCSP, C1, C2, C2f, C3, C3TR, C3Ghost, nn.ConvTranspose2d, DWConvTranspose2d, C3x): c1, c2 = ch[f], args[0] if c2 != nc: # if c2 not equal to number of classes (i.e. for Classify() output) - c2 = make_divisible(c2 * gw, 8) + c2 = make_divisible(min(c2, max_channels) * width, 8) args = [c1, c2, *args[1:]] if m in (BottleneckCSP, C1, C2, C2f, C3, C3TR, C3Ghost, C3x): @@ -454,7 +467,7 @@ def parse_model(d, ch, verbose=True): # model_dict, input_channels(3) elif m in (Detect, Segment): args.append([ch[x] for x in f]) if m is Segment: - args[2] = make_divisible(args[2] * gw, 8) + args[2] = make_divisible(min(args[2], max_channels) * width, 8) else: c2 = ch[f] @@ -472,6 +485,41 @@ def parse_model(d, ch, verbose=True): # model_dict, input_channels(3) return nn.Sequential(*layers), sorted(save) +def yaml_model_load(path): + import re + + path = Path(path) + if path.stem in (f'yolov{d}{x}6' for x in 'nsmlx' for d in (5, 8)): + new_stem = re.sub(r'(\d+)([nslmx])6(.+)?$', r'\1\2-p6\3', path.stem) + LOGGER.warning(f'WARNING ⚠️ Ultralytics YOLO P6 models now use -p6 suffix. Renaming {path.stem} to {new_stem}.') + path = path.with_stem(new_stem) + + unified_path = re.sub(r'(\d+)([nslmx])(.+)?$', r'\1\3', str(path)) # i.e. yolov8x.yaml -> yolov8.yaml + yaml_file = check_yaml(unified_path, hard=False) or check_yaml(path) + d = yaml_load(yaml_file) # model dict + d['scale'] = guess_model_scale(path) + d['yaml_file'] = str(path) + return d + + +def guess_model_scale(model_path): + """ + Takes a path to a YOLO model's YAML file as input and extracts the size character of the model's scale. + The function uses regular expression matching to find the pattern of the model scale in the YAML file name, + which is denoted by n, s, m, l, or x. The function returns the size character of the model scale as a string. + + Args: + model_path (str or Path): The path to the YOLO model's YAML file. + + Returns: + (str): The size character of the model's scale, which can be n, s, m, l, or x. + """ + with contextlib.suppress(AttributeError): + import re + return re.search(r'yolov\d+([nslmx])', Path(model_path).stem).group(1) # n, s, m, l, or x + return '' + + def guess_model_task(model): """ Guess the task of a PyTorch model from its architecture or configuration. diff --git a/ultralytics/yolo/data/dataset.py b/ultralytics/yolo/data/dataset.py index 80fe24be..24128820 100644 --- a/ultralytics/yolo/data/dataset.py +++ b/ultralytics/yolo/data/dataset.py @@ -17,7 +17,7 @@ from .utils import HELP_URL, LOCAL_RANK, LOGGER, get_hash, img2label_paths, veri class YOLODataset(BaseDataset): - cache_version = '1.0.1' # dataset labels *.cache version, >= 1.0.0 for YOLOv8 + cache_version = '1.0.2' # dataset labels *.cache version, >= 1.0.0 for YOLOv8 rand_interp_methods = [cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_LANCZOS4] """ Dataset class for loading images object detection and/or segmentation labels in YOLO format. diff --git a/ultralytics/yolo/engine/exporter.py b/ultralytics/yolo/engine/exporter.py index 1943c84d..a77c08e5 100644 --- a/ultralytics/yolo/engine/exporter.py +++ b/ultralytics/yolo/engine/exporter.py @@ -245,8 +245,7 @@ class Exporter: if tflite: f[7], _ = self._export_tflite(s_model, nms=False, agnostic_nms=self.args.agnostic_nms) if edgetpu: - f[8], _ = self._export_edgetpu(tflite_model=str( - Path(f[5]) / (self.file.stem + '_full_integer_quant.tflite'))) # int8 in/out + f[8], _ = self._export_edgetpu(tflite_model=Path(f[5]) / f'{self.file.stem}_full_integer_quant.tflite') if tfjs: f[9], _ = self._export_tfjs() if paddle: # PaddlePaddle @@ -532,9 +531,16 @@ class Exporter: subprocess.run(cmd, shell=True) yaml_save(f / 'metadata.yaml', self.metadata) # add metadata.yaml + # Remove/rename TFLite models + if self.args.int8: + for file in f.rglob('*_dynamic_range_quant.tflite'): + file.rename(file.with_stem(file.stem.replace('_dynamic_range_quant', '_int8'))) + for file in f.rglob('*_integer_quant_with_int16_act.tflite'): + file.unlink() # delete extra fp16 activation TFLite files + # Add TFLite metadata for file in f.rglob('*.tflite'): - self._add_tflite_metadata(file) + f.unlink() if 'quant_with_int16_act.tflite' in str(f) else self._add_tflite_metadata(file) # Load saved_model keras_model = tf.saved_model.load(f, tags=None, options=None) @@ -565,9 +571,9 @@ class Exporter: LOGGER.info(f'\n{prefix} starting export with tensorflow {tf.__version__}...') saved_model = Path(str(self.file).replace(self.file.suffix, '_saved_model')) if self.args.int8: - f = saved_model / f'{self.file.stem}_integer_quant.tflite' # fp32 in/out + f = saved_model / f'{self.file.stem}_int8.tflite' # fp32 in/out elif self.args.half: - f = saved_model / f'{self.file.stem}_float16.tflite' + f = saved_model / f'{self.file.stem}_float16.tflite' # fp32 in/out else: f = saved_model / f'{self.file.stem}_float32.tflite' return str(f), None diff --git a/ultralytics/yolo/engine/model.py b/ultralytics/yolo/engine/model.py index df46056f..fb85e374 100644 --- a/ultralytics/yolo/engine/model.py +++ b/ultralytics/yolo/engine/model.py @@ -5,7 +5,7 @@ from pathlib import Path from ultralytics import yolo # noqa from ultralytics.nn.tasks import (ClassificationModel, DetectionModel, SegmentationModel, attempt_load_one_weight, - guess_model_task, nn) + guess_model_task, nn, yaml_model_load) from ultralytics.yolo.cfg import get_cfg from ultralytics.yolo.engine.exporter import Exporter from ultralytics.yolo.utils import (DEFAULT_CFG, DEFAULT_CFG_DICT, DEFAULT_CFG_KEYS, LOGGER, RANK, ROOT, callbacks, @@ -111,8 +111,8 @@ class YOLO: task (str) or (None): model task verbose (bool): display model info on load """ - self.cfg = check_yaml(cfg) # check YAML - cfg_dict = yaml_load(self.cfg, append_filename=True) # model dict + cfg_dict = yaml_model_load(cfg) + self.cfg = cfg self.task = task or guess_model_task(cfg_dict) self.model = TASK_MAP[self.task][0](cfg_dict, verbose=verbose and RANK == -1) # build model self.overrides['model'] = self.cfg diff --git a/ultralytics/yolo/utils/checks.py b/ultralytics/yolo/utils/checks.py index 06aaf72d..d1362468 100644 --- a/ultralytics/yolo/utils/checks.py +++ b/ultralytics/yolo/utils/checks.py @@ -248,9 +248,9 @@ def check_yolov5u_filename(file: str, verbose: bool = True): # Replace legacy YOLOv5 filenames with updated YOLOv5u filenames if ('yolov3' in file or 'yolov5' in file) and 'u' not in file: original_file = file - file = re.sub(r'(.*yolov5([nsmlx]))\.', '\\1u.', file) # i.e. yolov5n.pt -> yolov5nu.pt - file = re.sub(r'(.*yolov5([nsmlx])6)\.', '\\1u.', file) # i.e. yolov5n6.pt -> yolov5n6u.pt - file = re.sub(r'(.*yolov3(|-tiny|-spp))\.', '\\1u.', file) # i.e. yolov3-spp.pt -> yolov3-sppu.pt + file = re.sub(r'(.*yolov5([nsmlx]))\.pt', '\\1u.pt', file) # i.e. yolov5n.pt -> yolov5nu.pt + file = re.sub(r'(.*yolov5([nsmlx])6)\.pt', '\\1u.pt', file) # i.e. yolov5n6.pt -> yolov5n6u.pt + file = re.sub(r'(.*yolov3(|-tiny|-spp))\.pt', '\\1u.pt', file) # i.e. yolov3-spp.pt -> yolov3-sppu.pt if file != original_file and verbose: LOGGER.info(f"PRO TIP 💡 Replace 'model={original_file}' with new 'model={file}'.\nYOLOv5 'u' models are " f'trained with https://github.com/ultralytics/ultralytics and feature improved performance vs ' @@ -258,7 +258,7 @@ def check_yolov5u_filename(file: str, verbose: bool = True): return file -def check_file(file, suffix='', download=True): +def check_file(file, suffix='', download=True, hard=True): # Search/download file (if necessary) and return path check_suffix(file, suffix) # optional file = str(file) # convert to string @@ -277,16 +277,16 @@ def check_file(file, suffix='', download=True): files = [] for d in 'models', 'datasets', 'tracker/cfg', 'yolo/cfg': # search directories files.extend(glob.glob(str(ROOT / d / '**' / file), recursive=True)) # find file - if not files: + if not files and hard: raise FileNotFoundError(f"'{file}' does not exist") - elif len(files) > 1: + elif len(files) > 1 and hard: raise FileNotFoundError(f"Multiple files match '{file}', specify exact path: {files}") - return files[0] # return file + return files[0] if len(files) else [] # return file -def check_yaml(file, suffix=('.yaml', '.yml')): +def check_yaml(file, suffix=('.yaml', '.yml'), hard=True): # Search/download YAML file (if necessary) and return path, checking suffix - return check_file(file, suffix) + return check_file(file, suffix, hard=hard) def check_imshow(warn=False): diff --git a/ultralytics/yolo/v8/detect/predict.py b/ultralytics/yolo/v8/detect/predict.py index 7c38674f..4df94b1b 100644 --- a/ultralytics/yolo/v8/detect/predict.py +++ b/ultralytics/yolo/v8/detect/predict.py @@ -63,13 +63,12 @@ class DetectionPredictor(BasePredictor): # write for d in reversed(det): - cls, conf, id = d.cls.squeeze(), d.conf.squeeze(), None if d.id is None else int(d.id.item()) + c, conf, id = int(d.cls), float(d.conf), None if d.id is None else int(d.id.item()) if self.args.save_txt: # Write to file - line = (cls, *d.xywhn.view(-1)) + (conf, ) * self.args.save_conf + (() if id is None else (id, )) + line = (c, *d.xywhn.view(-1)) + (conf, ) * self.args.save_conf + (() if id is None else (id, )) with open(f'{self.txt_path}.txt', 'a') as f: f.write(('%g ' * len(line)).rstrip() % line + '\n') - if self.args.save or self.args.save_crop or self.args.show: # Add bbox to image - c = int(cls) # integer class + if self.args.save or self.args.show: # Add bbox to image name = ('' if id is None else f'id:{id} ') + self.model.names[c] label = None if self.args.hide_labels else (name if self.args.hide_conf else f'{name} {conf:.2f}') self.annotator.box_label(d.xyxy.squeeze(), label, color=colors(c, True)) diff --git a/ultralytics/yolo/v8/segment/predict.py b/ultralytics/yolo/v8/segment/predict.py index 82fc47f0..90211c10 100644 --- a/ultralytics/yolo/v8/segment/predict.py +++ b/ultralytics/yolo/v8/segment/predict.py @@ -76,17 +76,17 @@ class SegmentationPredictor(DetectionPredictor): # Write results for j, d in enumerate(reversed(det)): - cls, conf, id = d.cls.squeeze(), d.conf.squeeze(), None if d.id is None else int(d.id.item()) + c, conf, id = int(d.cls), float(d.conf), None if d.id is None else int(d.id.item()) if self.args.save_txt: # Write to file seg = mask.segments[len(det) - j - 1].copy().reshape(-1) # reversed mask.segments, (n,2) to (n*2) - line = (cls, *seg) + (conf, ) * self.args.save_conf + (() if id is None else (id, )) + line = (c, *seg) + (conf, ) * self.args.save_conf + (() if id is None else (id, )) with open(f'{self.txt_path}.txt', 'a') as f: f.write(('%g ' * len(line)).rstrip() % line + '\n') - if self.args.save or self.args.save_crop or self.args.show: # Add bbox to image - c = int(cls) # integer class + if self.args.save or self.args.show: # Add bbox to image name = ('' if id is None else f'id:{id} ') + self.model.names[c] label = None if self.args.hide_labels else (name if self.args.hide_conf else f'{name} {conf:.2f}') - self.annotator.box_label(d.xyxy.squeeze(), label, color=colors(c, True)) if self.args.boxes else None + if self.args.boxes: + self.annotator.box_label(d.xyxy.squeeze(), label, color=colors(c, True)) if self.args.save_crop: save_one_box(d.xyxy, imc, diff --git a/ultralytics/yolo/v8/segment/train.py b/ultralytics/yolo/v8/segment/train.py index 5a4c5b20..3cc64664 100644 --- a/ultralytics/yolo/v8/segment/train.py +++ b/ultralytics/yolo/v8/segment/train.py @@ -122,13 +122,15 @@ class SegLoss(Loss): xyxyn = target_bboxes[i][fg_mask[i]] / imgsz[[1, 0, 1, 0]] marea = xyxy2xywh(xyxyn)[:, 2:].prod(1) mxyxy = xyxyn * torch.tensor([mask_w, mask_h, mask_w, mask_h], device=self.device) - loss[1] += self.single_mask_loss(gt_mask, pred_masks[i][fg_mask[i]], proto[i], mxyxy, - marea) # seg loss - # WARNING: Uncomment lines below in case of Multi-GPU DDP unused gradient errors - # else: - # loss[1] += proto.sum() * 0 + pred_masks.sum() * 0 - # else: - # loss[1] += proto.sum() * 0 + pred_masks.sum() * 0 + loss[1] += self.single_mask_loss(gt_mask, pred_masks[i][fg_mask[i]], proto[i], mxyxy, marea) # seg + + # WARNING: lines below prevents Multi-GPU DDP 'unused gradient' PyTorch errors, do not remove + else: + loss[1] += proto.sum() * 0 + pred_masks.sum() * 0 + + # WARNING: lines below prevent Multi-GPU DDP 'unused gradient' PyTorch errors, do not remove + else: + loss[1] += proto.sum() * 0 + pred_masks.sum() * 0 loss[0] *= self.hyp.box # box gain loss[1] *= self.hyp.box / batch_size # seg gain