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

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

# Inference for Detections

Object detection models label each sample with a [`Detections`](../../api/fiftyone.core.labels.md#fiftyone.core.labels.Detections) field, which
you generate by passing a model to
[`apply_model()`](../../api/fiftyone.core.collections.md#fiftyone.core.collections.SampleCollection.apply_model).
The same field type also covers polygon and instance segmentation output,
since [`Detection`](../../api/fiftyone.core.labels.md#fiftyone.core.labels.Detection) instances can optionally carry a mask.

The Model Zoo includes detectors like Faster R-CNN and the YOLO family, and
the [Object Detection Guide](../../getting_started/object_detection/index.md#detection-guide) walks through applying
both a zoo detector and a custom one to the same 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>

For a custom model, you can either construct [`Detection`](../../api/fiftyone.core.labels.md#fiftyone.core.labels.Detection) instances yourself
in a loop, or configure a
[`TorchImageModel`](../../api/fiftyone.utils.torch.md#fiftyone.utils.torch.TorchImageModel) with a
[`DetectorOutputProcessor`](../../api/fiftyone.utils.torch.md#fiftyone.utils.torch.DetectorOutputProcessor)
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="../../recipes/adding_detections.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 manual-loop recipe for custom detectors</div>
    </a>
</div>
