TwelveLabs Integration#
FiftyOne integrates with TwelveLabs, whose video foundation models let you embed and caption videos for dataset curation with a few lines of code:
Marengo generates 512-dimensional video embeddings (and matching text embeddings), so you can compute visualizations, build similarity indexes, and run text-to-video searches over your video datasets
Pegasus generates natural-language captions/answers about a video
The models run server-side via the TwelveLabs API, so no local GPU is required.
Setup#
Install the twelvelabs package:
1pip install twelvelabs
You can grab a free API key at twelvelabs.io — there
is a generous free tier. Provide it via the TWELVELABS_API_KEY environment
variable:
1export TWELVELABS_API_KEY=...
or pass it directly via the api_key config parameter when loading the
model.
Video embeddings#
Apply the Marengo embedding model to your video dataset to power visualizations and similarity searches:
1import fiftyone as fo
2import fiftyone.zoo as foz
3import fiftyone.brain as fob
4from fiftyone.utils.twelvelabs import TwelveLabsModel, TwelveLabsModelConfig
5
6dataset = foz.load_zoo_dataset("quickstart-video")
7
8# Load directly
9model = TwelveLabsModel(TwelveLabsModelConfig({"operation": "embed"}))
10
11# Load via zoo
12# model = foz.load_zoo_model(("twelvelabs-marengo3.0")
13
14dataset.compute_embeddings(model, embeddings_field="twelvelabs")
Because Marengo aligns text and video in a shared embedding space, you can build a similarity index and run text-to-video searches:
1index = fob.compute_similarity(
2 dataset,
3 model=model,
4 embeddings="twelvelabs",
5 brain_key="tl_sim",
6)
7
8view = dataset.sort_by_similarity(
9 "a person riding a bike",
10 brain_key="tl_sim",
11 k=10,
12)
13
14session = fo.launch_app(view)
Video captions#
Apply the Pegasus model to caption your videos for curation:
1import fiftyone as fo
2import fiftyone.zoo as foz
3from fiftyone.utils.twelvelabs import TwelveLabsModel, TwelveLabsModelConfig
4
5dataset = foz.load_zoo_dataset("quickstart-video")
6
7# Load directly
8model = TwelveLabsModel(TwelveLabsModelConfig({"operation": "caption"}))
9
10# Load via zoo
11# model = foz.load_zoo_model("twelvelabs-pegasus1.5")
12
13dataset.apply_model(model, label_field="caption")
You can customize the prompt and generation length:
1# Load directly
2model = TwelveLabsModel(
3 TwelveLabsModelConfig(
4 {
5 "operation": "caption",
6 "prompt": "List the main objects that appear in this video.",
7 "max_tokens": 1024,
8 }
9 )
10)
11
12# Load via zoo
13model = foz.load_zoo_model(
14 "twelvelabs-pegasus1.5",
15 prompt="List the main objects that appear in this video.",
16 max_tokens=1024,
17)