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

102 lines
2.3 KiB

# Video-Text Retrieval Embedding with BridgeFormer
*author: Jinling Xu*
<br />
## Description
This operator extracts features for video or text with [BridgeFormer](https://arxiv.org/pdf/2201.04850.pdf) which can generate embeddings for text and video by jointly training a video encoder and text encoder to maximize the cosine similarity.
<br />
## Code Example
Load a 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.
- Encode video (default):
```python
2 years ago
from towhee import pipe, ops, DataCollection
p = (
pipe.input('video_path') \
.map('video_path', 'video_frames', ops.video_decode.ffmpeg()) \
.map('video_frames', 'vec', ops.video_text_embedding.bridge_former(model_name='frozen_model', modality='video')) \
.output('video_path', 'video_frames', 'vec')
)
DataCollection(p('./demo_video.mp4')).show()
```
<img src="./video_emb_result.png" width="800px"/>
- Encode text:
```python
2 years ago
from towhee import pipe, ops, DataCollection
p = (
pipe.input('text') \
.map('text', 'vec', ops.video_text_embedding.bridge_former(model_name='frozen_model', modality='text')) \
.output('text', 'vec')
)
DataCollection(p('kids feeding and playing with the horse')).show()
```
<img src="./text_emb_result.png" width="800px"/>
<br />
## Factory Constructor
Create the operator via the following factory method
***bridge_former(model_name, modality, weight_path)***
**Parameters:**
***model_name:*** *str*
​ The model name of frozen in time. Supported model names:
- frozen_model
- clip_initialized_model
***modality:*** *str*
​ Which modality(*video* or *text*) is used to generate the embedding.
***weight_path:*** *str*
​ pretrained model weights path.
<br />
## Interface
An video-text embedding operator takes a list of [Towhee VideoFrame](link/to/towhee/image/api/doc) 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.
3 years ago