emmi_inference.preprocess

Classes

Compose

Chain multiple preprocessing ops.

AddBatch

Insert a batch dimension.

NormalizeAny

Normalize tensors or dicts of tensors using scalar or per-channel stats.

Module Contents

class emmi_inference.preprocess.Compose(*ops)

Chain multiple preprocessing ops.

Each op must be a callable that accepts and returns the same data structure (e.g., a torch.Tensor or a dict[str, torch.Tensor]). Ops that are None are ignored, which makes conditional composition convenient.

Parameters:

ops (object)

ops

A list of callables applied in order.

ops
class emmi_inference.preprocess.AddBatch(dim=0)

Insert a batch dimension.

Works for a single torch.Tensor or a mapping of tensors; in the latter case, the dimension is inserted for every value.

dim

Dimension index at which to insert the batch.

Configure the batch insertion.

Parameters:

dim (int) – Dimension index along which to insert the new batch axis. Defaults to 0.

dim = 0
class emmi_inference.preprocess.NormalizeAny

Normalize tensors or dicts of tensors using scalar or per-channel stats.

This transform supports two modes:

  1. Tensor input: mean/std can be a scalar or 1-D sequences for per-channel normalization. Broadcasting is performed along dim.

  2. Dict input: per_key maps keys to their own NormalizeAny to apply to each value. Keys without a configured normalizer are left unchanged.

mean

Scalar or 1-D sequence of means for tensor normalization. If None, no normalization is applied.

std

Scalar or 1-D sequence of standard deviations matching mean. Zero values are clamped to 1 to avoid division by zero.

per_key

Optional mapping from key to a NormalizeAny applied to dict inputs.

dim

Feature/channel dimension for broadcasting vector stats.

mean: float | collections.abc.Sequence[float] | None = None
std: float | collections.abc.Sequence[float] | None = None
per_key: collections.abc.Mapping[str, NormalizeAny] | None = None
dim: int = -1