ultralytics 8.0.59
new MLFlow and feature updates (#1720)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: St. HeMeow <sheng.heyang@gmail.com> Co-authored-by: Danny Kim <imbird0312@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Torge Kummerow <CySlider@users.noreply.github.com> Co-authored-by: dankernel <dkdkernel@gmail.com> Co-authored-by: Burhan <62214284+Burhan-Q@users.noreply.github.com> Co-authored-by: Roshanlal <roshanlaladchitre103@gmail.com> Co-authored-by: Lorenzo Mammana <lorenzo.mammana@orobix.com> Co-authored-by: Yonghye Kwon <developer.0hye@gmail.com>
This commit is contained in:
@ -152,7 +152,8 @@ operations are cached, meaning they're only calculated once per object, and thos
|
||||
```python
|
||||
results = model(inputs)
|
||||
masks = results[0].masks # Masks object
|
||||
masks.segments # bounding coordinates of masks, List[segment] * N
|
||||
masks.xy # x, y segments (pixels), List[segment] * N
|
||||
masks.xyn # x, y segments (normalized), List[segment] * N
|
||||
masks.data # raw masks tensor, (N, H, W) or masks.masks
|
||||
```
|
||||
|
||||
@ -185,3 +186,47 @@ masks, classification logits, etc.) found in the results object
|
||||
- `show_conf (bool)`: Show confidence
|
||||
- `line_width (Float)`: The line width of boxes. Automatically scaled to img size if not provided
|
||||
- `font_size (Float)`: The font size of . Automatically scaled to img size if not provided
|
||||
|
||||
## Streaming Source `for`-loop
|
||||
|
||||
Here's a Python script using OpenCV (cv2) and YOLOv8 to run inference on video frames. This script assumes you have already installed the necessary packages (opencv-python and ultralytics).
|
||||
|
||||
!!! example "Streaming for-loop"
|
||||
|
||||
```python
|
||||
import cv2
|
||||
from ultralytics import YOLO
|
||||
|
||||
# Load the YOLOv8 model
|
||||
model = YOLO('yolov8n.pt')
|
||||
|
||||
# Open the video file
|
||||
video_path = "path/to/your/video/file.mp4"
|
||||
cap = cv2.VideoCapture(video_path)
|
||||
|
||||
# Loop through the video frames
|
||||
while cap.isOpened():
|
||||
# Read a frame from the video
|
||||
success, frame = cap.read()
|
||||
|
||||
if success:
|
||||
# Run YOLOv8 inference on the frame
|
||||
results = model(frame)
|
||||
|
||||
# Visualize the results on the frame
|
||||
annotated_frame = results[0].plot()
|
||||
|
||||
# Display the annotated frame
|
||||
cv2.imshow("YOLOv8 Inference", annotated_frame)
|
||||
|
||||
# Break the loop if 'q' is pressed
|
||||
if cv2.waitKey(1) & 0xFF == ord("q"):
|
||||
break
|
||||
else:
|
||||
# Break the loop if the end of the video is reached
|
||||
break
|
||||
|
||||
# Release the video capture object and close the display window
|
||||
cap.release()
|
||||
cv2.destroyAllWindows()
|
||||
```
|
@ -73,7 +73,7 @@ task.
|
||||
| `deterministic` | `True` | whether to enable deterministic mode |
|
||||
| `single_cls` | `False` | train multi-class data as single-class |
|
||||
| `image_weights` | `False` | use weighted image selection for training |
|
||||
| `rect` | `False` | support rectangular training |
|
||||
| `rect` | `False` | rectangular training with each batch collated for minimum padding |
|
||||
| `cos_lr` | `False` | use cosine learning rate scheduler |
|
||||
| `close_mosaic` | `10` | disable mosaic augmentation for final 10 epochs |
|
||||
| `resume` | `False` | resume training from last checkpoint |
|
||||
|
@ -62,7 +62,7 @@ validation dataset and to detect and prevent overfitting.
|
||||
| `device` | `None` | device to run on, i.e. cuda device=0/1/2/3 or device=cpu |
|
||||
| `dnn` | `False` | use OpenCV DNN for ONNX inference |
|
||||
| `plots` | `False` | show plots during training |
|
||||
| `rect` | `False` | support rectangular evaluation |
|
||||
| `rect` | `False` | rectangular val with each batch collated for minimum padding |
|
||||
| `split` | `val` | dataset split to use for validation, i.e. 'val', 'test' or 'train' |
|
||||
|
||||
## Export Formats
|
||||
|
@ -12,75 +12,74 @@ In this example, we want to return the original frame with each result object. H
|
||||
|
||||
```python
|
||||
def on_predict_batch_end(predictor):
|
||||
# results -> List[batch_size]
|
||||
# Retrieve the batch data
|
||||
_, _, im0s, _, _ = predictor.batch
|
||||
|
||||
# Ensure that im0s is a list
|
||||
im0s = im0s if isinstance(im0s, list) else [im0s]
|
||||
|
||||
# Combine the prediction results with the corresponding frames
|
||||
predictor.results = zip(predictor.results, im0s)
|
||||
|
||||
# Create a YOLO model instance
|
||||
model = YOLO(f'yolov8n.pt')
|
||||
|
||||
# Add the custom callback to the model
|
||||
model.add_callback("on_predict_batch_end", on_predict_batch_end)
|
||||
|
||||
# Iterate through the results and frames
|
||||
for (result, frame) in model.track/predict():
|
||||
pass
|
||||
```
|
||||
|
||||
## All callbacks
|
||||
|
||||
Here are all supported callbacks.
|
||||
Here are all supported callbacks. See callbacks [source code](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/yolo/utils/callbacks/base.py) for additional details.
|
||||
|
||||
### Trainer
|
||||
|
||||
`on_pretrain_routine_start`
|
||||
### Trainer Callbacks
|
||||
|
||||
`on_pretrain_routine_end`
|
||||
| Callback | Description |
|
||||
|-----------------------------|---------------------------------------------------------|
|
||||
| `on_pretrain_routine_start` | Triggered at the beginning of pre-training routine |
|
||||
| `on_pretrain_routine_end` | Triggered at the end of pre-training routine |
|
||||
| `on_train_start` | Triggered when the training starts |
|
||||
| `on_train_epoch_start` | Triggered at the start of each training epoch |
|
||||
| `on_train_batch_start` | Triggered at the start of each training batch |
|
||||
| `optimizer_step` | Triggered during the optimizer step |
|
||||
| `on_before_zero_grad` | Triggered before gradients are zeroed |
|
||||
| `on_train_batch_end` | Triggered at the end of each training batch |
|
||||
| `on_train_epoch_end` | Triggered at the end of each training epoch |
|
||||
| `on_fit_epoch_end` | Triggered at the end of each fit epoch |
|
||||
| `on_model_save` | Triggered when the model is saved |
|
||||
| `on_train_end` | Triggered when the training process ends |
|
||||
| `on_params_update` | Triggered when model parameters are updated |
|
||||
| `teardown` | Triggered when the training process is being cleaned up |
|
||||
|
||||
`on_train_start`
|
||||
|
||||
`on_train_epoch_start`
|
||||
### Validator Callbacks
|
||||
|
||||
`on_train_batch_start`
|
||||
| Callback | Description |
|
||||
|----------------------|-------------------------------------------------|
|
||||
| `on_val_start` | Triggered when the validation starts |
|
||||
| `on_val_batch_start` | Triggered at the start of each validation batch |
|
||||
| `on_val_batch_end` | Triggered at the end of each validation batch |
|
||||
| `on_val_end` | Triggered when the validation ends |
|
||||
|
||||
`optimizer_step`
|
||||
|
||||
`on_before_zero_grad`
|
||||
### Predictor Callbacks
|
||||
|
||||
`on_train_batch_end`
|
||||
| Callback | Description |
|
||||
|------------------------------|---------------------------------------------------|
|
||||
| `on_predict_start` | Triggered when the prediction process starts |
|
||||
| `on_predict_batch_start` | Triggered at the start of each prediction batch |
|
||||
| `on_predict_postprocess_end` | Triggered at the end of prediction postprocessing |
|
||||
| `on_predict_batch_end` | Triggered at the end of each prediction batch |
|
||||
| `on_predict_end` | Triggered when the prediction process ends |
|
||||
|
||||
`on_train_epoch_end`
|
||||
### Exporter Callbacks
|
||||
|
||||
`on_fit_epoch_end`
|
||||
|
||||
`on_model_save`
|
||||
|
||||
`on_train_end`
|
||||
|
||||
`on_params_update`
|
||||
|
||||
`teardown`
|
||||
|
||||
### Validator
|
||||
|
||||
`on_val_start`
|
||||
|
||||
`on_val_batch_start`
|
||||
|
||||
`on_val_batch_end`
|
||||
|
||||
`on_val_end`
|
||||
|
||||
### Predictor
|
||||
|
||||
`on_predict_start`
|
||||
|
||||
`on_predict_batch_start`
|
||||
|
||||
`on_predict_postprocess_end`
|
||||
|
||||
`on_predict_batch_end`
|
||||
|
||||
`on_predict_end`
|
||||
|
||||
### Exporter
|
||||
|
||||
`on_export_start`
|
||||
|
||||
`on_export_end`
|
||||
| Callback | Description |
|
||||
|-------------------|------------------------------------------|
|
||||
| `on_export_start` | Triggered when the export process starts |
|
||||
| `on_export_end` | Triggered when the export process ends |
|
||||
|
@ -12,6 +12,18 @@ YOLOv8 'yolo' CLI commands use the following syntax:
|
||||
yolo TASK MODE ARGS
|
||||
```
|
||||
|
||||
=== "Python"
|
||||
|
||||
```python
|
||||
from ultralytics import YOLO
|
||||
|
||||
# Load a YOLOv8 model from a pre-trained weights file
|
||||
model = YOLO('yolov8n.pt')
|
||||
|
||||
# Run MODE mode using the custom arguments ARGS (guess TASK)
|
||||
model.MODE(ARGS)
|
||||
```
|
||||
|
||||
Where:
|
||||
|
||||
- `TASK` (optional) is one of `[detect, segment, classify, pose]`. If it is not passed explicitly YOLOv8 will try to
|
||||
@ -36,6 +48,8 @@ differ in the type of output they produce and the specific problem they are desi
|
||||
|--------|------------|-------------------------------------------------|
|
||||
| `task` | `'detect'` | YOLO task, i.e. detect, segment, classify, pose |
|
||||
|
||||
[Tasks Guide](../tasks/index.md){ .md-button .md-button--primary}
|
||||
|
||||
#### Modes
|
||||
|
||||
YOLO models can be used in different modes depending on the specific problem you are trying to solve. These modes
|
||||
@ -52,14 +66,11 @@ include:
|
||||
|--------|-----------|---------------------------------------------------------------|
|
||||
| `mode` | `'train'` | YOLO mode, i.e. train, val, predict, export, track, benchmark |
|
||||
|
||||
### Training
|
||||
[Modes Guide](../modes/index.md){ .md-button .md-button--primary}
|
||||
|
||||
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
|
||||
include the batch size, learning rate, momentum, and weight decay. Other factors that may affect the training process
|
||||
include the choice of optimizer, the choice of loss function, and the size and composition of the training dataset. It
|
||||
is important to carefully tune and experiment with these settings to achieve the best possible performance for a given
|
||||
task.
|
||||
## Train
|
||||
|
||||
The training settings for YOLO models encompass various hyperparameters and configurations used during the training process. These settings influence the model's performance, speed, and accuracy. Key training settings include batch size, learning rate, momentum, and weight decay. Additionally, the choice of optimizer, loss function, and training dataset composition can impact the training process. Careful tuning and experimentation with these settings are crucial for optimizing performance.
|
||||
|
||||
| Key | Value | Description |
|
||||
|-------------------|----------|-----------------------------------------------------------------------------|
|
||||
@ -84,7 +95,7 @@ task.
|
||||
| `deterministic` | `True` | whether to enable deterministic mode |
|
||||
| `single_cls` | `False` | train multi-class data as single-class |
|
||||
| `image_weights` | `False` | use weighted image selection for training |
|
||||
| `rect` | `False` | support rectangular training |
|
||||
| `rect` | `False` | rectangular training with each batch collated for minimum padding |
|
||||
| `cos_lr` | `False` | use cosine learning rate scheduler |
|
||||
| `close_mosaic` | `10` | disable mosaic augmentation for final 10 epochs |
|
||||
| `resume` | `False` | resume training from last checkpoint |
|
||||
@ -107,15 +118,11 @@ task.
|
||||
| `dropout` | `0.0` | use dropout regularization (classify train only) |
|
||||
| `val` | `True` | validate/test during training |
|
||||
|
||||
### Prediction
|
||||
[Train Guide](../modes/train.md){ .md-button .md-button--primary}
|
||||
|
||||
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
|
||||
prediction settings include the confidence threshold, non-maximum suppression (NMS) threshold, and the number of classes
|
||||
to consider. Other factors that may affect the prediction process include the size and format of the input data, the
|
||||
presence of additional features such as masks or multiple labels per box, and the specific task the model is being used
|
||||
for. It is important to carefully tune and experiment with these settings to achieve the best possible performance for a
|
||||
given task.
|
||||
## Predict
|
||||
|
||||
The prediction settings for YOLO models encompass a range of hyperparameters and configurations that influence the model's performance, speed, and accuracy during inference on new data. Careful tuning and experimentation with these settings are essential to achieve optimal performance for a specific task. Key settings include the confidence threshold, Non-Maximum Suppression (NMS) threshold, and the number of classes considered. Additional factors affecting the prediction process are input data size and format, the presence of supplementary features such as masks or multiple labels per box, and the particular task the model is employed for.
|
||||
|
||||
| Key | Value | Description |
|
||||
|------------------|------------------------|----------------------------------------------------------|
|
||||
@ -141,15 +148,11 @@ given task.
|
||||
| `classes` | `None` | filter results by class, i.e. class=0, or class=[0,2,3] |
|
||||
| `boxes` | `True` | Show boxes in segmentation predictions |
|
||||
|
||||
### Validation
|
||||
[Predict Guide](../modes/predict.md){ .md-button .md-button--primary}
|
||||
|
||||
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
|
||||
accuracy. Some common YOLO validation settings include the batch size, the frequency with which validation is performed
|
||||
during training, and the metrics used to evaluate the model's performance. Other factors that may affect the validation
|
||||
process include the size and composition of the validation dataset and the specific task the model is being used for. It
|
||||
is important to carefully tune and experiment with these settings to ensure that the model is performing well on the
|
||||
validation dataset and to detect and prevent overfitting.
|
||||
## Val
|
||||
|
||||
The val (validation) settings for YOLO models involve various hyperparameters and configurations used to evaluate the model's performance on a validation dataset. These settings influence the model's performance, speed, and accuracy. Common YOLO validation settings include batch size, validation frequency during training, and performance evaluation metrics. Other factors affecting the validation process include the validation dataset's size and composition, as well as the specific task the model is employed for. Careful tuning and experimentation with these settings are crucial to ensure optimal performance on the validation dataset and detect and prevent overfitting.
|
||||
|
||||
| Key | Value | Description |
|
||||
|---------------|---------|--------------------------------------------------------------------|
|
||||
@ -162,19 +165,14 @@ validation dataset and to detect and prevent overfitting.
|
||||
| `device` | `None` | device to run on, i.e. cuda device=0/1/2/3 or device=cpu |
|
||||
| `dnn` | `False` | use OpenCV DNN for ONNX inference |
|
||||
| `plots` | `False` | show plots during training |
|
||||
| `rect` | `False` | support rectangular evaluation |
|
||||
| `rect` | `False` | rectangular val with each batch collated for minimum padding |
|
||||
| `split` | `val` | dataset split to use for validation, i.e. 'val', 'test' or 'train' |
|
||||
|
||||
### Export
|
||||
[Val Guide](../modes/val.md){ .md-button .md-button--primary}
|
||||
|
||||
Export settings for YOLO models refer to the various configurations and options used to save or
|
||||
export the model for use in other environments or platforms. These settings can affect the model's performance, size,
|
||||
and compatibility with different systems. Some common YOLO export settings include the format of the exported model
|
||||
file (e.g. ONNX, TensorFlow SavedModel), the device on which the model will be run (e.g. CPU, GPU), and the presence of
|
||||
additional features such as masks or multiple labels per box. Other factors that may affect the export process include
|
||||
the specific task the model is being used for and the requirements or constraints of the target environment or platform.
|
||||
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.
|
||||
## Export
|
||||
|
||||
Export settings for YOLO models encompass configurations and options related to saving or exporting the model for use in different environments or platforms. These settings can impact the model's performance, size, and compatibility with various systems. Key export settings include the exported model file format (e.g., ONNX, TensorFlow SavedModel), the target device (e.g., CPU, GPU), and additional features such as masks or multiple labels per box. The export process may also be affected by the model's specific task and the requirements or constraints of the destination environment or platform. It is crucial to thoughtfully configure these settings to ensure the exported model is optimized for the intended use case and functions effectively in the target environment.
|
||||
|
||||
| Key | Value | Description |
|
||||
|-------------|-----------------|------------------------------------------------------|
|
||||
@ -190,7 +188,9 @@ the intended use case and can be used effectively in the target environment.
|
||||
| `workspace` | `4` | TensorRT: workspace size (GB) |
|
||||
| `nms` | `False` | CoreML: add NMS |
|
||||
|
||||
### Augmentation
|
||||
[Export Guide](../modes/export.md){ .md-button .md-button--primary}
|
||||
|
||||
## 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
|
||||
@ -217,7 +217,7 @@ ensure that the augmented dataset is diverse and representative enough to train
|
||||
| `mixup` | 0.0 | image mixup (probability) |
|
||||
| `copy_paste` | 0.0 | segment copy-paste (probability) |
|
||||
|
||||
### Logging, checkpoints, plotting and file management
|
||||
## Logging, checkpoints, plotting and file management
|
||||
|
||||
Logging, checkpoints, plotting, and file management are important considerations when training a YOLO model.
|
||||
|
||||
|
@ -61,7 +61,7 @@ Where:
|
||||
|
||||
- `TASK` (optional) is one of `[detect, segment, classify]`. If it is not passed explicitly YOLOv8 will try to guess
|
||||
the `TASK` from the model type.
|
||||
- `MODE` (required) is one of `[train, val, predict, export]`
|
||||
- `MODE` (required) is one of `[train, val, predict, export, track]`
|
||||
- `ARGS` (optional) are any number of custom `arg=value` pairs like `imgsz=320` that override defaults.
|
||||
For a full list of available `ARGS` see the [Configuration](cfg.md) page and `defaults.yaml`
|
||||
GitHub [source](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/yolo/cfg/default.yaml).
|
||||
|
@ -150,7 +150,8 @@ predicts the classes and locations of objects in the input images or videos.
|
||||
|
||||
# segmentation
|
||||
result.masks.masks # masks, (N, H, W)
|
||||
result.masks.segments # bounding coordinates of masks, List[segment] * N
|
||||
result.masks.xy # x,y segments (pixels), List[segment] * N
|
||||
result.masks.xyn # x,y segments (normalized), List[segment] * N
|
||||
|
||||
# classification
|
||||
result.probs # cls prob, (num_class, )
|
||||
|
@ -25,7 +25,7 @@ Creating a custom model to detect your objects is an iterative process of collec
|
||||
YOLOv5 models must be trained on labelled data in order to learn classes of objects in that data. There are two options for creating your dataset before you start training:
|
||||
|
||||
<details markdown>
|
||||
<summary>Use <a href="https://roboflow.com/?ref=ultralytics">Roboflow</a> to manage your dataset in YOLO format</summary>
|
||||
<summary>Use Roboflow to manage your dataset in YOLO format</summary>
|
||||
|
||||
### 1.1 Collect Images
|
||||
|
||||
@ -102,7 +102,7 @@ names:
|
||||
|
||||
### 1.2 Create Labels
|
||||
|
||||
After using a tool like [Roboflow Annotate](https://roboflow.com/annotate?ref=ultralytics) to label your images, export your labels to **YOLO format**, with one `*.txt` file per image (if no objects in image, no `*.txt` file is required). The `*.txt` file specifications are:
|
||||
After using an annotation tool to label your images, export your labels to **YOLO format**, with one `*.txt` file per image (if no objects in image, no `*.txt` file is required). The `*.txt` file specifications are:
|
||||
|
||||
- One row per object
|
||||
- Each row is `class x_center y_center width height` format.
|
||||
|
Reference in New Issue
Block a user