logo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions

2.2 KiB

Pipeline: Image Embedding using Resnet50

Authors: derekdqc, shiyu22

Overview

The pipeline is used to extract the feature vector of a given image. It first normalizes the image and then uses Resnet50 model to generate the vector.

Interface

Input Arguments:

  • image:
    • the input image to be encoded
    • supported types: PIL.Image

Pipeline Output:

The pipeline returns a tuple Tuple[('feature_vector', numpy.ndarray)] containing following fields:

  • feature_vector:
    • the embedding of input image
    • data type: numpy.ndarray

How to use

  1. Install Towhee
$ pip3 install towhee

You can refer to Getting Started with Towhee for more details. If you have any questions, you can submit an issue to the towhee repository.

  1. Run it with Towhee
>>> from towhee import pipeline
>>> from PIL import Image

>>> img = Image.open('path/to/your/image') # for example, './test.jpg'
>>> embedding_pipeline = pipeline('towhee/image-embedding-resnet50')
>>> embedding = embedding_pipeline(img)

This pipeline uses the resnet50 model, you can also change the parameters resnet50 in the local file ~/.towhee/image_embedding_resnet50&towhee$main/image_embedding_resnet.yaml to the resnet101 model.

How it works

This pipeline includes two main operators: transform image (implemented as towhee/transform-image) and image embedding (implemented as towhee/resnet-image-embedding). The transform image operator will first convert the original image into a normalized format, such as with 512x512 resolutions. Then, the normalized image will be encoded via image embedding operator, and finally we get a feature vector of the given image.

Refer Towhee architecture for basic concepts in Towhee: pipeline, operator, dataframe.

img

2.2 KiB

Pipeline: Image Embedding using Resnet50

Authors: derekdqc, shiyu22

Overview

The pipeline is used to extract the feature vector of a given image. It first normalizes the image and then uses Resnet50 model to generate the vector.

Interface

Input Arguments:

  • image:
    • the input image to be encoded
    • supported types: PIL.Image

Pipeline Output:

The pipeline returns a tuple Tuple[('feature_vector', numpy.ndarray)] containing following fields:

  • feature_vector:
    • the embedding of input image
    • data type: numpy.ndarray

How to use

  1. Install Towhee
$ pip3 install towhee

You can refer to Getting Started with Towhee for more details. If you have any questions, you can submit an issue to the towhee repository.

  1. Run it with Towhee
>>> from towhee import pipeline
>>> from PIL import Image

>>> img = Image.open('path/to/your/image') # for example, './test.jpg'
>>> embedding_pipeline = pipeline('towhee/image-embedding-resnet50')
>>> embedding = embedding_pipeline(img)

This pipeline uses the resnet50 model, you can also change the parameters resnet50 in the local file ~/.towhee/image_embedding_resnet50&towhee$main/image_embedding_resnet.yaml to the resnet101 model.

How it works

This pipeline includes two main operators: transform image (implemented as towhee/transform-image) and image embedding (implemented as towhee/resnet-image-embedding). The transform image operator will first convert the original image into a normalized format, such as with 512x512 resolutions. Then, the normalized image will be encoded via image embedding operator, and finally we get a feature vector of the given image.

Refer Towhee architecture for basic concepts in Towhee: pipeline, operator, dataframe.

img