peal.data.transformations.Normalization

class peal.data.transformations.Normalization[source]

Bases: object

Per-channel (x - mean) / std normalization with an exact inverse.

mean and std are stored as [C, 1, 1] tensors so the transform broadcasts over [C, H, W] images and [B, C, H, W] batches alike and moves to the input’s device on every call.

Parameters:
  • mean (sequence of float) – Per-channel means.

  • std (sequence of float) – Per-channel standard deviations.

Methods

invert

Undo the normalization.

__init__(mean, std)[source]

Store mean and std as broadcastable [C, 1, 1] tensors.

__call__(sample)[source]

Normalize sample.

Parameters:

sample (torch.Tensor) – Image [C, H, W] or batch [B, C, H, W].

Returns:

(sample - mean) / std with the same shape.

Return type:

torch.Tensor

invert(batch)[source]

Undo the normalization.

Parameters:

batch (torch.Tensor) – Normalized image or batch.

Returns:

batch * std + mean with the same shape.

Return type:

torch.Tensor