Adapters¶
An adapter wraps a model so the engine can call it on a batch of tiles. Any callable that maps a
[B, 3, h, w] batch to B tuples of (boxes, scores, labels) works as well.
TorchDetector ¶
Bases: Protocol
Callable that runs detection on a batch of tiles.
UltralyticsAdapter ¶
UltralyticsAdapter(
model: Any,
conf: float = 0.25,
iou: float = 0.7,
max_det: int = 300,
classes: list[int] | None = None,
multi_label: bool = False,
half: bool | Literal["auto"] = "auto",
imgsz: int | None = 640,
direct: bool = True,
channels_last: bool | Literal["auto"] = "auto",
compile: bool | Literal["auto"] = "auto",
)
Feed tile batches to an Ultralytics model as tensors, skipping its NumPy path.
Tiles are scaled on-device so the longer side equals imgsz, zero-padded bottom/right to
a stride multiple, and boxes are scaled back to tile pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Weights path/name ( |
required |
conf
|
float
|
Confidence threshold. |
0.25
|
iou
|
float
|
Per-tile NMS IoU threshold. |
0.7
|
max_det
|
int
|
Maximum detections per tile. |
300
|
classes
|
list[int] | None
|
Keep only these class ids. |
None
|
multi_label
|
bool
|
Keep all classes above |
False
|
half
|
bool | Literal['auto']
|
|
'auto'
|
imgsz
|
int | None
|
Longer-side network input size, or |
640
|
direct
|
bool
|
Run the network and decoding directly instead of |
True
|
channels_last
|
bool | Literal['auto']
|
Use |
'auto'
|
compile
|
bool | Literal['auto']
|
|
'auto'
|
at_input_size ¶
This adapter at network input size (longer side), for EASI's
full_frame_size pass. It shares the model and every setting except imgsz and
runs eagerly: one image per call, whose shape changes with the frame's, so a compiled
graph would recompile per shape (and pad the image to the tiles' batch); eager costs
the same there (RTX 3090). Exported models run only at the size they were built
for and raise.
detect_flat ¶
The boxes of __call__ in one piece, (boxes, scores, labels, tile), with
tile each box's index in batch (same boxes, same order). EASI prefers this:
YOLO's batched NMS already has every box's tile, so the per-tile split, its host sync
and the join in :func:~easi.slicing.to_canvas are skipped (0.5 / 2.4 /
9.7 ms less per 1080p / 4K / 8K frame, yolo11n on an RTX 3070). Other heads (RT-DETR,
NMS-free, direct=False) give their per-tile lists joined.
TorchvisionAdapter ¶
TorchvisionAdapter(
model: Module,
score_threshold: float = 0.3,
device: device | str | None = None,
names: dict[int, str] | None = None,
half: bool = False,
)
Wrap a torchvision detection model.
These models normalize and resize internally and return boxes in input pixels, so tiles are passed through unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
e.g. |
required |
score_threshold
|
float
|
Drop detections below this score. |
0.3
|
device
|
device | str | None
|
Move the model here; defaults to wherever it already is. |
None
|
names
|
dict[int, str] | None
|
Optional class id → name map, e.g. from |
None
|
half
|
bool
|
Run the model under FP16 autocast (CUDA; MPS with PyTorch 2.5+): PyTorch's mixed
precision, which keeps precision-sensitive ops (box decoding, softmax) in float32.
Boxes and scores are returned as float32. On the CPU it needs PyTorch 2.3+: with
an older PyTorch, |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|
HuggingFaceAdapter ¶
HuggingFaceAdapter(
model: Any,
processor: Any = None,
conf: float = 0.3,
decode: Literal["processor", "max"] = "processor",
revision: str | None = None,
half: bool = False,
)
Run a transformers object-detection model on tile batches, on the device.
The image processor's resize and normalization are reproduced with tensor ops, so tiles never go through PIL or NumPy. Boxes come back in tile pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
A model id ( |
required |
processor
|
Any
|
The matching image processor; loaded from |
None
|
conf
|
float
|
Score threshold. |
0.3
|
decode
|
Literal['processor', 'max']
|
|
'processor'
|
revision
|
str | None
|
Model revision when loading by id (e.g. |
None
|
half
|
bool
|
Run the model under FP16 autocast (CUDA; MPS with PyTorch 2.5+); decoding stays float32. |
False
|
export_tensorrt ¶
export_tensorrt(
model: str = "yolo11n.pt",
batch: int = 16,
half: bool = True,
imgsz: int = 640,
device: int = 0,
dynamic: bool = False,
) -> str
Export an Ultralytics YOLO model to a TensorRT engine and return its file path.