FiftyOne Computer Vision Tips and Tricks - March 8, 2024
Tags: computervision, ai, machinelearning, datascience
Published: 2024-03-08 15:30:00

Welcome to our weekly FiftyOne tips and tricks blog where we recap interesting questions and answers that have recently popped up on [Slack](https://join.slack.com/t/fiftyone-users/shared_invite/zt-s6936w7b-2R5eVPJoUw008wP7miJmPQ), [GitHub](https://github.com/voxel51/fiftyone), Stack Overflow, and Reddit.

As an open source community, the FiftyOne community is open to all. This means everyone is welcome to ask questions, and everyone is welcome to answer them. Continue reading to see the latest questions asked and answers provided!

## Wait, what’s FiftyOne?

[FiftyOne](https://voxel51.com/fiftyone/) is an open source machine learning toolset that enables data science teams to improve the performance of their computer vision models by helping them curate high quality datasets, evaluate models, find mistakes, visualize embeddings, and get to production faster.

{% embed https://player.vimeo.com/video/826021982?h=c8c3ff0632&amp;color=ED7630&amp %}

- If you like what you see on GitHub, [give the project a star](https://github.com/voxel51/fiftyone).
- [Get started](https://voxel51.com/docs/fiftyone/index.html)! We’ve made it easy to get up and running in a few minutes.
- Join the FiftyOne [Slack community](https://join.slack.com/t/fiftyone-users/shared_invite/zt-s6936w7b-2R5eVPJoUw008wP7miJmPQ), we’re always happy to help.

Ok, let’s dive into this week’s tips and tricks!

## Extracting the SimilarityIndex

Community Slack member Rafi asked:

> Suppose I've computed similarity using fob, for instance:

```
results = fob.compute_similarity(
    dataset,
    embeddings="embedding",
    brain_key="sim",
    metric="cosine",
)
```

> If I aim to later extract the `SimilarityIndex` using the `brain_key`, how can I achieve this?

This should be straight-forward when you use:

```
results = dataset.load_brain_results(brain_key)
```
Learn more about the [FiftyOne Brain’s “similarity” features](https://docs.voxel51.com/user_guide/brain.html?highlight=brain#brain-similarity) in the Docs.

## Applying prediction labels to video samples

Community Slack member ZKW asked:

> Can I apply prediction labels to video samples and display the video with dynamic labels (like moving a bbox) in FiftyOne App?

Check out the [“Video Labels – FiftyOne Tips and Tricks”](https://voxel51.com/blog/computer-vision-video-labels-fiftyone-tips-and-tricks-october-14th-2023/) blog. Frame level detections allow you to apply detection labels to a video, in case the bounding_boxes move as the objects move when the video is displayed. The relevant snippet is below:

```
dataset.ensure_frames()
sample.frames
```
The “identity” of boxes are preserved across frames via the `index` attribute.

## Modifying sample fields in batches

Community Slack member Clement asked:

> I am looking for a clever way to modify a batch of sample fields all at once, based on their Ids. Specifically, I want to modify a particular bounding box in a frame. What’s the most best way to go about this in FiftyOne?

You'll want to take a look at the [“Setting Values”](https://docs.voxel51.com/user_guide/using_datasets.html#setting-values) section of the Docs. Using `dataset.values()` and `dataset.set_values() `is the recommended way to retrieve and set up large amounts of field elements at a single time across your dataset.

For example, getting a dictionary mapping sample id to field value for each sample can be done with:

```
d = zip(*dataset.values(["id", "my_field"]))
```
Then check out `set_values()` [in the Docs](https://docs.voxel51.com/api/fiftyone.core.collections.html#fiftyone.core.collections.SampleCollection.set_label_values) for how to add new fields or update existing fields similarly.

## Rendering Alpha Matts

Community Slack member Shuo asked:

> I have prepared an ImageSegmentationDirectory and successfully imported it, but alpha matts are rendered as binary masks. See the screenshot below. How can I achieve the desired results?

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gllfd3jkqekzqtb6dpx.png)

Use the Heatmap label. The [Segmentation](https://docs.voxel51.com/api/fiftyone.core.labels.html#fiftyone.core.labels.Segmentation) label will be rendered as a binary mask while the [Heatmap](https://docs.voxel51.com/api/fiftyone.core.labels.html#fiftyone.core.labels.Heatmap) label will render an alpha matt. Once you have the heatmap in FiftyOne, try playing around with the [opacity of labels](https://docs.voxel51.com/user_guide/app.html#color-schemes-in-the-app) in the FiftyOne App!

## Clipping Video Samples

Community Slack member Daniel asked:

> I have a video sample with 18,000 frames and I want to copy the first 9,000 to another sample. How can I accomplish this?

If you are working with FFMPEG and want to add frames or modify the actual video files, It may be easy to retrieve the  file names and do the editing programmatically with FiftyOne. Check out the [“Clips Views”](https://docs.voxel51.com/user_guide/using_views.html#video-views) section of the Docs. 

You can use `to_clips()` to create views into your video datasets that contain one sample per clip defined by a specific field or expression in a video collection.

For example, if you have temporal detection labels on your dataset, then you can create a clips view that contains one sample per temporal segment by simply passing the name of the temporal detection field to `to_clips()`.