32 const float *input_data, [[maybe_unused]]
const Shape &gamma_shape,
33 const float *gamma_data, [[maybe_unused]]
const Shape &beta_shape,
43 assert(output_activation_min <= output_activation_max);
45 for (int32_t batch = 0; batch < batches; batch++)
47 for (int32_t channel = 0; channel < channels; channel++)
50 double square_sum = 0.0f;
51 int32_t
size = heights * widths;
53 for (int32_t height = 0; height < heights; height++)
55 for (int32_t width = 0; width < widths; width++)
57 double input_val = input_data[
Offset(input_shape, batch, height, width, channel)];
59 square_sum += (input_val * input_val);
63 double mean = sum /
size;
64 double var = square_sum /
size - mean * mean;
66 double gamma = gamma_data[channel];
67 double beta = beta_data[channel];
69 double a = gamma / (std::sqrt(var + params.
epsilon));
70 double b = -mean * a + beta;
72 for (int32_t height = 0; height < heights; height++)
74 for (int32_t width = 0; width < widths; width++)
77 double output_value = input_value * a + b;
80 output_activation_max);
void InstanceNorm(const InstanceNormParams ¶ms, const Shape &input_shape, const float *input_data, const Shape &gamma_shape, const float *gamma_data, const Shape &beta_shape, const float *beta_data, const Shape &output_shape, float *output_data)