<table class="fo-notebook-links" align="left">
    <td>
        <a target="_blank" href="https://colab.research.google.com/github/voxel51/fiftyone/blob/main/docs/source/getting_started/annotation/03_smart_selection.ipynb">
            <img src="https://cdn.voxel51.com/colab-logo-256px.png"> &nbsp; Run in Google Colab
        </a>
    </td>
    <td>
        <a target="_blank" href="https://github.com/voxel51/fiftyone/blob/main/docs/source/getting_started/annotation/03_smart_selection.ipynb">
            <img src="https://cdn.voxel51.com/github-logo-256px.png"> &nbsp; View source on GitHub
        </a>
    </td>
    <td>
        <a target="_blank" href="https://raw.githubusercontent.com/voxel51/fiftyone/main/docs/source/getting_started/annotation/03_smart_selection.ipynb" download>
            <img src="https://cdn.voxel51.com/cloud-icon-256px.png"> &nbsp; Download notebook
        </a>
    </td>
</table>

# Step 3: Smart Sample Selection

Random sampling wastes labels on redundant near-duplicates. This step uses **diversity-based selection** to pick high-value scenes that cover your data distribution efficiently.

We’ll use **ZCore (Zero-Shot Coreset Selection)** to score samples based on:

- **Coverage**: How much of the embedding space does this sample represent?
- **Redundancy**: How many near-duplicates exist?

High ZCore score = valuable for labeling. Low score = redundant, skip it.

> **Note:** For grouped datasets, we compute embeddings on the **left camera slice** and select at the **group level** (scene).

## Compute Embeddings on Left Camera Slice

For diversity selection, we need embeddings. We compute them on the **left camera images** since that is our primary 2D annotation target.

> **Dependencies:** This step requires `torch` and `umap-learn`. Install them if needed:

> ```bash
> pip install torch torchvision umap-learn
> ```

## ZCore: Zero-Shot Coreset Selection

ZCore scores each sample by iteratively:

1. Sampling random points in embedding space
2. Finding the nearest data point (coverage bonus)
3. Penalizing nearby neighbors (redundancy penalty)

The result: samples covering unique regions score high; redundant samples score low.

## Select at the Group Level

We computed scores on individual samples (left camera), but we need to select **groups** (scenes). Each group includes all slices (left, right, pcd).

Selection strategy: Use the ZCore score from the left camera sample to rank groups.

In the App:

1. Open the **Embeddings** panel to see the 2D projection
2. Color by `zcore` to see score distribution
3. Filter by `batch:v0` tag to see selected groups
4. Verify high-ZCore samples are spread across clusters (good coverage)

![Embeddings panel with ZCore scores](https://cdn.voxel51.com/getting_started_annotation/notebook3/embeddings_zcore.webp)

## Why Diversity Sampling Beats Random

| Method     | What it does                    | Result                                        |
|------------|---------------------------------|-----------------------------------------------|
| **Random** | Picks samples uniformly         | Over-samples dense regions, misses rare cases |
| **ZCore**  | Balances coverage vs redundancy | Maximizes diversity, fewer wasted labels      |

Research shows diversity-based selection can significantly reduce labeling requirements while maintaining model performance.

## Summary

You selected a diverse batch using ZCore:

- Computed embeddings on **left camera slice**
- Ran ZCore to score coverage vs redundancy
- Selected top-scoring **groups** (scenes)
- Tagged all slices (left, right, pcd) for annotation

**Artifacts:**

- `embeddings` field on left camera samples
- `zcore` field with selection scores
- `batch_v0` saved view (all slices for selected groups)
- Tags: `batch:v0`, `to_annotate`

**Next:** Step 4 - 2D Annotation + QA
