[Docs]: Add customization tutorial and address feedback (#155)
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
14
docs/cli.md
14
docs/cli.md
@ -3,10 +3,10 @@ If you want to train, validate or run inference on models and don't need to make
|
||||
|
||||
!!! tip "Syntax"
|
||||
```bash
|
||||
yolo task=detect mode=train model=s.yaml epochs=1 ...
|
||||
yolo task=detect mode=train model=yolov8n.yaml epochs=1 ...
|
||||
... ... ...
|
||||
segment infer s-cls.pt
|
||||
classify val s-seg.pt
|
||||
segment predict yolov8n-seg.pt
|
||||
classify val yolov8n-cls.pt
|
||||
```
|
||||
|
||||
The experiment arguments can be overridden directly by pass `arg=val` covered in the next section. You can run any supported task by setting `task` and `mode` in cli.
|
||||
@ -18,13 +18,13 @@ The experiment arguments can be overridden directly by pass `arg=val` covered in
|
||||
| Instance Segment | `segment` | <pre><code>yolo task=segment mode=train </code></pre> |
|
||||
| Classification| `classify` | <pre><code>yolo task=classify mode=train </code></pre> |
|
||||
|
||||
=== "Inference"
|
||||
=== "Prediction"
|
||||
|
||||
| | `task` | snippet |
|
||||
| ----------- | ------------- | ------------------------------------------------------------ |
|
||||
| Detection | `detect` | <pre><code>yolo task=detect mode=infer </code></pre> |
|
||||
| Instance Segment | `segment` | <pre><code>yolo task=segment mode=infer </code></pre>|
|
||||
| Classification| `classify` | <pre><code>yolo task=classify mode=infer </code></pre>|
|
||||
| Detection | `detect` | <pre><code>yolo task=detect mode=predict </code></pre> |
|
||||
| Instance Segment | `segment` | <pre><code>yolo task=segment mode=predict </code></pre>|
|
||||
| Classification| `classify` | <pre><code>yolo task=classify mode=predict </code></pre>|
|
||||
|
||||
=== "Validation"
|
||||
|
||||
|
@ -46,7 +46,7 @@ include train, val, and predict.
|
||||
| model | null | Set the model. Format can differ for task type. Supports `model_name`, `model.yaml` & `model.pt` |
|
||||
| data | null | Set the data. Format can differ for task type. Supports `data.yaml`, `data_folder`, `dataset_name` |
|
||||
|
||||
### Training settings
|
||||
### Training
|
||||
|
||||
Training settings for YOLO models refer to the various hyperparameters and configurations used to train the model on a
|
||||
dataset. These settings can affect the model's performance, speed, and accuracy. Some common YOLO training settings
|
||||
@ -88,7 +88,7 @@ task.
|
||||
| mask_ratio | 4 | **Segmentation**: Set mask downsampling |
|
||||
| dropout | `False` | **Classification**: Use dropout while training |
|
||||
|
||||
### Prediction Settings
|
||||
### Prediction
|
||||
|
||||
Prediction settings for YOLO models refer to the various hyperparameters and configurations used to make predictions
|
||||
with the model on new data. These settings can affect the model's performance, speed, and accuracy. Some common YOLO
|
||||
@ -114,7 +114,7 @@ given task.
|
||||
| agnostic_nms | `False` | Class-agnostic NMS |
|
||||
| retina_masks | `False` | **Segmentation:** High resolution masks |
|
||||
|
||||
### Validation settings
|
||||
### Validation
|
||||
|
||||
Validation settings for YOLO models refer to the various hyperparameters and configurations used to
|
||||
evaluate the model's performance on a validation dataset. These settings can affect the model's performance, speed, and
|
||||
@ -147,7 +147,7 @@ the specific task the model is being used for and the requirements or constraint
|
||||
It is important to carefully consider and configure these settings to ensure that the exported model is optimized for
|
||||
the intended use case and can be used effectively in the target environment.
|
||||
|
||||
### Augmentation settings
|
||||
### Augmentation
|
||||
|
||||
Augmentation settings for YOLO models refer to the various transformations and modifications
|
||||
applied to the training data to increase the diversity and size of the dataset. These settings can affect the model's
|
||||
|
66
docs/engine.md
Normal file
66
docs/engine.md
Normal file
@ -0,0 +1,66 @@
|
||||
Both the Ultralytics YOLO command-line and python interfaces are simply a high-level abstraction on the base engine executors. Let's take a look at the Trainer engine.
|
||||
|
||||
## BaseTrainer
|
||||
BaseTrainer contains the generic boilerplate training routine. It can be customized for any task based over overidding the required functions or operations as long the as correct formats are followed. For example you can support your own custom model and dataloder by just overriding these functions:
|
||||
|
||||
* `get_model(cfg, weights)` - The function that builds a the model to be trained
|
||||
* `get_dataloder()` - The function that builds the dataloder
|
||||
More details and source code can be found in [`BaseTrainer` Reference](../reference/base_trainer.md)
|
||||
|
||||
## DetectionTrainer
|
||||
Here's how you can use the YOLOv8 `DetectionTrainer` and customize it.
|
||||
```python
|
||||
from Ultrlaytics.yolo.v8 import DetectionTrainer
|
||||
|
||||
trainer = DetectionTrainer(overrides={...})
|
||||
trainer.train()
|
||||
trained_model = trainer.best # get best model
|
||||
```
|
||||
|
||||
### Customizing the DetectionTrainer
|
||||
Let's customize the trainer **to train a custom detection model** that is not supported directly. You can do this by simply overloading the existing the `get_model` functionality:
|
||||
```python
|
||||
from Ultrlaytics.yolo.v8 import DetectionTrainer
|
||||
|
||||
class CustomTrainer(DetectionTrainer):
|
||||
def get_model(self, cfg, weights):
|
||||
...
|
||||
|
||||
trainer = CustomTrainer(overrides={...})
|
||||
trainer.train()
|
||||
```
|
||||
You now realize that you need to customize the trainer further to:
|
||||
|
||||
* Customize the `loss function`.
|
||||
* Add `callback` that uploads model to your google drive after every 10 `epochs`
|
||||
Here's how you can do it:
|
||||
|
||||
```python
|
||||
from Ultrlaytics.yolo.v8 import DetectionTrainer
|
||||
|
||||
class CustomTrainer(DetectionTrainer):
|
||||
def get_model(self, cfg, weights):
|
||||
...
|
||||
|
||||
def criterion(self, preds, batch):
|
||||
# get ground truth
|
||||
imgs = batch["imgs"]
|
||||
bboxes = batch["bboxes"]
|
||||
...
|
||||
return loss, loss_items # see Reference-> Trainer for details on the expected format
|
||||
|
||||
# callback to upload model weights
|
||||
def log_model(trainer):
|
||||
last_weight_path = trainer.last
|
||||
...
|
||||
|
||||
trainer = CustomTrainer(overrides={...})
|
||||
trainer.add_callback("on_train_epoch_end", log_model) # Adds to existing callback
|
||||
trainer.train()
|
||||
```
|
||||
|
||||
To know more about Callback triggering events and entry point, checkout our Callbacks guide # TODO
|
||||
|
||||
## Other engine components
|
||||
There are other componenets that can be customized similarly like `Validators` and `Predictiors`
|
||||
To know more about their implementation details, go to Reference
|
@ -49,7 +49,7 @@ For more information about the history and development of YOLO, you can refer to
|
||||
conference on computer vision and pattern recognition (pp. 779-788).
|
||||
- Redmon, J., & Farhadi, A. (2016). YOLO9000: Better, faster, stronger. In Proceedings
|
||||
|
||||
### YOLOv8 by Ultralytics
|
||||
### Ultralytics YOLOv8
|
||||
|
||||
YOLOv8 is the latest version of the YOLO object detection and image segmentation model developed by
|
||||
Ultralytics. YOLOv8 is a cutting-edge, state-of-the-art (SOTA) model that builds upon the success of previous YOLO
|
||||
|
52
docs/sdk.md
52
docs/sdk.md
@ -56,42 +56,36 @@ This is the simplest way of simply using yolo models in a python environment. It
|
||||
|
||||
More functionality coming soon
|
||||
|
||||
To know more about using `YOLO` models, refer Model class refernce
|
||||
To know more about using `YOLO` models, refer Model class Reference
|
||||
|
||||
[Model reference](reference/model.md){ .md-button .md-button--primary}
|
||||
|
||||
---
|
||||
### Customizing Tasks with Trainers
|
||||
### Using Trainers
|
||||
`YOLO` model class is a high-level wrapper on the Trainer classes. Each YOLO task has its own trainer that inherits from `BaseTrainer`.
|
||||
You can easily cusotmize Trainers to support custom tasks or explore R&D ideas.
|
||||
|
||||
!!! tip "Trainer Examples"
|
||||
=== "DetectionTrainer"
|
||||
!!! tip "Detection Trainer Example"
|
||||
```python
|
||||
from ultralytics import yolo
|
||||
from ultralytics.yolo import v8 import DetectionTrainer, DetectionValidator, DetectionPredictor
|
||||
|
||||
trainer = yolo.DetectionTrainer(data=..., epochs=1) # override default configs
|
||||
trainer = yolo.DetectionTrainer(data=..., epochs=1, device="1,2,3,4") # DDP
|
||||
# trainer
|
||||
trainer = DetectionTrainer(overrides={})
|
||||
trainer.train()
|
||||
trained_model = trainer.best
|
||||
|
||||
# Validator
|
||||
val = DetectionValidator(args=...)
|
||||
val(model=trained_model)
|
||||
|
||||
# predictor
|
||||
pred = DetectionPredictor(overrides={})
|
||||
pred(source=SOURCE, model=trained_model)
|
||||
|
||||
# resume from last weight
|
||||
overrides["resume"] = trainer.last
|
||||
trainer = detect.DetectionTrainer(overrides=overrides)
|
||||
|
||||
```
|
||||
You can easily customize Trainers to support custom tasks or explore R&D ideas.
|
||||
Learn more about Customizing `Trainers`, `Validators` and `Predictors` to suit your project needs in the Customization Section.
|
||||
|
||||
=== "SegmentationTrainer"
|
||||
```python
|
||||
from ultralytics import yolo
|
||||
|
||||
trainer = yolo.SegmentationTrainer(data=..., epochs=1) # override default configs
|
||||
trainer = yolo.SegmentationTrainer(data=..., epochs=1, device="0,1,2,3") # DDP
|
||||
trainer.train()
|
||||
```
|
||||
=== "ClassificationTrainer"
|
||||
```python
|
||||
from ultralytics import yolo
|
||||
|
||||
trainer = yolo.ClassificationTrainer(data=..., epochs=1) # override default configs
|
||||
trainer = yolo.ClassificationTrainer(data=..., epochs=1, device="0,1,2,3") # DDP
|
||||
trainer.train()
|
||||
```
|
||||
|
||||
Learn more about Customizing `Trainers`, `Validators` and `Predictors` to suit your project needs in the Customization Section. More details about the base engine classes is available in the reference section.
|
||||
|
||||
[Customization tutorials](#){ .md-button .md-button--primary}
|
||||
[Customization tutorials](engine.md){ .md-button .md-button--primary}
|
||||
|
Reference in New Issue
Block a user