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

video-text-embedding

Video-Text Retrieval Embedding with DRL

author: Chen Zhang


Description

This operator extracts features for video or text with DRL(Disentangled Representation Learning for Text-Video Retrieval), and then it can get the similarity by Weighted Token-wise Interaction (WTI) module.


Code Example

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

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

Write the pipeline in simplified style:

import towhee

towhee.dc(['./demo_video.mp4']) \
    .video_decode.ffmpeg(sample_type='uniform_temporal_subsample', args={'num_samples': 12}) \
    .runas_op(func=lambda x: [y for y in x]) \
    .drl(base_encoder='clip_vit_b32', modality='video', device='cpu') \
    .show()

towhee.dc(['kids feeding and playing with the horse']) \
    .drl(base_encoder='clip_vit_b32', modality='text', device='cpu') \
    .show()


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

import towhee

towhee.dc['path'](['./demo_video.mp4']) \
        .video_decode.ffmpeg['path', 'frames'](sample_type='uniform_temporal_subsample', args={'num_samples': 12}) \
        .runas_op['frames', 'frames'](func=lambda x: [y for y in x]) \
        .drl['frames', 'vec'](base_encoder='clip_vit_b32', modality='video', device='cpu') \
        .show(formatter={'path': 'video_path'})

towhee.dc['text'](['kids feeding and playing with the horse']) \
      .drl['text','vec'](base_encoder='clip_vit_b32', modality='text', device='cpu') \
      .select['text', 'vec']() \
      .show()



Factory Constructor

Create the operator via the following factory method

drl(base_encoder, modality)

Parameters:

base_encoder: str

​ The base CLIP encode name in DRL model. Supported model names:

  • clip_vit_b32

modality: str

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


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.VideoFrame] or str

​ The data (list of 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. When text, the shape is (text_token_num, model_dim), when video, the shape is (video_token_num, model_dim)

ChengZi 015cad44a5 add pth weights 3 Commits
file-icon .gitattributes
1.2 KiB
download-icon
add pth weights 3 years ago
file-icon README.md
2.7 KiB
download-icon
init DRL model 3 years ago
file-icon WTI.png
82 KiB
download-icon
init DRL model 3 years ago
file-icon __init__.py
719 B
download-icon
init DRL model 3 years ago
file-icon clip_vit_b32_wti.pth
388 MiB
download-icon
add pth weights 3 years ago
file-icon demo_video.mp4
950 KiB
download-icon
init DRL model 3 years ago
file-icon drl.py
3.7 KiB
download-icon
init DRL model 3 years ago
file-icon requirements.txt
52 B
download-icon
init DRL model 3 years ago
file-icon vect_explicit_text.png
15 KiB
download-icon
init DRL model 3 years ago
file-icon vect_explicit_video.png
585 KiB
download-icon
init DRL model 3 years ago
file-icon vect_simplified_text.png
18 KiB
download-icon
init DRL model 3 years ago
file-icon vect_simplified_video.png
16 KiB
download-icon
init DRL model 3 years ago