|
OpenNN
Open-source neural networks library
|
Batch normalization with learnable scale/shift and running statistics for inference. More...
#include <operators.h>
Public Member Functions | |
| bool | active () const |
| Returns true when the operator has been configured (features > 0). | |
| void | set (Index new_features, float new_momentum=0.1f) |
| Configures the per-feature normalization. | |
| vector< TensorSpec > | parameter_specs () const override |
| Returns the tensor specs of trainable parameters owned by this operator. | |
| vector< TensorSpec > | state_specs () const override |
| Returns the tensor specs of persistent state owned by this operator. | |
| void | link_parameters (span< const TensorView > views) override |
| Binds parameter views provided by the hosting layer. | |
| void | link_gradients (span< const TensorView > views) override |
| Binds gradient views provided by the hosting layer. | |
| void | link_states (span< const TensorView > views) override |
| Binds state views provided by the hosting layer. | |
| void | set_parameters_random () override |
| Initializes parameters with random values. | |
| void | set_parameters_glorot () override |
| Initializes parameters using Glorot (Xavier) initialization. | |
| void | init_defaults () |
| Resets gamma to one, beta to zero, and running stats to identity values. | |
| void | forward_propagate (ForwardPropagation &fp, size_t layer, bool is_training) noexcept override |
| Runs the operator's forward computation. | |
| void | back_propagate (ForwardPropagation &fp, BackPropagation &bp, size_t layer) const noexcept override |
| Runs the operator's backward computation, accumulating into gradient/delta buffers. | |
| void | apply_delta (const TensorView &input, const TensorView &mean, const TensorView &inverse_variance, TensorView &delta) const |
| Computes the input gradient given the cached normalization statistics from forward. | |
| void | update_inference_cache () |
| Rebuilds the fused scale/shift cache used by the inference path from running stats. | |
| void | invalidate_inference_cache () |
| Marks the inference cache as stale so it is rebuilt on the next inference call. | |
| void | to_JSON (JsonWriter &w) const override |
| Serializes the operator configuration to a JSON writer. | |
| void | from_JSON (const Json *parent) override |
| Restores the operator configuration from a JSON node. | |
| void | load_state_from_JSON (const Json *parent) override |
| Restores persistent state (e.g. running statistics) from a JSON node. | |
Public Member Functions inherited from opennn::Operator | |
| virtual | ~Operator ()=default |
| virtual void | destroy_cuda () |
| Releases CUDA resources owned by the operator; called from destructors. | |
| TensorView & | get_input (ForwardPropagation &fp, size_t layer, size_t i=0) const noexcept |
| vector< TensorView > & | get_inputs (ForwardPropagation &fp, size_t layer, size_t i=0) const noexcept |
| TensorView & | get_output (ForwardPropagation &fp, size_t layer, size_t i=0) const noexcept |
| TensorView & | get_output_delta (BackPropagation &bp, size_t layer, size_t i=0) const noexcept |
| TensorView & | get_input_delta (BackPropagation &bp, size_t layer, size_t i=0) const noexcept |
Public Attributes | |
| Index | features = 0 |
| float | momentum = 0.1f |
| TensorView | gamma |
| TensorView | beta |
| TensorView | running_mean |
| TensorView | running_variance |
| TensorView | gamma_gradient |
| TensorView | beta_gradient |
Public Attributes inherited from opennn::Operator | |
| vector< size_t > | input_slots = {0} |
| vector< size_t > | output_slots = {1} |
| vector< size_t > | input_delta_slots = {1} |
| vector< size_t > | output_delta_slots = {0} |
Batch normalization with learnable scale/shift and running statistics for inference.
|
inline |
Returns true when the operator has been configured (features > 0).
| void opennn::BatchNormOp::apply_delta | ( | const TensorView & | input, |
| const TensorView & | mean, | ||
| const TensorView & | inverse_variance, | ||
| TensorView & | delta ) const |
Computes the input gradient given the cached normalization statistics from forward.
| input | Forward-pass input tensor. |
| mean | Per-feature mean cached during forward. |
| inverse_variance | Per-feature inverse standard deviation cached during forward. |
| delta | In/out gradient: output_delta on input, input_delta on output. |
|
overridevirtualnoexcept |
Runs the operator's backward computation, accumulating into gradient/delta buffers.
| fp | Forward propagation workspace (read-only). |
| bp | Back propagation workspace receiving gradients and deltas. |
| layer | Index of the hosting layer in the workspace. |
Reimplemented from opennn::Operator.
|
overridevirtualnoexcept |
Runs the operator's forward computation.
| fp | Forward propagation workspace. |
| layer | Index of the hosting layer in the workspace. |
| is_training | If true, enables training-only behavior (e.g. dropout sampling). |
Reimplemented from opennn::Operator.
|
overridevirtual |
Restores the operator configuration from a JSON node.
Reimplemented from opennn::Operator.
| void opennn::BatchNormOp::init_defaults | ( | ) |
Resets gamma to one, beta to zero, and running stats to identity values.
|
inline |
Marks the inference cache as stale so it is rebuilt on the next inference call.
|
overridevirtual |
Binds gradient views provided by the hosting layer.
Reimplemented from opennn::Operator.
|
overridevirtual |
Binds parameter views provided by the hosting layer.
Reimplemented from opennn::Operator.
|
overridevirtual |
Binds state views provided by the hosting layer.
Reimplemented from opennn::Operator.
|
overridevirtual |
Restores persistent state (e.g. running statistics) from a JSON node.
Reimplemented from opennn::Operator.
|
overridevirtual |
Returns the tensor specs of trainable parameters owned by this operator.
Reimplemented from opennn::Operator.
| void opennn::BatchNormOp::set | ( | Index | new_features, |
| float | new_momentum = 0.1f ) |
Configures the per-feature normalization.
| new_features | Number of channels / features to normalize independently. |
| new_momentum | Exponential-moving-average momentum for running statistics. |
|
inlineoverridevirtual |
Initializes parameters using Glorot (Xavier) initialization.
Reimplemented from opennn::Operator.
|
inlineoverridevirtual |
Initializes parameters with random values.
Reimplemented from opennn::Operator.
|
overridevirtual |
Returns the tensor specs of persistent state owned by this operator.
Reimplemented from opennn::Operator.
|
overridevirtual |
Serializes the operator configuration to a JSON writer.
Reimplemented from opennn::Operator.
| void opennn::BatchNormOp::update_inference_cache | ( | ) |
Rebuilds the fused scale/shift cache used by the inference path from running stats.
| TensorView opennn::BatchNormOp::beta |
| TensorView opennn::BatchNormOp::beta_gradient |
| Index opennn::BatchNormOp::features = 0 |
| TensorView opennn::BatchNormOp::gamma |
| TensorView opennn::BatchNormOp::gamma_gradient |
| float opennn::BatchNormOp::momentum = 0.1f |
| TensorView opennn::BatchNormOp::running_mean |
| TensorView opennn::BatchNormOp::running_variance |