|
@ -4,7 +4,7 @@ |
|
|
|
|
|
|
|
|
<br /> |
|
|
<br /> |
|
|
|
|
|
|
|
|
## Desription |
|
|
|
|
|
|
|
|
## Description |
|
|
|
|
|
|
|
|
An image embedding operator generates a vector given an image. |
|
|
An image embedding operator generates a vector given an image. |
|
|
This operator extracts features for image top ranked models from |
|
|
This operator extracts features for image top ranked models from |
|
@ -18,22 +18,25 @@ The default pretrained model weights are from [The 1st Place Solution of ISC21 ( |
|
|
Load an image from path './towhee.jpg' |
|
|
Load an image from path './towhee.jpg' |
|
|
and use the pretrained ISC model ('resnet50') to generate an image embedding. |
|
|
and use the pretrained ISC model ('resnet50') to generate an image embedding. |
|
|
|
|
|
|
|
|
*Write the pipeline in simplified style:* |
|
|
|
|
|
|
|
|
*Write a same pipeline with explicit inputs/outputs name specifications:* |
|
|
|
|
|
|
|
|
|
|
|
- **option 1:** |
|
|
|
|
|
|
|
|
```python |
|
|
```python |
|
|
import towhee |
|
|
|
|
|
|
|
|
from towhee.dc2 import pipe, ops, DataCollection |
|
|
|
|
|
|
|
|
( |
|
|
|
|
|
towhee.glob('./towhee.jpg') |
|
|
|
|
|
.image_decode() |
|
|
|
|
|
.image_embedding.isc() |
|
|
|
|
|
.show() |
|
|
|
|
|
|
|
|
p = ( |
|
|
|
|
|
pipe.input('path') |
|
|
|
|
|
.map('path', 'img', ops.image_decode()) |
|
|
|
|
|
.map('img', 'vec', ops.image_embedding.isc()) |
|
|
|
|
|
.output('img', 'vec') |
|
|
) |
|
|
) |
|
|
``` |
|
|
|
|
|
<img src="./result1.png" height="50px"/> |
|
|
|
|
|
|
|
|
|
|
|
*Write a same pipeline with explicit inputs/outputs name specifications:* |
|
|
|
|
|
|
|
|
DataCollection(p('towhee.jpeg')).show() |
|
|
|
|
|
``` |
|
|
|
|
|
<img src="./result.png" height="150px"/> |
|
|
|
|
|
|
|
|
|
|
|
- **option 2:** |
|
|
```python |
|
|
```python |
|
|
import towhee |
|
|
import towhee |
|
|
|
|
|
|
|
@ -45,7 +48,6 @@ import towhee |
|
|
.show() |
|
|
.show() |
|
|
) |
|
|
) |
|
|
``` |
|
|
``` |
|
|
<img src="./result2.png" height="150px"/> |
|
|
|
|
|
|
|
|
|
|
|
<br /> |
|
|
<br /> |
|
|
|
|
|
|
|
@ -83,10 +85,32 @@ It uses the pre-trained model specified by model name to generate an image embed |
|
|
The decoded image data in numpy.ndarray. |
|
|
The decoded image data in numpy.ndarray. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Returns:** *numpy.ndarray* |
|
|
**Returns:** *numpy.ndarray* |
|
|
|
|
|
|
|
|
The image embedding extracted by model. |
|
|
The image embedding extracted by model. |
|
|
|
|
|
|
|
|
|
|
|
<br /> |
|
|
|
|
|
|
|
|
|
|
|
***save_model(format='pytorch', path='default')*** |
|
|
|
|
|
|
|
|
|
|
|
Save model to local with specified format. |
|
|
|
|
|
|
|
|
|
|
|
**Parameters:** |
|
|
|
|
|
|
|
|
|
|
|
***format***: *str* |
|
|
|
|
|
|
|
|
|
|
|
The format of saved model, defaults to 'pytorch'. |
|
|
|
|
|
|
|
|
|
|
|
***path***: *str* |
|
|
|
|
|
|
|
|
|
|
|
The path where model is saved to. By default, it will save model to the operator directory. |
|
|
|
|
|
|
|
|
|
|
|
```python |
|
|
|
|
|
from towhee import ops |
|
|
|
|
|
|
|
|
|
|
|
op = ops.image_embedding.isc().get_op() |
|
|
|
|
|
op.save_model('onnx', 'test.onnx') |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|