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

<a id="running-inference"></a>

# Running Inference

FiftyOne lets you add model predictions to any dataset or view via
[`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).
Whatever your model produces — classifications, detections, instance or
semantic segmentations, keypoints, heatmaps, and more — is stored directly on
your samples using FiftyOne’s native [`Label`](../../api/fiftyone.core.labels.md#fiftyone.core.labels.Label) types, ready to explore in the
App.

These methods work identically whether the model comes from the
[Model Zoo](../../model_zoo/index.md#model-zoo) or is entirely your own.

<a id="running-inference-zoo"></a>

## Inference with zoo models

The [Model Zoo](../../model_zoo/index.md#model-zoo) provides hundreds of pre-trained models,
spanning detection, classification, segmentation, keypoints, embeddings, and
more, that you can apply to your data in a couple of lines:

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

dataset = foz.load_zoo_dataset("quickstart")

model = foz.load_zoo_model("faster-rcnn-resnet50-fpn-coco-torch")
dataset.apply_model(model, label_field="predictions")

session = fo.launch_app(dataset)
```

<div style="margin:0; display:inline-block;">
    <a href="../../model_zoo/overview.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">See the full recipe for zoo model inference</div>
    </a>
</div>

#### NOTE
Browse or search the [Model Zoo catalog](../../model_zoo/index.md#model-zoo) to find a model
for your task, or work through the
[Model Dataset Zoo Guide](../../getting_started/model_dataset_zoo/index.md#model-dataset-zoo-guide) for a complete,
guided walkthrough.

<a id="running-inference-custom"></a>

## Inference with custom models

If your model isn’t in the zoo, you have two options.

The simplest is to iterate over your dataset and construct the appropriate
[`Label`](../../api/fiftyone.core.labels.md#fiftyone.core.labels.Label) instances yourself. This is the most direct path and requires no
FiftyOne-specific model code.

The more reusable option is to wrap your model so that it implements the
[`Model`](../../api/fiftyone.core.models.md#fiftyone.core.models.Model) interface, at which point it works with
[`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)
exactly like a zoo model. FiftyOne’s
[`TorchImageModel`](../../api/fiftyone.utils.torch.md#fiftyone.utils.torch.TorchImageModel) class makes
this easy for most PyTorch models.

<div style="margin:0; display:inline-block;">
    <a href="../../model_zoo/design.html#model-zoo-custom-models" 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 and custom models</div>
    </a>
</div>

#### NOTE
Did you know? You can also
[register your custom model](../../model_zoo/remote.md#model-zoo-remote) under a name of your
choice so that it can be loaded and shared just like a built-in zoo
model.
