ultralytics 8.0.40
TensorRT metadata and Results visualizer (#1014)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Laughing <61612323+Laughing-q@users.noreply.github.com> Co-authored-by: Bogdan Gheorghe <112427971+bogdan-galileo@users.noreply.github.com> Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com> Co-authored-by: Jaap van de Loosdrecht <jaap@vdlmv.nl> Co-authored-by: Noobtoss <96134731+Noobtoss@users.noreply.github.com> Co-authored-by: nerdyespresso <106761627+nerdyespresso@users.noreply.github.com>
This commit is contained in:
75
docs/callbacks.md
Normal file
75
docs/callbacks.md
Normal file
@ -0,0 +1,75 @@
|
||||
## Callbacks
|
||||
Ultralytics framework supports callbacks as entry points in strategic stages of train, val, export, and predict modes. Each callback accepts a `Trainer`, `Validator`, or `Predictor` object depending on the operation type. All properties of these objects can be found in Reference section of the docs.
|
||||
|
||||
## Examples
|
||||
|
||||
### Returning additional information with Prediction
|
||||
In this example, we want to return the original frame with each result object. Here's how we can do that
|
||||
```python
|
||||
def on_predict_batch_end(predictor):
|
||||
# results -> List[batch_size]
|
||||
_, _, im0s, _, _ = predictor.batch
|
||||
im0s = im0s if isinstance(im0s, list) else [im0s]
|
||||
predictor.results = zip(predictor.results, im0s)
|
||||
|
||||
model = YOLO(f"yolov8n.pt")
|
||||
model.add_callback("on_predict_batch_end", on_predict_batch_end)
|
||||
for (result, frame) in model.track/predict():
|
||||
pass
|
||||
```
|
||||
|
||||
## All callbacks
|
||||
Here are all supported callbacks.
|
||||
### Trainer
|
||||
`on_pretrain_routine_start`
|
||||
|
||||
`on_pretrain_routine_end`
|
||||
|
||||
`on_train_start`
|
||||
|
||||
`on_train_epoch_start`
|
||||
|
||||
`on_train_batch_start`
|
||||
|
||||
`optimizer_step`
|
||||
|
||||
`on_before_zero_grad`
|
||||
|
||||
`on_train_batch_end`
|
||||
|
||||
`on_train_epoch_end`
|
||||
|
||||
`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`
|
@ -34,7 +34,8 @@ Results object consists of these component objects:
|
||||
|
||||
- `Results.boxes` : `Boxes` object with properties and methods for manipulating bboxes
|
||||
- `Results.masks` : `Masks` object used to index masks or to get segment coordinates.
|
||||
- `Results.prob` : `torch.Tensor` containing the class probabilities/logits.
|
||||
- `Results.probs` : `torch.Tensor` containing the class probabilities/logits.
|
||||
- `Results.orig_shape` : `tuple` containing the original image size as (height, width).
|
||||
|
||||
Each result is composed of torch.Tensor by default, in which you can easily use following functionality:
|
||||
|
||||
@ -92,3 +93,19 @@ results[0].probs # cls prob, (num_class, )
|
||||
```
|
||||
|
||||
Class reference documentation for `Results` module and its components can be found [here](reference/results.md)
|
||||
|
||||
## Visualizing results
|
||||
|
||||
You can use `visualize()` function of `Result` object to get a visualization. It plots all componenets(boxes, masks, classification logits, etc) found in the results object
|
||||
```python
|
||||
res = model(img)
|
||||
res_plotted = res[0].visualize()
|
||||
cv2.imshow("result", res_plotted)
|
||||
```
|
||||
!!! example "`visualize()` arguments"
|
||||
|
||||
`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
|
||||
|
@ -90,6 +90,7 @@ Use a trained YOLOv8n-cls model to run predictions on images.
|
||||
yolo classify predict model=yolov8n-cls.pt source="https://ultralytics.com/images/bus.jpg" # predict with official model
|
||||
yolo classify predict model=path/to/best.pt source="https://ultralytics.com/images/bus.jpg" # predict with custom model
|
||||
```
|
||||
|
||||
Read more details of `predict` in our [Predict](https://docs.ultralytics.com/predict/) page.
|
||||
|
||||
## Export
|
||||
@ -117,20 +118,20 @@ Export a YOLOv8n-cls model to a different format like ONNX, CoreML, etc.
|
||||
yolo export model=path/to/best.pt format=onnx # export custom trained model
|
||||
```
|
||||
|
||||
Available YOLOv8-cls export formats include:
|
||||
Available YOLOv8-cls export formats include:
|
||||
|
||||
| Format | `format=` | Model | Metadata |
|
||||
|--------------------------------------------------------------------|---------------|-------------------------------|----------|
|
||||
| [PyTorch](https://pytorch.org/) | - | `yolov8n-cls.pt` | ✅ |
|
||||
| [TorchScript](https://pytorch.org/docs/stable/jit.html) | `torchscript` | `yolov8n-cls.torchscript` | ✅ |
|
||||
| [ONNX](https://onnx.ai/) | `onnx` | `yolov8n-cls.onnx` | ✅ |
|
||||
| [OpenVINO](https://docs.openvino.ai/latest/index.html) | `openvino` | `yolov8n-cls_openvino_model/` | ✅ |
|
||||
| [TensorRT](https://developer.nvidia.com/tensorrt) | `engine` | `yolov8n-cls.engine` | ✅ |
|
||||
| [CoreML](https://github.com/apple/coremltools) | `coreml` | `yolov8n-cls.mlmodel` | ✅ |
|
||||
| [TF SavedModel](https://www.tensorflow.org/guide/saved_model) | `saved_model` | `yolov8n-cls_saved_model/` | ✅ |
|
||||
| [TF GraphDef](https://www.tensorflow.org/api_docs/python/tf/Graph) | `pb` | `yolov8n-cls.pb` | ❌ |
|
||||
| [TF Lite](https://www.tensorflow.org/lite) | `tflite` | `yolov8n-cls.tflite` | ✅ |
|
||||
| [TF Edge TPU](https://coral.ai/docs/edgetpu/models-intro/) | `edgetpu` | `yolov8n-cls_edgetpu.tflite` | ✅ |
|
||||
| [TF.js](https://www.tensorflow.org/js) | `tfjs` | `yolov8n-cls_web_model/` | ✅ |
|
||||
| [PaddlePaddle](https://github.com/PaddlePaddle) | `paddle` | `yolov8n-cls_paddle_model/` | ✅ |
|
||||
|
||||
| Format | `format=` | Model |
|
||||
|----------------------------------------------------------------------------|---------------|-------------------------------|
|
||||
| [PyTorch](https://pytorch.org/) | - | `yolov8n-cls.pt` |
|
||||
| [TorchScript](https://pytorch.org/docs/stable/jit.html) | `torchscript` | `yolov8n-cls.torchscript` |
|
||||
| [ONNX](https://onnx.ai/) | `onnx` | `yolov8n-cls.onnx` |
|
||||
| [OpenVINO](https://docs.openvino.ai/latest/index.html) | `openvino` | `yolov8n-cls_openvino_model/` |
|
||||
| [TensorRT](https://developer.nvidia.com/tensorrt) | `engine` | `yolov8n-cls.engine` |
|
||||
| [CoreML](https://github.com/apple/coremltools) | `coreml` | `yolov8n-cls.mlmodel` |
|
||||
| [TensorFlow SavedModel](https://www.tensorflow.org/guide/saved_model) | `saved_model` | `yolov8n-cls_saved_model/` |
|
||||
| [TensorFlow GraphDef](https://www.tensorflow.org/api_docs/python/tf/Graph) | `pb` | `yolov8n-cls.pb` |
|
||||
| [TensorFlow Lite](https://www.tensorflow.org/lite) | `tflite` | `yolov8n-cls.tflite` |
|
||||
| [TensorFlow Edge TPU](https://coral.ai/docs/edgetpu/models-intro/) | `edgetpu` | `yolov8n-cls_edgetpu.tflite` |
|
||||
| [TensorFlow.js](https://www.tensorflow.org/js) | `tfjs` | `yolov8n-cls_web_model/` |
|
||||
| [PaddlePaddle](https://github.com/PaddlePaddle) | `paddle` | `yolov8n-cls_paddle_model/` |
|
||||
|
||||
|
@ -92,6 +92,7 @@ Use a trained YOLOv8n model to run predictions on images.
|
||||
yolo detect predict model=yolov8n.pt source="https://ultralytics.com/images/bus.jpg" # predict with official model
|
||||
yolo detect predict model=path/to/best.pt source="https://ultralytics.com/images/bus.jpg" # predict with custom model
|
||||
```
|
||||
|
||||
Read more details of `predict` in our [Predict](https://docs.ultralytics.com/predict/) page.
|
||||
|
||||
## Export
|
||||
@ -119,19 +120,19 @@ Export a YOLOv8n model to a different format like ONNX, CoreML, etc.
|
||||
yolo export model=path/to/best.pt format=onnx # export custom trained model
|
||||
```
|
||||
|
||||
Available YOLOv8 export formats include:
|
||||
|
||||
| Format | `format=` | Model |
|
||||
|----------------------------------------------------------------------------|--------------------|---------------------------|
|
||||
| [PyTorch](https://pytorch.org/) | - | `yolov8n.pt` |
|
||||
| [TorchScript](https://pytorch.org/docs/stable/jit.html) | `torchscript` | `yolov8n.torchscript` |
|
||||
| [ONNX](https://onnx.ai/) | `onnx` | `yolov8n.onnx` |
|
||||
| [OpenVINO](https://docs.openvino.ai/latest/index.html) | `openvino` | `yolov8n_openvino_model/` |
|
||||
| [TensorRT](https://developer.nvidia.com/tensorrt) | `engine` | `yolov8n.engine` |
|
||||
| [CoreML](https://github.com/apple/coremltools) | `coreml` | `yolov8n.mlmodel` |
|
||||
| [TensorFlow SavedModel](https://www.tensorflow.org/guide/saved_model) | `saved_model` | `yolov8n_saved_model/` |
|
||||
| [TensorFlow GraphDef](https://www.tensorflow.org/api_docs/python/tf/Graph) | `pb` | `yolov8n.pb` |
|
||||
| [TensorFlow Lite](https://www.tensorflow.org/lite) | `tflite` | `yolov8n.tflite` |
|
||||
| [TensorFlow Edge TPU](https://coral.ai/docs/edgetpu/models-intro/) | `edgetpu` | `yolov8n_edgetpu.tflite` |
|
||||
| [TensorFlow.js](https://www.tensorflow.org/js) | `tfjs` | `yolov8n_web_model/` |
|
||||
| [PaddlePaddle](https://github.com/PaddlePaddle) | `paddle` | `yolov8n_paddle_model/` |
|
||||
Available YOLOv8 export formats include:
|
||||
|
||||
| Format | `format=` | Model | Metadata |
|
||||
|--------------------------------------------------------------------|---------------|---------------------------|----------|
|
||||
| [PyTorch](https://pytorch.org/) | - | `yolov8n.pt` | ✅ |
|
||||
| [TorchScript](https://pytorch.org/docs/stable/jit.html) | `torchscript` | `yolov8n.torchscript` | ✅ |
|
||||
| [ONNX](https://onnx.ai/) | `onnx` | `yolov8n.onnx` | ✅ |
|
||||
| [OpenVINO](https://docs.openvino.ai/latest/index.html) | `openvino` | `yolov8n_openvino_model/` | ✅ |
|
||||
| [TensorRT](https://developer.nvidia.com/tensorrt) | `engine` | `yolov8n.engine` | ✅ |
|
||||
| [CoreML](https://github.com/apple/coremltools) | `coreml` | `yolov8n.mlmodel` | ✅ |
|
||||
| [TF SavedModel](https://www.tensorflow.org/guide/saved_model) | `saved_model` | `yolov8n_saved_model/` | ✅ |
|
||||
| [TF GraphDef](https://www.tensorflow.org/api_docs/python/tf/Graph) | `pb` | `yolov8n.pb` | ❌ |
|
||||
| [TF Lite](https://www.tensorflow.org/lite) | `tflite` | `yolov8n.tflite` | ✅ |
|
||||
| [TF Edge TPU](https://coral.ai/docs/edgetpu/models-intro/) | `edgetpu` | `yolov8n_edgetpu.tflite` | ✅ |
|
||||
| [TF.js](https://www.tensorflow.org/js) | `tfjs` | `yolov8n_web_model/` | ✅ |
|
||||
| [PaddlePaddle](https://github.com/PaddlePaddle) | `paddle` | `yolov8n_paddle_model/` | ✅ |
|
||||
|
@ -96,6 +96,7 @@ Use a trained YOLOv8n-seg model to run predictions on images.
|
||||
yolo segment predict model=yolov8n-seg.pt source="https://ultralytics.com/images/bus.jpg" # predict with official model
|
||||
yolo segment predict model=path/to/best.pt source="https://ultralytics.com/images/bus.jpg" # predict with custom model
|
||||
```
|
||||
|
||||
Read more details of `predict` in our [Predict](https://docs.ultralytics.com/predict/) page.
|
||||
|
||||
## Export
|
||||
@ -123,22 +124,21 @@ Export a YOLOv8n-seg model to a different format like ONNX, CoreML, etc.
|
||||
yolo export model=path/to/best.pt format=onnx # export custom trained model
|
||||
```
|
||||
|
||||
Available YOLOv8-seg export formats include:
|
||||
|
||||
| Format | `format=` | Model |
|
||||
|----------------------------------------------------------------------------|---------------|-------------------------------|
|
||||
| [PyTorch](https://pytorch.org/) | - | `yolov8n-seg.pt` |
|
||||
| [TorchScript](https://pytorch.org/docs/stable/jit.html) | `torchscript` | `yolov8n-seg.torchscript` |
|
||||
| [ONNX](https://onnx.ai/) | `onnx` | `yolov8n-seg.onnx` |
|
||||
| [OpenVINO](https://docs.openvino.ai/latest/index.html) | `openvino` | `yolov8n-seg_openvino_model/` |
|
||||
| [TensorRT](https://developer.nvidia.com/tensorrt) | `engine` | `yolov8n-seg.engine` |
|
||||
| [CoreML](https://github.com/apple/coremltools) | `coreml` | `yolov8n-seg.mlmodel` |
|
||||
| [TensorFlow SavedModel](https://www.tensorflow.org/guide/saved_model) | `saved_model` | `yolov8n-seg_saved_model/` |
|
||||
| [TensorFlow GraphDef](https://www.tensorflow.org/api_docs/python/tf/Graph) | `pb` | `yolov8n-seg.pb` |
|
||||
| [TensorFlow Lite](https://www.tensorflow.org/lite) | `tflite` | `yolov8n-seg.tflite` |
|
||||
| [TensorFlow Edge TPU](https://coral.ai/docs/edgetpu/models-intro/) | `edgetpu` | `yolov8n-seg_edgetpu.tflite` |
|
||||
| [TensorFlow.js](https://www.tensorflow.org/js) | `tfjs` | `yolov8n-seg_web_model/` |
|
||||
| [PaddlePaddle](https://github.com/PaddlePaddle) | `paddle` | `yolov8n-seg_paddle_model/` |
|
||||
Available YOLOv8-seg export formats include:
|
||||
|
||||
| Format | `format=` | Model | Metadata |
|
||||
|--------------------------------------------------------------------|---------------|-------------------------------|----------|
|
||||
| [PyTorch](https://pytorch.org/) | - | `yolov8n-seg.pt` | ✅ |
|
||||
| [TorchScript](https://pytorch.org/docs/stable/jit.html) | `torchscript` | `yolov8n-seg.torchscript` | ✅ |
|
||||
| [ONNX](https://onnx.ai/) | `onnx` | `yolov8n-seg.onnx` | ✅ |
|
||||
| [OpenVINO](https://docs.openvino.ai/latest/index.html) | `openvino` | `yolov8n-seg_openvino_model/` | ✅ |
|
||||
| [TensorRT](https://developer.nvidia.com/tensorrt) | `engine` | `yolov8n-seg.engine` | ✅ |
|
||||
| [CoreML](https://github.com/apple/coremltools) | `coreml` | `yolov8n-seg.mlmodel` | ✅ |
|
||||
| [TF SavedModel](https://www.tensorflow.org/guide/saved_model) | `saved_model` | `yolov8n-seg_saved_model/` | ✅ |
|
||||
| [TF GraphDef](https://www.tensorflow.org/api_docs/python/tf/Graph) | `pb` | `yolov8n-seg.pb` | ❌ |
|
||||
| [TF Lite](https://www.tensorflow.org/lite) | `tflite` | `yolov8n-seg.tflite` | ✅ |
|
||||
| [TF Edge TPU](https://coral.ai/docs/edgetpu/models-intro/) | `edgetpu` | `yolov8n-seg_edgetpu.tflite` | ✅ |
|
||||
| [TF.js](https://www.tensorflow.org/js) | `tfjs` | `yolov8n-seg_web_model/` | ✅ |
|
||||
| [PaddlePaddle](https://github.com/PaddlePaddle) | `paddle` | `yolov8n-seg_paddle_model/` | ✅ |
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user