From 1ee99d169d57d819e940490b67889beb30c3b1b3 Mon Sep 17 00:00:00 2001 From: Filip Haltmayer Date: Thu, 10 Feb 2022 13:47:47 -0800 Subject: [PATCH] upload --- README.md | 23 ++--- image_embedding_resnet50.yaml | 161 +++++++++++++++------------------- 2 files changed, 77 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index 510e108..d8881a9 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ -# Pipeline: Image Embedding using Resnet50 +# Pipeline: Image Embedding using resnet50 -Authors: derekdqc +Authors: Filip ## Overview -The pipeline is used to **extract the feature vector of a given image**. It uses Resnet50 model to generate the vector. +The pipeline is used to **extract the feature vector of a given image**. It uses the the resnet50 model from Ross Wightman's [`timm`](https://github.com/rwightman/pytorch-image-models) to generate the vector. ## Interface **Input Arguments:** - img_path: - - path to the input image + - the input image path - supported types: `str` **Pipeline Output:** @@ -21,7 +21,8 @@ The pipeline returns a tuple `Tuple[('feature_vector', numpy.ndarray)]` containi - feature_vector: - the embedding of input image - data type: `numpy.ndarray` - - shape: (2048,) + - shape: (1, 2048) + ## How to use 1. Install [Towhee](https://github.com/towhee-io/towhee) @@ -37,15 +38,7 @@ $ pip3 install towhee ```python >>> from towhee import pipeline +>>> img_path = 'path/to/your/image' >>> embedding_pipeline = pipeline('towhee/image-embedding-resnet50') ->>> embedding = embedding_pipeline('path/to/your/image') #such as './readme_res/pipeline.png' +>>> embedding = embedding_pipeline(img_path) ``` - -## How it works - -This pipeline includes one operator: [image embedding](https://hub.towhee.io/towhee/image-embedding-operator-template) (implemented as [towhee/resnet-image-embedding](https://hub.towhee.io/towhee/resnet-image-embedding)). The image will be encoded via image embedding operator, then we can get a feature vector of the given image. - - -> Refer [Towhee architecture](https://github.com/towhee-io/towhee#towhee-architecture) for basic concepts in Towhee: pipeline, operator, dataframe. - -![img](./readme_res/pipeline.png) diff --git a/image_embedding_resnet50.yaml b/image_embedding_resnet50.yaml index d201a81..9fe6a77 100644 --- a/image_embedding_resnet50.yaml +++ b/image_embedding_resnet50.yaml @@ -1,94 +1,71 @@ -name: 'image-embedding-resnet' -type: 'image-embedding' +name: image_embedding_resnet50 +type: image-embedding operators: - - - name: '_start_op' - function: '_start_op' - init_args: - inputs: - - - df: '_start_df' - name: 'img_path' - col: 0 - outputs: - - - df: 'img_str' - iter_info: - type: map - - - name: 'image_decoder' - function: 'towhee/image-decoder' - tag: 'main' - init_args: - inputs: - - - df: 'img_str' - name: 'image_path' - col: 0 - outputs: - - - df: 'image' - iter_info: - type: map - - - - name: 'embedding_model' - function: 'towhee/resnet-image-embedding' # same as 'resnet50-image-embedding', default user is towhee - tag: 'main' - init_args: - model_name: 'resnet50' - inputs: - - - df: 'image' - name: 'image' - col: 0 - outputs: - - - df: 'embedding' - iter_info: - type: map - - - name: '_end_op' - function: '_end_op' - init_args: - inputs: - - - df: 'embedding' - name: 'feature_vector' - col: 0 - outputs: - - - df: '_end_df' - iter_info: - type: map +- name: _start_op + function: _start_op + init_args: null + inputs: + - df: _start_df + name: img_path + col: 0 + outputs: + - df: img_str + iter_info: + type: map +- name: image_decoder + function: towhee/image-decoder + tag: main + init_args: null + inputs: + - df: img_str + name: image_path + col: 0 + outputs: + - df: image + iter_info: + type: map +- name: embedding_model + function: towhee/timm-image-embedding + tag: main + init_args: + model_name: resnet50 + inputs: + - df: image + name: image + col: 0 + outputs: + - df: embedding + iter_info: + type: map +- name: _end_op + function: _end_op + init_args: null + inputs: + - df: embedding + name: feature_vector + col: 0 + outputs: + - df: _end_df + iter_info: + type: map dataframes: - - - name: '_start_df' - columns: - - - name: 'img_path' - vtype: 'str' - - - name: 'img_str' - columns: - - - name: 'img_path' - vtype: 'str' - - - name: 'image' - columns: - - - name: 'image' - vtype: 'towhee.types.Image' - - - name: 'embedding' - columns: - - - name: 'feature_vector' - vtype: 'numpy.ndarray' - - - name: '_end_df' - columns: - - - name: 'feature_vector' - vtype: 'numpy.ndarray' +- name: _start_df + columns: + - name: img_path + vtype: str +- name: img_str + columns: + - name: img_path + vtype: str +- name: image + columns: + - name: image + vtype: towhee.types.Image +- name: embedding + columns: + - name: feature_vector + vtype: numpy.ndarray +- name: _end_df + columns: + - name: feature_vector + vtype: numpy.ndarray