Skip to main content

ClikaRT::nn::InstanceNorm

class

Header: ClikaRT/nn/instance_norm.h
Inherits: ClikaRT::nn::Module

Instance normalization.

y=x−μσ2+ε⋅weight+biasy = \frac{x - \mu}{\sqrt{\sigma^2 + \varepsilon}} \cdot \mathrm{weight} + \mathrm{bias}

with mu / sigma^2 taken per (sample, channel) over the spatial dimensions, or per channel from the stored statistics when the module tracks them. The channel axis is the last one. The module form of ops::instance_norm.

auto norm = ClikaRT::nn::InstanceNorm::make(64, {.affine = true});
norm->set_weights(gamma, beta);
auto y = (*norm)(x); // [N, H, W, 64] -> [N, H, W, 64]

Static member functions​

make()​

static std::shared_ptr<InstanceNorm> make(std::int64_t num_features, InstanceNormOptions options = {})

Construct from config with storage-free slots: registers the [num_features] parameter slots (weight, bias, when options.affine) and, when options.track_running_stats, the running_mean / running_var buffer slots plus the num_batches_tracked counter, on options.dtype / options.device; no weight memory is allocated. The first forward builds. Raises ClikaRT::Error on a channel count or eps that is not positive.

Declared in ClikaRT/nn/instance_norm.h, line 93

Member functions​

set_weights()​

void set_weights(Tensor weight, OptionalTensor bias = {})

Bind the affine parameters positionally: weight (scale, [C]) and bias (shift, [C]). The declared placement wins; shapes must match the declaration; the next forward rebuilds. Raises ClikaRT::Error on a geometry mismatch or on a module made with affine = false.

Declared in ClikaRT/nn/instance_norm.h, line 103

set_running_stats()​

void set_running_stats(Tensor running_mean, Tensor running_var)

Bind the statistics positionally: running_mean and running_var, both [C]. Raises ClikaRT::Error on a geometry mismatch or on a module made without track_running_stats.

Declared in ClikaRT/nn/instance_norm.h, line 111

~InstanceNorm()​

~InstanceNorm() override

Declared in ClikaRT/nn/instance_norm.h, line 115

to_impl(StreamOrDevice)​

virtual Result<void> to_impl(StreamOrDevice where) override

Move to a placement (Device / Stream) or cast to a dtype. Rebuilds over the moved slots on the next forward.

Declared in ClikaRT/nn/instance_norm.h, line 119

to_impl(DataType)​

virtual Result<void> to_impl(DataType dtype) override

Declared in ClikaRT/nn/instance_norm.h, line 120

forward()​

Tensor forward(Tensor input) const

Normalizes input [N, D1..Dn, C] per sample and channel (or with the stored statistics), applies the affine parameters when declared and the fused activation when set; output shape and dtype follow input. The first call builds (once, thread-safe). Raises ClikaRT::Error when a slot is still unbound or the channel count does not match.

Declared in ClikaRT/nn/instance_norm.h, line 129

operator()()​

Tensor operator()(Tensor input) const

Same as forward.

Declared in ClikaRT/nn/instance_norm.h, line 133

num_features()​

std::int64_t num_features() const noexcept

The channel count the module was made with.

Declared in ClikaRT/nn/instance_norm.h, line 138

options()​

const InstanceNormOptions& options() const noexcept

The settings the module was made with.

Declared in ClikaRT/nn/instance_norm.h, line 140

Protected member functions​

initialize_impl()​

virtual Result<void> initialize_impl() override

The pack hook (Module::initialize_impl): builds the normalization over the bound slots (idempotent, thread-safe). Every declared slot must hold a real (loaded) tensor; a still-unbound slot is a clean error naming it.

Declared in ClikaRT/nn/instance_norm.h, line 151