copied
Readme
Files and versions
Updated 2 years ago
image-embedding
Image Embedding with Timm
author: Jael Gu, Filip
Description
An image embedding operator generates a vector given an image. This operator extracts features for image with pre-trained models provided by Timm. Timm is a deep-learning library developed by Ross Wightman, who maintains SOTA deep-learning models and tools in computer vision.
Code Example
Load an image from path './towhee.jpeg' and use the pre-trained ResNet50 model ('resnet50') to generate an image embedding.
Write the pipeline in simplified style:
import towhee
towhee.glob('./towhee.jpeg') \
.image_decode() \
.image_embedding.timm(model_name='resnet50') \
.show()
Write a same pipeline with explicit inputs/outputs name specifications:
import towhee
towhee.glob['path']('./towhee.jpeg') \
.image_decode['path', 'img']() \
.image_embedding.timm['img', 'vec'](model_name='resnet50') \
.select['img', 'vec']() \
.show()
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 to Timm Docs to get a full list of supported models.
num_classes: int
The number of classes. The default value is 1000. It is related to model and dataset.
skip_preprocess: bool
The flag to control whether to skip image pre-process. The default value is False. If set to True, it will skip image preprocessing steps (transforms). In this case, input image data must be prepared in advance in order to properly fit the model.
Interface
An image embedding operator takes a towhee image as input. It uses the pre-trained model specified by model name to generate an image embedding in ndarray.
Parameters:
data: towhee._types.Image
The decoded image data in towhee Image (a subset of numpy.ndarray).
Returns: numpy.ndarray
An image embedding generated by model, in shape of (feature_dim,).
junjie.jiang
2989fee8f3
| 52 Commits | ||
---|---|---|---|
.gitattributes |
1.1 KiB
|
3 years ago | |
README.md |
2.3 KiB
|
2 years ago | |
__init__.py |
680 B
|
3 years ago | |
requirements.txt |
31 B
|
2 years ago | |
result1.png |
4.0 KiB
|
3 years ago | |
result2.png |
80 KiB
|
3 years ago | |
test_onnx.py |
2.5 KiB
|
2 years ago | |
test_torchscript.py |
2.5 KiB
|
2 years ago | |
timm_image.py |
5.6 KiB
|
2 years ago | |
towhee.jpeg |
49 KiB
|
2 years ago |