Enable comments and add cloning instruction to Model YAML configuration guide (#22154)

Signed-off-by: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
Mohammed Yasin 2025-09-22 01:34:41 +08:00 committed by GitHub
parent 544480358b
commit 3a92d90e5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 9 deletions

View File

@ -1,10 +1,10 @@
---
title: Model YAML Configuration Guide
comments: true
description: Learn how to structure and customize model architectures using Ultralytics YAML configuration files. Master module definitions, connections, and scaling parameters.
keywords: Ultralytics, YOLO, model architecture, YAML configuration, neural networks, deep learning, backbone, head, modules, custom models
---
# Model YAML Configuration
# Model YAML Configuration Guide
The model YAML configuration file serves as the architectural blueprint for Ultralytics neural networks. It defines how layers connect, what parameters each module uses, and how the entire network scales across different model sizes.
@ -229,7 +229,9 @@ from ultralytics.nn.modules import ( # noqa: F401, E501
Modifying the source code is the most versatile way to integrate your custom modules, but it can be tricky. To define and use a custom module, follow these steps:
1. **Define your module** in [`ultralytics/nn/modules/block.py`](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/modules/block.py):
1. **Install Ultralytics in development mode** using the Git clone method from the [Quickstart guide](https://docs.ultralytics.com/quickstart#git-clone).
2. **Define your module** in [`ultralytics/nn/modules/block.py`](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/modules/block.py):
```python
class CustomBlock(nn.Module):
@ -241,19 +243,19 @@ Modifying the source code is the most versatile way to integrate your custom mod
return self.layers(x)
```
2. **Expose your module at the package level** in [`ultralytics/nn/modules/__init__.py`](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/modules/__init__.py):
3. **Expose your module at the package level** in [`ultralytics/nn/modules/__init__.py`](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/modules/__init__.py):
```python
from .block import CustomBlock # noqa makes CustomBlock available as ultralytics.nn.modules.CustomBlock
```
3. **Add to imports** in [`ultralytics/nn/tasks.py`](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/tasks.py):
4. **Add to imports** in [`ultralytics/nn/tasks.py`](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/tasks.py):
```python
from ultralytics.nn.modules import CustomBlock # noqa
```
4. **Handle special arguments** (if needed) inside [`parse_model()`](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/tasks.py) in `ultralytics/nn/tasks.py`:
5. **Handle special arguments** (if needed) inside [`parse_model()`](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/nn/tasks.py) in `ultralytics/nn/tasks.py`:
```python
elif m is CustomBlock:
@ -261,7 +263,7 @@ Modifying the source code is the most versatile way to integrate your custom mod
args = [c1, c2, *args[1:]]
```
5. **Use the module** in your model YAML:
6. **Use the module** in your model YAML:
```yaml
# custom_model.yaml
@ -272,7 +274,7 @@ Modifying the source code is the most versatile way to integrate your custom mod
- [-1, 1, Classify, [nc]]
```
6. **Check FLOPs** to ensure the forward pass works:
7. **Check FLOPs** to ensure the forward pass works:
```python
from ultralytics import YOLO

View File

@ -399,6 +399,7 @@ nav:
- YOLO Thread-Safe Inference: guides/yolo-thread-safe-inference.md
- YOLO Data Augmentation: guides/yolo-data-augmentation.md
- Model Deployment Options: guides/model-deployment-options.md
- Model YAML Configuration Guide: guides/model-yaml-config.md
- K-Fold Cross Validation: guides/kfold-cross-validation.md
- Hyperparameter Tuning: guides/hyperparameter-tuning.md
- SAHI Tiled Inference: guides/sahi-tiled-inference.md
@ -424,7 +425,6 @@ nav:
- Best Practices for Model Deployment: guides/model-deployment-practices.md
- Maintaining Your Computer Vision Model: guides/model-monitoring-and-maintenance.md
- Deploying YOLO on Vertex AI in Docker container: guides/vertex-ai-deployment-with-docker.md
- Model YAML Configuration Guide: guides/model-yaml-config.md
- Explorer:
- datasets/explorer/index.md
- Explorer API: datasets/explorer/api.md