Skip to content

tenzr::nn::BatchNorm

Batch normalization module over the channel dimension.

#include <norm.h>

Inherits from tenzr::nn::Module

Public Functions

Name
BatchNorm(int64_t num_features, double eps, double momentum, DType dtype)
template <typename T =float>
BatchNorm(int64_t num_features, double eps =1.0e-5, double momentum =0.1)
Construct with the parameter dtype inferred from T.
template <typename T >
BatchNorm(std::type_identity< T > , int64_t num_features, double eps =1.0e-5, double momentum =0.1)
Construct from an explicit std::type_identity dtype tag.
virtual Tensor Forward(const Tensor & input) override
Tensor & Weight()
const Tensor & Weight() const
Tensor & Bias()
const Tensor & Bias() const
const std::vector< float > & RunningMean() const
const std::vector< float > & RunningVar() const
int64_t NumFeatures() const
double Eps() const
double Momentum() const
virtual std::string Name() const override
template <typename T =float>
BatchNorm
Create(int64_t num_features, double eps =1.0e-5, double momentum =0.1)
Static factory mirroring the templated constructor.

Additional inherited members

Public Functions inherited from tenzr::nn::Module

Name
virtual ~Module() =default
Tensor operator()(const Tensor & input)
virtual void Train(bool mode)
void Train()
Switch to training mode.
void Eval()
Switch to evaluation mode.
bool IsTraining() const
Tensor & RegisterParameter(std::string name, Tensor param)
template <typename T ,typename... Args>
std::shared_ptr< T >
RegisterSubmodule(std::string name, Args &&... args)
std::shared_ptr< Module > RegisterSubmodule(std::string name, std::shared_ptr< Module > submod)
std::vector< Tensor > Parameters(bool recurse =true) const
std::unordered_map< std::string, Tensor > NamedParameters(std::string prefix ="", bool recurse =true) const
std::unordered_map< std::string, Tensor > StateDict() const
void LoadStateDict(const std::unordered_map< std::string, Tensor > & state)

Protected Attributes inherited from tenzr::nn::Module

Name
std::unordered_map< std::string, Tensor > parameters_
std::unordered_map< std::string, std::shared_ptr< Module > > submodules_
bool training_

Public Functions Documentation

function BatchNorm

BatchNorm(
    int64_t num_features,
    double eps,
    double momentum,
    DType dtype
)

Parameters:

  • num_features Number of channels.
  • eps Variance epsilon.
  • momentum Running-statistics update momentum.
  • dtype Parameter dtype.
  • num_features Channel count.
  • eps Stabilizing epsilon.
  • momentum Running-statistics update rate.
  • dtype Parameter dtype.

Construct with an explicit runtime dtype. Create a batch normalization over channels of a [N, C, ...] input.

function BatchNorm

template <typename T  =float>
inline explicit BatchNorm(
    int64_t num_features,
    double eps =1.0e-5,
    double momentum =0.1
)

Construct with the parameter dtype inferred from T.

function BatchNorm

template <typename T >
inline explicit BatchNorm(
    std::type_identity< T > ,
    int64_t num_features,
    double eps =1.0e-5,
    double momentum =0.1
)

Construct from an explicit std::type_identity dtype tag.

function Forward

virtual Tensor Forward(
    const Tensor & input
) override

Parameters:

  • input Input of shape (N, C, ...).
  • input Input tensor of shape [N, C, ...].

Return:

  • Normalized tensor with the same shape.
  • Normalized tensor with the same shape.

Reimplements: tenzr::nn::Module::Forward

Normalize input over the channel dimension. Normalize per-channel using batch statistics in training or running statistics otherwise.

function Weight

inline Tensor & Weight()

Return: Mutable reference to the affine weight.

function Weight

inline const Tensor & Weight() const

Return: Const reference to the affine weight.

function Bias

inline Tensor & Bias()

Return: Mutable reference to the affine bias.

function Bias

inline const Tensor & Bias() const

Return: Const reference to the affine bias.

function RunningMean

inline const std::vector< float > & RunningMean() const

Return: Running mean per channel.

function RunningVar

inline const std::vector< float > & RunningVar() const

Return: Running variance per channel.

function NumFeatures

inline int64_t NumFeatures() const

Return: Number of channels.

function Eps

inline double Eps() const

Return: Variance epsilon.

function Momentum

inline double Momentum() const

Return: Running-statistics momentum.

function Name

inline virtual std::string Name() const override

Return: "BatchNorm".

Reimplements: tenzr::nn::Module::Name

function Create

template <typename T  =float>
static inline BatchNorm Create(
    int64_t num_features,
    double eps =1.0e-5,
    double momentum =0.1
)

Static factory mirroring the templated constructor.