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)

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)

Constructors

Link copied to clipboard
constructor(ctx: ExecutionContext, mean: FloatArray, std: FloatArray, channelAxis: Int = -1)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
open override fun apply(input: Tensor<T, V>): Tensor<T, V>

Applies this transformation to the given input.

Link copied to clipboard
open override fun toString(): String