<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/adding_classifications.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/adding_classifications.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/adding_classifications.ipynb" download>
            <img src="https://cdn.voxel51.com/cloud-icon-256px.png"> &nbsp; Download notebook
        </a>
    </td>
</table>

# Adding Classifier Predictions to a Dataset

This recipe provides a glimpse into the possibilities for integrating FiftyOne into your ML workflows. Specifically, it covers:

- [Loading](https://voxel51.com/docs/fiftyone/user_guide/import_datasets.html) an image classification dataset in FiftyOne
- [Adding classifier predictions](https://voxel51.com/docs/fiftyone/user_guide/using_datasets.html#classification) to a dataset
- Launching the [FiftyOne App](https://voxel51.com/docs/fiftyone/user_guide/app.html) and visualizing/exploring your data
- Integrating the App into your data analysis workflow

## Setup

If you haven’t already, install FiftyOne:

You’ll also need to install `torch` and `torchvision`, if necessary:

In this example, we’ll work with the test split of the CIFAR-10 dataset, which is conveniently available for download from the [FiftyOne Dataset Zoo](https://voxel51.com/docs/fiftyone/user_guide/dataset_zoo/datasets.html#dataset-zoo-cifar10):

We’ll also download a pre-trained CIFAR-10 PyTorch model that we’ll use to generate some predictions:

## Loading an image classification dataset

Suppose you have an image classification dataset on disk in the following format:

```none
<dataset_dir>/
    data/
        <uuid1>.<ext>
        <uuid2>.<ext>
        ...
    labels.json
```

where `labels.json` is a JSON file in the following format:

```none
{
    "classes": [
        <labelA>,
        <labelB>,
        ...
    ],
    "labels": {
        <uuid1>: <target1>,
        <uuid2>: <target2>,
        ...
    }
}
```

In your current workflow, you may parse this data into a list of `(image_path, label)` tuples as follows:

Building a [FiftyOne dataset](https://voxel51.com/docs/fiftyone/user_guide/using_datasets.html) from your samples in this format is simple:

## Working with views

FiftyOne provides a powerful notion of [dataset views](https://voxel51.com/docs/fiftyone/user_guide/using_views.html) that you can use to explore subsets of the samples in your dataset.

Here’s an example operation:

Iterating over the samples in a view is easy:

## Adding model predictions

Now let’s [add our classifier’s predictions](https://voxel51.com/docs/fiftyone/user_guide/using_datasets.html#classification) to our FiftyOne dataset in a new `predictions` field:

We can print our dataset to verify that a `predictions` field has been added to its schema:

Let’s explore the predictions we added by creating a view that sorts the samples in order of prediction confidence:

## Using the FiftyOne App

The [FiftyOne App](https://voxel51.com/docs/fiftyone/user_guide/app.html) allows you easily visualize, explore, search, filter, your datasets.

You can explore the App interactively through the GUI, and you can even interact with it in real-time from your Python interpreter!

You can select samples in the App by clicking on the images. Try it!

After you’ve selected some images in the App, you can hop back over to Python and make a view that contains those samples!
