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

# Annotating Datasets with Labelbox

All successful computer vision projects start with the same thing: LOTS OF LABELED DATA!

In this walkthrough, we’ll cover how to use [the integration](https://voxel51.com/docs/fiftyone/integrations/labelbox.html) between [FiftyOne](https://fiftyone.ai) and the popular annotation tool [Labelbox](https://labelbox.com/) to build a high-quality labeled dataset.

Specifically, this walkthrough covers:

- Using the FiftyOne Brain to select unique samples for annotation
- Annotating unlabeled samples with Labelbox
- Improving existing annotations using FiftyOne tagging and Labelbox
- Additional utilities for managing Labelbox annotation projects

**So, what’s the takeaway?**

FiftyOne Datasets are the best way to explore, understand, and improve your datasets and models. This walkthrough covers how to use our Labelbox integration to streamline the annotation creation and improvement process.

## Setup

To get started, you need to [install FiftyOne](https://voxel51.com/docs/fiftyone/getting_started/install.html) and the [Labelbox Python client](https://github.com/Labelbox/labelbox-python):

You’ll also need to set up a [Labelbox account](https://app.labelbox.com/). FiftyOne supports both standard Labelbox cloud accounts and Labelbox enterprise solutions.

The easiest way to get started is to use the default Labelbox server, which simply requires creating an account and then providing your API key as shown below.

Alternatively, for a more permanent solution, you can store your credentials in your FiftyOne annotation config located at `~/.fiftyone/annotation_config.json`:

See [this page](https://voxel51.com/docs/fiftyone/integrations/labelbox.html#setup) for more advanced Labelbox setup options.

## Raw Data

To start, you need to gather raw image or video data relevant to your task. The internet has a lot of places to look for free data. Assuming you have your raw data downloaded locally, you can [easily load it into FiftyOne](https://voxel51.com/docs/fiftyone/user_guide/import_datasets.html).

Another method is to use publically available datasets that may be relevant. For example, the [Open Images dataset](https://storage.googleapis.com/openimages/web/download.html) contains millions of images available for public use and can be accessed directly through the [FiftyOne Dataset Zoo](https://voxel51.com/docs/fiftyone/user_guide/dataset_zoo/index.html).

Either way, once your data is in FiftyOne, we can [visualize it in the FiftyOne App](https://voxel51.com/docs/fiftyone/user_guide/app.html).

FiftyOne provides a [variety of methods](https://voxel51.com/docs/fiftyone/user_guide/brain.html) that can help you understand the quality of the dataset and pick the best samples to annotate. For example, the ``compute_similarity()` <[https://voxel51.com/docs/fiftyone/user_guide/brain.html#visual-similarity](https://voxel51.com/docs/fiftyone/user_guide/brain.html#visual-similarity)>\`_\_ the method can be used to find both the most similar, and the most unique samples, ensuring that your dataset will contain an even distribution of data.

Now to select only the slice of our dataset that contains the 10 most unique samples.

## Annotation

The [integration between FiftyOne and Labelbox](https://voxel51.com/docs/fiftyone/integrations/labelbox.html) allows you to begin annotating your image or video data by calling a single method!

![labelbox-detection](tutorials/images/labelbox_detection.png)

The annotations can then be [loaded back into FiftyOne](https://voxel51.com/docs/fiftyone/integrations/labelbox.html#loading-annotations) in just one more line.

This API provides [advanced customization options](https://voxel51.com/docs/fiftyone/integrations/labelbox.html#requesting-annotations) for your annotation tasks. For example, we can construct a sophisticated schema to define the annotations we want and even directly assign the annotators:

After you’re finished annotating in Labelbox, you can easily download the results:

## Next Steps

Now that you have a labeled dataset, you can go ahead and start training a model. FiftyOne lets you [export your data to disk in a variety of formats](https://voxel51.com/docs/fiftyone/user_guide/export_datasets.html) (ex: COCO, YOLO, etc) expected by most training pipelines. It also provides workflows for using popular model training libraries like [PyTorch](https://towardsdatascience.com/stop-wasting-time-with-pytorch-datasets-17cac2c22fa8), [PyTorch Lightning
Flash](https://voxel51.com/docs/fiftyone/integrations/lightning_flash.html), and [Tensorflow](https://voxel51.com/docs/fiftyone/user_guide/export_datasets.html#tfobjectdetectiondataset).

Once the model is trained, the [model predictions can be loaded](https://voxel51.com/docs/fiftyone/user_guide/import_datasets.html#adding-model-predictions) back into FiftyOne. These [predictions can then be evaluated against the ground truth](https://voxel51.com/docs/fiftyone/user_guide/evaluation.html) annotations to find where the model is performing well, and where it is performing poorly. This provides insight into the type of samples that need to be added to the training set, as well
as any annotation errors that may exist.

We can use the [powerful querying capabilities of the FiftyOne API](https://voxel51.com/docs/fiftyone/user_guide/using_views.html) to create a [view filtering](https://voxel51.com/docs/fiftyone/user_guide/using_views.html#filtering) these model results by false positives with high confidence which generally indicates an error in the ground truth annotation.

This sample appears to be missing a ground truth annotation of skis. Let’s [tag it in FiftyOne](https://voxel51.com/docs/fiftyone/user_guide/app.html#tags-and-tagging), and send it to Labelbox for reannotation.

The workflow for reannotating an existing label field is to annotate a new field, then merge the new field into the existing field.

Iterating over this process of training a model, evaluating its failure modes, and improving the dataset is the most surefire way to produce high-quality datasets and subsequently high-performing models.

## Additional Utilities

You can perform [additional Labelbox-specific operations](https://voxel51.com/docs/fiftyone/integrations/labelbox.html#additional-utilities) to monitor the progress of an annotation project initiated through this integration with FiftyOne.

For example, you can [view the status of an existing project](https://voxel51.com/docs/fiftyone/integrations/labelbox.html#viewing-project-status):

You can also [delete projects](https://voxel51.com/docs/fiftyone/integrations/labelbox.html#deleting-projects) associated with an annotation run directly through the FiftyOne API.

## Summary

No matter what computer vision projects you are working on, you will need a dataset. [FiftyOne](https://fiftyone.ai) makes it easy to curate and dig into your dataset to understand all aspects of it, including what needs to be annotated or reannotated.

In addition, using our [Labelbox integration](https://voxel51.com/docs/fiftyone/integrations/labelbox.html) can streamline the annotation process and help you build higher quality datasets and models, faster.
