Normalize
class Normalize<T : DType, V>(ctx: ExecutionContext, val mean: FloatArray, val std: FloatArray, val channelAxis: Int = -1) : TensorTransform<T, V> (source)
Normalizes tensor values using channel-wise mean and standard deviation.
For each channel c: output[c] = (input[c] - mean[c]) / std[c]
This is commonly used for normalizing images to match the statistics of training data (e.g., ImageNet normalization).
Usage
val normalize = Normalize<FP32, Float>(
ctx = executionContext,
mean = floatArrayOf(0.485f, 0.456f, 0.406f),
std = floatArrayOf(0.229f, 0.224f, 0.225f),
channelAxis = 1 // NCHW format
)
val normalizedTensor = normalize.apply(inputTensor)Content copied to clipboard
Parameters
T
The tensor data type
V
The value type
ctx
The execution context for tensor operations
mean
Per-channel mean values to subtract
std
Per-channel standard deviation values to divide by
channelAxis
The axis containing channel information (default: -1 for last axis)