<table class="fo-notebook-links" align="left">
    <td>
        <a target="_blank" href="https://colab.research.google.com/github/voxel51/fiftyone/blob/main/docs/source/recipes/draw_labels.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/recipes/draw_labels.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/recipes/draw_labels.ipynb" download>
            <img src="https://cdn.voxel51.com/cloud-icon-256px.png"> &nbsp; Download notebook
        </a>
    </td>
</table>

# Drawing Labels on Samples

This recipe demonstrates how to use FiftyOne to render annotated versions of image and video [samples](https://voxel51.com/docs/fiftyone/user_guide/using_datasets.html#samples) with their [label field(s)](https://voxel51.com/docs/fiftyone/user_guide/using_datasets.html#labels) overlaid.

## Setup

If you haven’t already, install FiftyOne:

In this recipe we’ll use the [FiftyOne Dataset Zoo](https://docs.voxel51.com/dataset_zoo/index.html) to download some labeled datasets to use as sample data for drawing labels.

Behind the scenes, FiftyOne uses either the [TensorFlow Datasets](https://www.tensorflow.org/datasets) or [TorchVision Datasets](https://pytorch.org/vision/stable/datasets.html) libraries to wrangle the datasets, depending on which ML library you have installed.

You can, for example, install PyTorch as follows (we’ll also need `pycocotools` to load the COCO dataset, in particular):

## Drawing COCO detections

You can download the validation split of the COCO-2017 dataset to `~/fiftyone/coco-2017/validation` by running the following command:

Now let’s load the dataset, extract a [DatasetView](https://voxel51.com/docs/fiftyone/user_guide/using_datasets.html#datasetviews) that contains 100 images from the dataset, and render them as annotated images with their ground truth labels overlaid:

Let’s list the output directory to verify that the annotations have been generated:

Here’s an example of an annotated image that was generated:

![coco-2017-annotated](recipes/images/draw_labels_coco2017.jpg)

## Drawing Caltech 101 classifications

You can download the test split of the Caltech 101 dataset to `~/fiftyone/caltech101/test` by running the following command:

Now let’s load the dataset, extract a [DatasetView](https://voxel51.com/docs/fiftyone/user_guide/using_datasets.html#datasetviews) that contains 100 images from the dataset, and render them as annotated images with their ground truth labels overlaid:

Let’s list the output directory to verify that the annotations have been generated:

Here’s an example of an annotated image that was generated:

![06292a73545146efa783bf21c83590ac](recipes/images/draw_labels_caltech101.jpg)

## Drawing labels on videos

FiftyOne can also render frame labels onto video samples.

To demonstrate, let’s work with the (small) video quickstart dataset from the zoo:

Note that the dataset contains frame-level detections in the `objs` field of each frame.

Let’s make a [DatasetView](https://voxel51.com/docs/fiftyone/user_guide/using_datasets.html#datasetviews) that contains a couple random videos from the dataset and render them as annotated videos with the frame-level detections overlaid:

Let’s list the output directory to verify that the annotations have been generated:

Here’s a snippet of an annotated video that was generated:

![quickstart-video-annotated](recipes/images/draw_labels_quickstart_video.gif)

## Cleanup

You can cleanup the files generated by this recipe by running the command below:
