logo
Browse Source

Update

Signed-off-by: shiyu22 <shiyu.chen@zilliz.com>
main
shiyu22 3 years ago
parent
commit
5e231c348a
  1. 37
      README.md
  2. 0
      readme_res/pipeline.png
  3. BIN
      test_data/test.jpg
  4. 18
      test_image_embedding_resnet50.py

37
README.md

@ -6,32 +6,19 @@ Authors: derekdqc, shiyu22
This pipeline is used to **extract the feature vector of the image**. First step is to normalize the image, and then use resnet50 model to generate the vector. This pipeline is used to **extract the feature vector of the image**. First step is to normalize the image, and then use resnet50 model to generate the vector.
The pipeline parses [the yaml file](./image_embedding_resnet50.yaml), which declares some components we call **Operator** and **DataFrame**. Next, we will introduce the interface, show how to use it and how it works, have fun with it!
## Interface ## Interface
`towhee.pipeline(task: str, fmc: FileManagerConfig = FileManagerConfig(), branch: str = 'main', force_download: bool = False)` [\[source\]](https://github.com/towhee-io/towhee/blob/main/towhee/__init__.py)
**params:**
- **task**(str): task name or pipeline repo name.
- **fmc**(FileManagerConfig): optional, file manager config for the local instance, default is a default FileManagerConfig obejct.
- **branch**(str): optional, which branch to use for operators/pipelines on hub, defaults to 'main'.
- **force_download**(bool): optional, whether to redownload pipeline and operators, default is False.
**return:**
- **_PipelineWrapper**, an instance of the wrapper class around `Pipeline`.
**Args:**
When we declare a pipeline object with a specific task, such as `towhee/image-embedding-resnet50` in this repo, it will run according to the Yaml file, and the input and output are:
- img_tensor(`PIL.Image`),
**inputs:**
The image to be encoded.
- **img_tensor**(PIL.Image), the image to be encoded.
**Returns:**
**outputs:**
- (`Tuple[('cnn', numpy.ndarray)]`)
- **cnn**(numpy.ndarray), the embedding of the image.
The embedding of the image.
## How to use ## How to use
@ -56,14 +43,6 @@ $ pip3 install towhee
## How it works ## How it works
First of all, you need to learn the pipeline and operator in Towhee architecture:
- **Pipeline**: A `Pipeline` is a single machine learning task that is composed of several operators. Operators are connected together internally via a directed acyclic graph.
- **Operator**: An `Operator` is a single node within a pipeline. It contains files (e.g. code, configs, models, etc...) and works for reusable operations (e.g., preprocessing an image, inference with a pretrained model).
This pipeline includes four functions: `_start_op`, `towhee/transform-image`, `towhee/resnet50-image-embedding` and `_end_op`. It is necessary to ensure that the input and output of the four Operators correspond to each other, and the input and output data types can be defined by DataFrame.
![img](./pic/pipeline.png)
You can learn the pipeline and operator in [Towhee architecture](https://github.com/towhee-io/towhee#towhee-architecture). This pipeline includes two main functions: [towhee/transform-image](https://hub.towhee.io/towhee/transform-image) and [towhee/resnet50-image-embedding](https://hub.towhee.io/towhee/resnet50-image-embedding). It is necessary to ensure that the input and output of the four Operators correspond to each other, and the input and output data types can be defined by DataFrame.
Among the four Operator, `_start_op` and `_end_op` are required in any Pipeline, and they are used to start and end the pipeline in the Towhee system. For the other two Operators, please refer to [towhee/transform-image](https://hub.towhee.io/towhee/transform-image) and [towhee/resnet50-image-embedding](https://hub.towhee.io/towhee/resnet50-image-embedding).
![img](./readme_res/pipeline.png)

0
pic/pipeline.png → readme_res/pipeline.png

Before

Width:  |  Height:  |  Size: 266 KiB

After

Width:  |  Height:  |  Size: 266 KiB

BIN
test_data/test.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 KiB

18
test_image_embedding_resnet50.py

@ -1,18 +0,0 @@
import os
import unittest
from towhee import pipeline
from PIL import Image
class TestImageEmbeddingResnet50(unittest.TestCase):
def test_image_embedding_resnet50(self):
img_src = './test_data/test.jpg'
test_img = Image.open(img_src)
dimension = 1000
embedding_pipeline = pipeline('towhee/image-embedding-resnet50')
embedding = embedding_pipeline(test_img)
self.assertEqual((1, dimension), embedding[0][0].shape)
if __name__ == '__main__':
unittest.main()
Loading…
Cancel
Save