# `BB.Estimator.ObjectDetection.Codec`
[🔗](https://github.com/beam-bots/bb_estimator_object_detection/blob/main/lib/bb/estimator/object_detection/codec.ex#L5)

The `:object_detection` task: what a `BB.Inference.ModelCodec` for an
object detector takes and gives, and the one thing it must say beyond the
generic contract.

A detection codec implements both behaviours:

    @behaviour BB.Inference.ModelCodec
    @behaviour BB.Estimator.ObjectDetection.Codec

    @impl BB.Inference.ModelCodec
    def task, do: :object_detection

## Encode

`c:BB.Inference.ModelCodec.encode/2` receives a
`BB.Estimator.ObjectDetection.Codec.Input`: a `{:raw, :I420}` frame and the
minimum score. It prepares the frame with
`BB.Estimator.ObjectDetection.Image.prepare/2` and carries the returned
transform, and the threshold, in its context.

## Decode

`c:BB.Inference.ModelCodec.decode/3` returns every candidate scoring at
least the threshold, as `BB.Message.Vision.Detections.Detection` structs
with boxes in frame pixels (`BB.Estimator.ObjectDetection.Image.to_frame/2`)
and `label: nil`. The estimator adds labels from the model.

Most of a detector's output is below the threshold, so a codec reading a
quantised output dequantises only the values it reads, with
`BB.Inference.Quantisation.value/5`, rather than the whole tensor.

## Non-maximum suppression

`c:nms?/1` says whether the candidates still overlap and need
non-maximum suppression, which the estimator then applies. A model that
ends in its own NMS says `false`.

# `nms?`

```elixir
@callback nms?(state :: term()) :: boolean()
```

Whether the decoded candidates still need non-maximum suppression.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
