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

Updated 3 years ago

image-embedding

Image Embdding with data2vec

author: David Wang


Description

This operator extracts features for image with data2vec. The core idea is to predict latent representations of the full input data based on a masked view of the input in a self-distillation setup using a standard Transformer architecture.


Code Example

Load an image from path './towhee.jpg' to generate an image embedding.

Write the pipeline in simplified style:

import towhee

towhee.glob('./towhee.jpg') \
      .image_decode.cv2() \
      .image_embedding.data2vec_vision(model_name='facebook/data2vec-vision-base-ft1k') \
      .show()

result1

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

import towhee

towhee.glob['path']('./towhee.jpg') \
      .image_decode.cv2['path', 'img']() \
      .image_embedding.data2vec_vision['img', 'vec'](model_name='facebook/data2vec-vision-base-ft1k') \
      .select['img', 'vec']() \
      .show()
result2


Factory Constructor

Create the operator via the following factory method

data2vec_vision(model_name='facebook/data2vec-vision-base')

Parameters:

model_name: str

The model name in string. The default value is "facebook/data2vec-vision-base-ft1k".

Supported model name:

  • facebook/data2vec-vision-base-ft1k
  • facebook/data2vec-vision-large-ft1k


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:

img: towhee.types.Image (a sub-class of numpy.ndarray)

​ The decoded image data in towhee.types.Image (numpy.ndarray).

Returns: numpy.ndarray

​ The image embedding extracted by model.

ChengZi d7a7261ad5 add requirement 3 Commits
file-icon .gitattributes
1.1 KiB
download-icon
Initial commit 3 years ago
file-icon README.md
2.1 KiB
download-icon
init the opeartor. 3 years ago
file-icon __init__.py
745 B
download-icon
init the opeartor. 3 years ago
file-icon data2vec_vision.py
1.5 KiB
download-icon
init the opeartor. 3 years ago
file-icon requirements.txt
52 B
download-icon
add requirement 3 years ago
file-icon result1.png
16 KiB
download-icon
init the opeartor. 3 years ago
file-icon result2.png
176 KiB
download-icon
init the opeartor. 3 years ago