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>single_channel
parent
d9a0fba251
commit
21b701c4ea
@ -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"
|
!!! example "Predict"
|
||||||
|
|
||||||
=== "Getting a List"
|
=== "Getting a List"
|
||||||
```python
|
|
||||||
inputs = [img, img] # list of np arrays
|
```python
|
||||||
results = model(inputs) # List of Results objects
|
inputs = [img, img] # list of np arrays
|
||||||
for result in results:
|
results = model(inputs) # List of Results objects
|
||||||
boxes = result.boxes # Boxes object for bbox outputs
|
|
||||||
masks = result.masks # Masks object for segmenation masks outputs
|
for result in results:
|
||||||
probs = result.probs # Class probabilities for classification outputs
|
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"
|
=== "Getting a Generator"
|
||||||
```python
|
|
||||||
inputs = [img, img] # list of np arrays
|
```python
|
||||||
results = model(inputs, stream=True) # Generator of Results objects
|
inputs = [img, img] # list of numpy arrays
|
||||||
for result in results:
|
results = model(inputs, stream=True) # generator of Results objects
|
||||||
boxes = result.boxes # Boxes object for bbox outputs
|
|
||||||
masks = result.masks # Masks object for segmenation masks outputs
|
for r in results:
|
||||||
probs = result.probs # Class probabilities for classification outputs
|
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
|
## Working with Results
|
||||||
|
|
||||||
Results object consists of these component objects:
|
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.boxes` : `Boxes` object with 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.masks` : `Masks` object used to index masks or to get segment coordinates.
|
||||||
- `results.prob` : It is a `Tensor` object. It contains the class probabilities/logits.
|
- `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:
|
Each result is composed of torch.Tensor by default, in which you can easily use following functionality:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
results = results.cuda()
|
results = results.cuda()
|
||||||
results = results.cpu()
|
results = results.cpu()
|
||||||
results = results.to("cpu")
|
results = results.to("cpu")
|
||||||
results = results.numpy()
|
results = results.numpy()
|
||||||
```
|
```
|
||||||
|
|
||||||
### Boxes
|
### 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
|
- Indexing a `Boxes` objects returns a `Boxes` object
|
||||||
|
|
||||||
```python
|
```python
|
||||||
boxes = results.boxes
|
results = model(inputs)
|
||||||
box = boxes[0] # returns one box
|
boxes = results[0].boxes
|
||||||
|
box = boxes[0] # returns one box
|
||||||
box.xyxy
|
box.xyxy
|
||||||
```
|
```
|
||||||
|
|
||||||
- Properties and conversions
|
- Properties and conversions
|
||||||
```
|
|
||||||
boxes.xyxy # box with xyxy format, (N, 4)
|
```python
|
||||||
boxes.xywh # box with xywh format, (N, 4)
|
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.xyxyn # box with xyxy format but normalized, (N, 4)
|
||||||
boxes.xywhn # box with xywh format but normalized, (N, 4)
|
boxes.xywhn # box with xywh format but normalized, (N, 4)
|
||||||
boxes.conf # confidence score, (N, 1)
|
boxes.conf # confidence score, (N, 1)
|
||||||
boxes.cls # cls, (N, 1)
|
boxes.cls # cls, (N, 1)
|
||||||
boxes.data # raw bboxes tensor, (N, 6) or boxes.boxes .
|
boxes.data # raw bboxes tensor, (N, 6) or boxes.boxes .
|
||||||
```
|
```
|
||||||
|
|
||||||
### Masks
|
### Masks
|
||||||
|
|
||||||
`Masks` object can be used index, manipulate and convert masks to segments. The segment conversion operation is cached.
|
`Masks` object can be used index, manipulate and convert masks to segments. The segment conversion operation is cached.
|
||||||
|
|
||||||
```python
|
```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.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
|
||||||
|
|
||||||
`probs` attribute of `Results` class is a `Tensor` containing class probabilities of a classification operation.
|
`probs` attribute of `Results` class is a `Tensor` containing class probabilities of a classification operation.
|
||||||
|
|
||||||
```python
|
```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)
|
Class reference documentation for `Results` module and its components can be found [here](reference/results.md)
|
||||||
|
Loading…
Reference in new issue