|
|
@ -22,37 +22,40 @@ This operator uses [PyTorch.yolov5](https://pytorch.org/hub/ultralytics_yolov5/) |
|
|
|
|
|
|
|
### Code Example |
|
|
|
|
|
|
|
Load an image from path './test.png' and use yolov5 model to detect objects in the image. |
|
|
|
|
|
|
|
*Write a same pipeline with explicit inputs/outputs name specifications:* |
|
|
|
|
|
|
|
- Write the pipeline in the simplified way: |
|
|
|
|
|
|
|
- **option 1: towhee>=0.9.0** |
|
|
|
```Python |
|
|
|
import towhee |
|
|
|
|
|
|
|
towhee.glob('./test.png') \ |
|
|
|
.image_decode() \ |
|
|
|
.object_detection.yolov5() \ |
|
|
|
.show() |
|
|
|
``` |
|
|
|
from towhee.dc2 import pipe, ops, DataCollection |
|
|
|
|
|
|
|
<img src="./results1.png" alt="results1" height="40px"/> |
|
|
|
p = ( |
|
|
|
pipe.input('path') |
|
|
|
.map('path', 'img', ops.image_decode()) |
|
|
|
.map('img', ('box', 'class', 'score'), ops.object_detection.yolov5()) |
|
|
|
.map(('img', 'box'), 'object', ops.image_crop(clamp=True)) |
|
|
|
.output('img', 'object', 'class') |
|
|
|
) |
|
|
|
|
|
|
|
- Write the same pipeline with explicitly specified inputs and outputs: |
|
|
|
DataCollection(p('./test.png')).show() |
|
|
|
``` |
|
|
|
|
|
|
|
```Python |
|
|
|
- **option 2:** |
|
|
|
```python |
|
|
|
import towhee |
|
|
|
|
|
|
|
towhee.glob['path']('./test.png') \ |
|
|
|
.image_decode['path','img']() \ |
|
|
|
.object_detection.yolov5['img', ('box', 'class', 'score')]() \ |
|
|
|
.image_crop[('img', 'box'), 'object'](clamp = True) \ |
|
|
|
.select['img','object']() \ |
|
|
|
( |
|
|
|
towhee.glob['path']('./test.png') |
|
|
|
.image_decode['path','img']() |
|
|
|
.object_detection.yolov5['img', ('box', 'class', 'score')]() |
|
|
|
.image_crop[('img', 'box'), 'object'](clamp = True) |
|
|
|
.select['img','object', 'class']() |
|
|
|
.show() |
|
|
|
) |
|
|
|
``` |
|
|
|
|
|
|
|
<img src="./results2.png" alt="results1" height="140px"/> |
|
|
|
|
|
|
|
|
|
|
|
<img src="./result.png" alt="result" height="140px"/> |
|
|
|
|
|
|
|
<br /> |
|
|
|
|
|
|
|