Packages

A BB.Inference runtime that runs TensorFlow Lite models through tflite_elixir.

Current section

Files

Jump to
bb_inference_tflite usage-rules.md
Raw

usage-rules.md

<!--
SPDX-FileCopyrightText: 2026 James Harton

SPDX-License-Identifier: Apache-2.0
-->

# BB.Inference.TFLite Usage Rules

`bb_inference_tflite` is a runtime for [`bb_inference`](https://hexdocs.pm/bb_inference).
See `bb_inference`'s rules for models, codecs and components; this file
covers only what is specific here.

## Core principles

1. **Name it as a model's `runtime`,** never call it directly from a
   component. Components go through `BB.Inference.infer/4`.
2. **It passes raw tensors.** Inputs must already be in the model's types;
   outputs come back in theirs.
3. **`describe/1` is partial.** Check `can?/1` before relying on a field.

## Wiring it in

```elixir
model :detector do
  runtime BB.Inference.TFLite
  source "https://example.com/model"
  sha256 "..."
  codec MyCodec
end
```

## Anti-patterns

- **Relying on quantisation or layout from `describe/1`** where `can?/1`
  says it isn't reported.
- **Converting tensors in the runtime.** Codecs do that, cheaply.

## Further reading

- [Hexdocs](https://hexdocs.pm/bb_inference_tflite)
- `BB.Inference.TFLite`, `BB.Inference.Runtime`