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

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

# Inference for Segmentations

Semantic segmentation models label each sample with a [`Segmentation`](../../api/fiftyone.core.labels.md#fiftyone.core.labels.Segmentation) field,
while instance segmentation output is stored as a [`Detections`](../../api/fiftyone.core.labels.md#fiftyone.core.labels.Detections) field whose
[`Detection`](../../api/fiftyone.core.labels.md#fiftyone.core.labels.Detection) instances carry per-object masks. Both are populated by passing
a model to
[`apply_model()`](../../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.apply_model).

The [Segmentation Guide](../../getting_started/segmentation/index.md#segmentation-guide) walks through applying a
zoo model — Segment Anything 2 — to generate segmentations from prompts.

<div style="margin:0; display:inline-block;">
    <a href="../../getting_started/segmentation/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">Work through the Segmentation Guide</div>
    </a>
</div>

For a custom model, configure a
[`TorchImageModel`](../../api/fiftyone.utils.torch.md#fiftyone.utils.torch.TorchImageModel) with an
[`InstanceSegmenterOutputProcessor`](../../api/fiftyone.utils.torch.md#fiftyone.utils.torch.InstanceSegmenterOutputProcessor)
or
[`SemanticSegmenterOutputProcessor`](../../api/fiftyone.utils.torch.md#fiftyone.utils.torch.SemanticSegmenterOutputProcessor)
so it works with `apply_model()` directly, as described in
[Inference with custom models](index.md#running-inference-custom).

<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>
