Release 8.0.5 PR (#279)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
Co-authored-by: Izam Mohammed <106471909+izam-mohammed@users.noreply.github.com>
Co-authored-by: Yue WANG 王跃 <92371174+yuewangg@users.noreply.github.com>
Co-authored-by: Thibaut Lucas <thibautlucas13@gmail.com>
This commit is contained in:
Laughing 2023-01-13 00:09:26 +08:00 committed by GitHub
parent 9552827157
commit c42e44a021
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 940 additions and 311 deletions

View file

@ -1,42 +1,55 @@
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.
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
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 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)
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 ultralytics.yolo.v8 import DetectionTrainer
from ultralytics.yolo.v8.detect import DetectionTrainer
trainer = DetectionTrainer(overrides={...})
trainer.train()
trained_model = trainer.best # get best model
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:
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 ultralytics.yolo.v8 import DetectionTrainer
from ultralytics.yolo.v8.detect 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:
* 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 ultralytics.yolo.v8 import DetectionTrainer
from ultralytics.yolo.v8.detect import DetectionTrainer
class CustomTrainer(DetectionTrainer):
def get_model(self, cfg, weights):
@ -47,20 +60,24 @@ class CustomTrainer(DetectionTrainer):
imgs = batch["imgs"]
bboxes = batch["bboxes"]
...
return loss, loss_items # see Reference-> Trainer for details on the expected format
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.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
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
There are other componenets that can be customized similarly like `Validators` and `Predictors`
See Reference section for more information on these.