Threadpool fixes and CLI improvements (#550)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
This commit is contained in:
43
docs/cfg.md
43
docs/cfg.md
@ -2,40 +2,51 @@ YOLO settings and hyperparameters play a critical role in the model's performanc
|
||||
and hyperparameters can affect the model's behavior at various stages of the model development process, including
|
||||
training, validation, and prediction.
|
||||
|
||||
Properly setting and tuning these parameters can have a significant impact on the model's ability to learn effectively
|
||||
from the training data and generalize to new data. For example, choosing an appropriate learning rate, batch size, and
|
||||
optimization algorithm can greatly affect the model's convergence speed and accuracy. Similarly, setting the correct
|
||||
confidence threshold and non-maximum suppression (NMS) threshold can affect the model's performance on detection tasks.
|
||||
YOLOv8 'yolo' CLI commands use the following syntax:
|
||||
|
||||
It is important to carefully consider and experiment with these settings and hyperparameters to achieve the best
|
||||
possible performance for a given task. This can involve trial and error, as well as using techniques such as
|
||||
hyperparameter optimization to search for the optimal set of parameters.
|
||||
!!! example ""
|
||||
|
||||
In summary, YOLO settings and hyperparameters are a key factor in the success of a YOLO model, and it is important to
|
||||
pay careful attention to them to achieve the desired results.
|
||||
=== "CLI"
|
||||
|
||||
```bash
|
||||
yolo TASK MODE ARGS
|
||||
```
|
||||
|
||||
### Setting the operation type
|
||||
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]`
|
||||
- `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).
|
||||
|
||||
#### Tasks
|
||||
|
||||
YOLO models can be used for a variety of tasks, including detection, segmentation, and classification. These tasks
|
||||
differ in the type of output they produce and the specific problem they are designed to solve.
|
||||
|
||||
- Detection: Detection tasks involve identifying and localizing objects or regions of interest in an image or video.
|
||||
- **Detect**: Detection tasks involve identifying and localizing objects or regions of interest in an image or video.
|
||||
YOLO models can be used for object detection tasks by predicting the bounding boxes and class labels of objects in an
|
||||
image.
|
||||
- Segmentation: Segmentation tasks involve dividing an image or video into regions or pixels that correspond to
|
||||
- **Segment**: Segmentation tasks involve dividing an image or video into regions or pixels that correspond to
|
||||
different objects or classes. YOLO models can be used for image segmentation tasks by predicting a mask or label for
|
||||
each pixel in an image.
|
||||
- Classification: Classification tasks involve assigning a class label to an input, such as an image or text. YOLO
|
||||
- **Classify**: Classification tasks involve assigning a class label to an input, such as an image or text. YOLO
|
||||
models can be used for image classification tasks by predicting the class label of an input image.
|
||||
|
||||
#### Modes
|
||||
|
||||
YOLO models can be used in different modes depending on the specific problem you are trying to solve. These modes
|
||||
include train, val, and predict.
|
||||
|
||||
- Train: The train mode is used to train the model on a dataset. This mode is typically used during the development and
|
||||
- **Train**: The train mode is used to train the model on a dataset. This mode is typically used during the development
|
||||
and
|
||||
testing phase of a model.
|
||||
- Val: The val mode is used to evaluate the model's performance on a validation dataset. This mode is typically used to
|
||||
- **Val**: The val mode is used to evaluate the model's performance on a validation dataset. This mode is typically used
|
||||
to
|
||||
tune the model's hyperparameters and detect overfitting.
|
||||
- Predict: The predict mode is used to make predictions with the model on new data. This mode is typically used in
|
||||
- **Predict**: The predict mode is used to make predictions with the model on new data. This mode is typically used in
|
||||
production or when deploying the model to users.
|
||||
|
||||
| Key | Value | Description |
|
||||
|
@ -16,8 +16,9 @@ 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]`
|
||||
- `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.
|
||||
- `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).
|
||||
|
||||
!!! note ""
|
||||
|
||||
|
@ -1,74 +1,94 @@
|
||||
Inference or prediction of a task returns a list of `Results` objects. Alternatively, in the streaming mode, it returns a generator of `Results` objects which is memory efficient. Streaming mode can be enabled by passing `stream=True` in predictor's call method.
|
||||
Inference or prediction of a task returns a list of `Results` objects. Alternatively, in the streaming mode, it returns
|
||||
a generator of `Results` objects which is memory efficient. Streaming mode can be enabled by passing `stream=True` in
|
||||
predictor's call method.
|
||||
|
||||
!!! example "Predict"
|
||||
|
||||
=== "Getting a List"
|
||||
```python
|
||||
inputs = [img, img] # list of np arrays
|
||||
results = model(inputs) # List of Results objects
|
||||
for result in results:
|
||||
boxes = result.boxes # Boxes object for bbox outputs
|
||||
masks = result.masks # Masks object for segmenation masks outputs
|
||||
probs = result.probs # Class probabilities for classification outputs
|
||||
...
|
||||
```
|
||||
|
||||
```python
|
||||
inputs = [img, img] # list of np arrays
|
||||
results = model(inputs) # List of Results objects
|
||||
|
||||
for result in results:
|
||||
boxes = result.boxes # Boxes object for bbox outputs
|
||||
masks = result.masks # Masks object for segmenation masks outputs
|
||||
probs = result.probs # Class probabilities for classification outputs
|
||||
```
|
||||
|
||||
=== "Getting a Generator"
|
||||
```python
|
||||
inputs = [img, img] # list of np arrays
|
||||
results = model(inputs, stream=True) # Generator of Results objects
|
||||
for result in results:
|
||||
boxes = result.boxes # Boxes object for bbox outputs
|
||||
masks = result.masks # Masks object for segmenation masks outputs
|
||||
probs = result.probs # Class probabilities for classification outputs
|
||||
...
|
||||
```
|
||||
|
||||
```python
|
||||
inputs = [img, img] # list of numpy arrays
|
||||
results = model(inputs, stream=True) # generator of Results objects
|
||||
|
||||
for r in results:
|
||||
boxes = r.boxes # Boxes object for bbox outputs
|
||||
masks = r.masks # Masks object for segmenation masks outputs
|
||||
probs = r.probs # Class probabilities for classification outputs
|
||||
```
|
||||
|
||||
## Working with Results
|
||||
|
||||
Results object consists of these component objects:
|
||||
|
||||
- `results.boxes` : It is an object of class `Boxes`. It has properties and methods for manipulating bboxes
|
||||
- `results.masks` : It is an object of class `Masks`. It can be used to index masks or to get segment coordinates.
|
||||
- `results.prob` : It is a `Tensor` object. It contains the class probabilities/logits.
|
||||
- `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.
|
||||
|
||||
Each result is composed of torch.Tensor by default, in which you can easily use following functionality:
|
||||
|
||||
```python
|
||||
results = results.cuda()
|
||||
results = results.cpu()
|
||||
results = results.to("cpu")
|
||||
results = results.numpy()
|
||||
```
|
||||
|
||||
### Boxes
|
||||
`Boxes` object can be used index, manipulate and convert bboxes to different formats. The box format conversion operations are cached, which means they're only calculated once per object and those values are reused for future calls.
|
||||
|
||||
`Boxes` object can be used index, manipulate and convert bboxes to different formats. The box format conversion
|
||||
operations are cached, which means they're only calculated once per object and those values are reused for future calls.
|
||||
|
||||
- Indexing a `Boxes` objects returns a `Boxes` object
|
||||
|
||||
```python
|
||||
boxes = results.boxes
|
||||
box = boxes[0] # returns one box
|
||||
results = model(inputs)
|
||||
boxes = results[0].boxes
|
||||
box = boxes[0] # returns one box
|
||||
box.xyxy
|
||||
```
|
||||
|
||||
- Properties and conversions
|
||||
```
|
||||
boxes.xyxy # box with xyxy format, (N, 4)
|
||||
boxes.xywh # box with xywh format, (N, 4)
|
||||
|
||||
```python
|
||||
boxes.xyxy # box with xyxy format, (N, 4)
|
||||
boxes.xywh # box with xywh format, (N, 4)
|
||||
boxes.xyxyn # box with xyxy format but normalized, (N, 4)
|
||||
boxes.xywhn # box with xywh format but normalized, (N, 4)
|
||||
boxes.conf # confidence score, (N, 1)
|
||||
boxes.cls # cls, (N, 1)
|
||||
boxes.data # raw bboxes tensor, (N, 6) or boxes.boxes .
|
||||
boxes.conf # confidence score, (N, 1)
|
||||
boxes.cls # cls, (N, 1)
|
||||
boxes.data # raw bboxes tensor, (N, 6) or boxes.boxes .
|
||||
```
|
||||
|
||||
### Masks
|
||||
|
||||
`Masks` object can be used index, manipulate and convert masks to segments. The segment conversion operation is cached.
|
||||
|
||||
```python
|
||||
masks = results.masks # Masks object
|
||||
results = model(inputs)
|
||||
masks = results[0].masks # Masks object
|
||||
masks.segments # bounding coordinates of masks, List[segment] * N
|
||||
masks.data # raw masks tensor, (N, H, W) or masks.masks
|
||||
masks.data # raw masks tensor, (N, H, W) or masks.masks
|
||||
```
|
||||
|
||||
### probs
|
||||
|
||||
`probs` attribute of `Results` class is a `Tensor` containing class probabilities of a classification operation.
|
||||
|
||||
```python
|
||||
results.probs # cls prob, (num_class, )
|
||||
results = model(inputs)
|
||||
results[0].probs # cls prob, (num_class, )
|
||||
```
|
||||
|
||||
Class reference documentation for `Results` module and its components can be found [here](reference/results.md)
|
||||
|
Reference in New Issue
Block a user