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 1 year ago

video-text-embedding

Video-Text Retrieval Embedding with Frozen In Time

author: Jinling Xu


Description

This operator extracts features for video or text with Frozen In Time which can generate embeddings for text and video by jointly training a video encoder and text encoder to maximize the cosine similarity.


Code Example

Load a video from path './demo_video.mp4' to generate a video embedding.

  • Encode video (default):
from towhee import pipe, ops, DataCollection

p = (
    pipe.input('video_path') \
        .map('video_path', 'flame_gen', ops.video_decode.ffmpeg(sample_type='uniform_temporal_subsample', args={'num_samples': 4})) \
        .map('flame_gen', 'flame_list', lambda x: [y for y in x]) \
        .map('flame_list', 'vec', ops.video_text_embedding.frozen_in_time(model_name='frozen_in_time_base_16_244', modality='video', device='cpu')) \
        .output('video_path', 'flame_list', 'vec')
)

DataCollection(p('./demo_video.mp4')).show()

Read the text 'kids feeding and playing with the horse' to generate a text embedding.

  • Encode text:
from towhee import pipe, ops, DataCollection

p = (
    pipe.input('text') \
        .map('text', 'vec', ops.video_text_embedding.frozen_in_time(model_name='frozen_in_time_base_16_244', modality='text', device='cpu')) \
        .output('text', 'vec')
)

DataCollection(p('kids feeding and playing with the horse')).show()


Factory Constructor

Create the operator via the following factory method

frozen_in_time(model_name, modality, weight_path)

Parameters:

model_name: str

​ The model name of frozen in time. Supported model names:

  • frozen_in_time_base_16_244

modality: str

​ Which modality(video or text) is used to generate the embedding.

weight_path: str

​ pretrained model weights path.


Interface

An video-text embedding operator takes a list of Towhee VideoFrame or string as input and generate an embedding in ndarray.

Parameters:

data: List[towhee.types.Image] or str

​ The data (list of Towhee VideoFrame (which is uniform subsampled from a video) or text based on specified modality) to generate embedding.

Returns: numpy.ndarray

​ The data embedding extracted by model.

ChengZi 10abdaf03c rm dc2 in readme 27 Commits
file-icon .gitattributes
1.1 KiB
download-icon
Initial commit 2 years ago
file-icon README.md
2.5 KiB
download-icon
rm dc2 in readme 1 year ago
file-icon __init__.py
755 B
download-icon
push model 2 years ago
file-icon demo_video.mp4
950 KiB
download-icon
add 2 years ago
file-icon frozen_in_time.py
4.8 KiB
download-icon
modify video shape 2 years ago
file-icon frozen_in_time_base_16_224.pth
690 MiB
download-icon
add pth 2 years ago
file-icon parse_config.py
7.0 KiB
download-icon
add2 2 years ago
file-icon requirements.txt
101 B
download-icon
update requirement 2 years ago
file-icon text_emb_result.png
14 KiB
download-icon
update readme with dc2 1 year ago
file-icon video_emb_result.png
30 KiB
download-icon
update readme with dc2 1 year ago