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.3 KiB

Image Embedding with Timm

author: Jael Gu, Filip

Desription

An image embedding operator generates a vector given an image. This operator extracts features for image with pretrained models provided by Timm. Timm is a deep-learning library developed by Ross Wightman, which maintains SOTA deep-learning models and tools in computer vision.

Code Example

Load an image from path './dog.jpg' and use the pretrained ResNet50 model ('resnet50') to generate an image embedding.

Write the pipeline in simplified style:

from towhee import dc

dc.glob('./dog.jpg') \
  .image_decode.cv2() \
  .image_embedding.timm(model_name='resnet50') \
  .show()

Write a same pipeline with explicit inputs/outputs name specifications:

from towhee import dc

dc.glob['path']('./dog.jpg') \
  .image_decode.cv2['path', 'img']() \
  .image_embedding.timm['img', 'vec'](model_name='resnet50') \
  .select('vec') \
  .to_list()
[array([0.        , 0.        , 0.        , ..., 0.        , 0.01748613,
   0.        ], dtype=float32)]

Factory Constructor

Create the operator via the following factory method

image_embedding.timm(model_name='resnet34', num_classes=1000, skip_preprocess=False)

Parameters:

model_name: str

​ The model name in string. The default value is "resnet34". Refer Timm Docs to get a full list of supported models.

num_classes: 1000

​ The number of classes. The default value is 1000. It is related to model and dataset.

skip_preprocess: bool Flag to control whether to skip image preprocess, defaults to False. If set to True, image preprocess steps such as transform, normalization will be skipped. In this case, the user should guarantee that all the input images are already reprocessed properly, and thus can be fed to model directly.

Interface

An image embedding operator takes an image in ndarray as input. It uses the pre-trained model specified by model name to generate an image embedding in ndarray.

Parameters:

img: numpy.ndarray

​ The decoded image data in numpy.ndarray.

Returns: numpy.ndarray

​ The image embedding extracted by model.

2.3 KiB

Image Embedding with Timm

author: Jael Gu, Filip

Desription

An image embedding operator generates a vector given an image. This operator extracts features for image with pretrained models provided by Timm. Timm is a deep-learning library developed by Ross Wightman, which maintains SOTA deep-learning models and tools in computer vision.

Code Example

Load an image from path './dog.jpg' and use the pretrained ResNet50 model ('resnet50') to generate an image embedding.

Write the pipeline in simplified style:

from towhee import dc

dc.glob('./dog.jpg') \
  .image_decode.cv2() \
  .image_embedding.timm(model_name='resnet50') \
  .show()

Write a same pipeline with explicit inputs/outputs name specifications:

from towhee import dc

dc.glob['path']('./dog.jpg') \
  .image_decode.cv2['path', 'img']() \
  .image_embedding.timm['img', 'vec'](model_name='resnet50') \
  .select('vec') \
  .to_list()
[array([0.        , 0.        , 0.        , ..., 0.        , 0.01748613,
   0.        ], dtype=float32)]

Factory Constructor

Create the operator via the following factory method

image_embedding.timm(model_name='resnet34', num_classes=1000, skip_preprocess=False)

Parameters:

model_name: str

​ The model name in string. The default value is "resnet34". Refer Timm Docs to get a full list of supported models.

num_classes: 1000

​ The number of classes. The default value is 1000. It is related to model and dataset.

skip_preprocess: bool Flag to control whether to skip image preprocess, defaults to False. If set to True, image preprocess steps such as transform, normalization will be skipped. In this case, the user should guarantee that all the input images are already reprocessed properly, and thus can be fed to model directly.

Interface

An image embedding operator takes an image in ndarray as input. It uses the pre-trained model specified by model name to generate an image embedding in ndarray.

Parameters:

img: numpy.ndarray

​ The decoded image data in numpy.ndarray.

Returns: numpy.ndarray

​ The image embedding extracted by model.