<!-- # hard line break macro for HTML -->

<a id="model-zoo-overview"></a>

# Model Zoo Overview


<div class="available-in">
    <div class="available-in-row">
        <span class="available-in-label">Available in:</span>
        <span class="available-in-pill available-in-pill--oss">Open Source</span><span class="available-in-pill available-in-pill--enterprise">Enterprise</span>
    </div>
    <div class="available-in-row">
        <span class="available-in-versions">Introduced in <a href="../release-notes.html#fiftyone-0-7-0">FiftyOne 0.7.0</a> &middot; <a href="../release-notes.html#fiftyone-enterprise-1-0">FiftyOne Enterprise 1.0</a></span>
    </div>
    
</div>

The FiftyOne Model Zoo provides a powerful interface for downloading models
and applying them to your FiftyOne datasets.

It provides native access to hundreds of pre-trained models, and it also
supports downloading arbitrary public or private models whose definitions are
provided via GitHub repositories or URLs.

## Basic recipe

The basic recipe for working with zoo models is to load one via
[`load_zoo_model()`](../api/fiftyone.zoo.models.md#fiftyone.zoo.models.load_zoo_model) and then
apply it to a dataset or view using methods like
[`apply_model()`](../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.apply_model)
and
[`compute_embeddings()`](../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.compute_embeddings).

Predictions

Embeddings

Logits

You can generate model predictions by passing any zoo model to the
[`apply_model()`](../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.apply_model)
method of a dataset or view.

For example, the code sample below shows a self-contained example of
loading a Faster R-CNN model from the model zoo and adding its predictions
to the [COCO-2017 dataset](../dataset_zoo/datasets/coco_2017.md#dataset-zoo-coco-2017):

```python
import fiftyone as fo
import fiftyone.zoo as foz

# List available zoo models
print(foz.list_zoo_models())

# Download and load a model
model = foz.load_zoo_model("faster-rcnn-resnet50-fpn-coco-torch")

# Load some samples from the COCO-2017 validation split
dataset = foz.load_zoo_dataset(
    "coco-2017",
    split="validation",
    dataset_name="coco-2017-validation-sample",
    max_samples=50,
    shuffle=True,
)

#
# Choose some samples to process. This can be the entire dataset, or a
# subset of the dataset. In this case, we'll choose some samples at
# random
#
samples = dataset.take(25)

#
# Generate predictions for each sample and store the results in the
# `faster_rcnn` field of the dataset, discarding all predictions with
# confidence below 0.5
#
samples.apply_model(model, label_field="faster_rcnn", confidence_thresh=0.5)
print(samples)

# Visualize predictions in the App
session = fo.launch_app(view=samples)
```

Many models in the Model Zoo expose embeddings for their predictions:

```python
import fiftyone.zoo as foz

# Load zoo model
model = foz.load_zoo_model("inception-v3-imagenet-torch")

# Check if model exposes embeddings
print(model.has_embeddings)  # True
```

For models that expose embeddings, you can generate embeddings for all
samples in a dataset or view by calling
[`compute_embeddings()`](../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.compute_embeddings):

```python
import fiftyone.zoo as foz

# Load zoo model
model = foz.load_zoo_model("inception-v3-imagenet-torch")
print(model.has_embeddings)  # True

# Load zoo dataset
dataset = foz.load_zoo_dataset("imagenet-sample")

# Select some samples to process
samples = dataset.take(10)

#
# Option 1: Generate embeddings for each sample and return them in a
# `num_samples x dim` array
#
embeddings = samples.compute_embeddings(model)

#
# Option 2: Generate embeddings for each sample and store them in an
# `embeddings` field of the dataset
#
samples.compute_embeddings(model, embeddings_field="embeddings")
```

You can also use
[`compute_patch_embeddings()`](../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.compute_patch_embeddings)
to generate embeddings for image patches defined by another label field,
e.g,. the detections generated by a detection model.

Many classifiers in the Model Zoo can optionally store logits for their
predictions.

#### NOTE
Storing logits for predictions enables you to run Brain methods such as
[label mistakes](../brain/index.md#brain-label-mistakes) and
[sample hardness](../brain/index.md#brain-sample-hardness) on your datasets!

You can check if a model exposes logits via
[`has_logits()`](../api/fiftyone.core.models.md#fiftyone.core.models.Model.has_logits):

```python
import fiftyone.zoo as foz

# Load zoo model
model = foz.load_zoo_model("inception-v3-imagenet-torch")

# Check if model has logits
print(model.has_logits)  # True
```

For models that expose logits, you can store logits for all predictions
generated by
[`apply_model()`](../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.apply_model)
by passing the optional `store_logits=True` argument:

```python
import fiftyone.zoo as foz

# Load zoo model
model = foz.load_zoo_model("inception-v3-imagenet-torch")
print(model.has_logits)  # True

# Load zoo dataset
dataset = foz.load_zoo_dataset("imagenet-sample")

# Select some samples to process
samples = dataset.take(10)

# Generate predictions and populate their `logits` fields
samples.apply_model(model, store_logits=True)
```

#### NOTE
Zoo models may require additional packages such as PyTorch or TensorFlow
(or specific versions of them) in order to be used. See
[this section](api.md#model-zoo-requirements) for more information on
viewing/installing package requirements for models.

If you try to load a zoo model without the proper packages installed, you
will receive an error message that will explain what you need to install.

Depending on your compute environment, some package requirement failures
may be erroneous. In such cases, you can
[suppress error messages](api.md#model-zoo-load).

## Built-in models

The Model Zoo provides built-in access to hundreds of pre-trained models that
you can apply to your datasets with a few simple commands.

<div style="margin:0; display:inline-block;">
    <a href="index.html" class="sd-btn sd-btn-primary book-a-demo" rel="noopener noreferrer" data-cta-dynamic="true">
        <div class="arrow">
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="size-3">
            <path stroke="currentColor" stroke-width="1.5"
                    d="M1.458 11.995h20.125M11.52 22.063 21.584 12 11.521 1.937"
                    vector-effect="non-scaling-stroke"></path>
            </svg>  
        </div>
        <div class="text">Explore the models in the zoo</div>
    </a>
</div>

## Remotely-sourced models

The Model Zoo also supports downloading and applying models whose definitions
are provided via GitHub repositories or URLs.

<div style="margin:0; display:inline-block;">
    <a href="remote.html" class="sd-btn sd-btn-primary book-a-demo" rel="noopener noreferrer" data-cta-dynamic="true">
        <div class="arrow">
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="size-3">
            <path stroke="currentColor" stroke-width="1.5"
                    d="M1.458 11.995h20.125M11.52 22.063 21.584 12 11.521 1.937"
                    vector-effect="non-scaling-stroke"></path>
            </svg>  
        </div>
        <div class="text">Learn how to download remote models</div>
    </a>
</div>

## Model interface

All models in the Model Zoo are exposed via the [`Model`](../api/fiftyone.core.models.md#fiftyone.core.models.Model) class, which defines a
common interface for loading models and generating predictions with
defined input and output data formats.

<div style="margin:0; display:inline-block;">
    <a href="design.html" class="sd-btn sd-btn-primary book-a-demo" rel="noopener noreferrer" data-cta-dynamic="true">
        <div class="arrow">
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="size-3">
            <path stroke="currentColor" stroke-width="1.5"
                    d="M1.458 11.995h20.125M11.52 22.063 21.584 12 11.521 1.937"
                    vector-effect="non-scaling-stroke"></path>
            </svg>  
        </div>
        <div class="text">Grok the Model interface</div>
    </a>
</div>

#### NOTE
Did you know? You can also pass
[custom models](design.md#model-zoo-custom-models) to methods like
[`apply_model()`](../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.apply_model)
and [`compute_embeddings()`](../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.compute_embeddings)!

## API reference

The Model Zoo can be accessed via the Python library and the CLI. Consult the
API reference below to see how to download, apply, and manage zoo models.

<div style="margin:0; display:inline-block;">
    <a href="api.html" class="sd-btn sd-btn-primary book-a-demo" rel="noopener noreferrer" data-cta-dynamic="true">
        <div class="arrow">
            <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" class="size-3">
            <path stroke="currentColor" stroke-width="1.5"
                    d="M1.458 11.995h20.125M11.52 22.063 21.584 12 11.521 1.937"
                    vector-effect="non-scaling-stroke"></path>
            </svg>  
        </div>
        <div class="text">Check out the API reference</div>
    </a>
</div>
