Compute Library
 19.08
NEBatchNormalizationLayer Class Reference

Basic function to run NENormalizationLayerKernel and simulate a batch normalization layer. More...

#include <NEBatchNormalizationLayer.h>

Collaboration diagram for NEBatchNormalizationLayer:
[legend]

Public Member Functions

 NEBatchNormalizationLayer ()
 Default constructor. More...
 
void configure (ITensor *input, ITensor *output, const ITensor *mean, const ITensor *var, const ITensor *beta=nullptr, const ITensor *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
 Set the input and output tensors. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const ITensorInfo *mean, const ITensorInfo *var, const ITensorInfo *beta=nullptr, const ITensorInfo *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
 Static function to check if given info will lead to a valid configuration of NEBatchNormalizationLayer. More...
 

Detailed Description

Basic function to run NENormalizationLayerKernel and simulate a batch normalization layer.

Batch normalization is calculated by:

\[ out_i = \gamma * (\frac{in_i - \mu_{B}}{\sqrt{\sigma^2_{B} + \epsilon}}) + \beta \equiv BN_{\gamma,\beta}(in_i) \]

Definition at line 42 of file NEBatchNormalizationLayer.h.

Constructor & Destructor Documentation

◆ NEBatchNormalizationLayer()

Default constructor.

Definition at line 35 of file NEBatchNormalizationLayer.cpp.

36  : _norm_kernel()
37 {
38 }

Member Function Documentation

◆ configure()

void configure ( ITensor input,
ITensor output,
const ITensor mean,
const ITensor var,
const ITensor beta = nullptr,
const ITensor gamma = nullptr,
float  epsilon = 0.001f,
ActivationLayerInfo  act_info = ActivationLayerInfo() 
)

Set the input and output tensors.

Note
If the output tensor is a nullptr or is equal to the input, the batch normalization function will be performed in-place
Parameters
[in,out]inputSource tensor. In case of output tensor = nullptr, this tensor will store the result. 3 lower dimensions represent a single input with dimensions [width, height, FM]. The rest are optional and used for representing batches. Data types supported: F16/F32.
[out]outputDestination tensor. Output will have the same number of dimensions as input. Data type supported: same as input
[in]meanMean values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]varVariance values tensor. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]beta(Optional) Beta values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for beta is 0. Data types supported: Same as input
[in]gamma(Optional) Gamma values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for gamma is 1. Data types supported: Same as input
[in]epsilon(Optional) Small value to avoid division with zero. Default value is 0.001f.
[in]act_info(Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.

Definition at line 40 of file NEBatchNormalizationLayer.cpp.

42 {
43  // Configure kernel
44  _norm_kernel.configure(input, output, mean, var, beta, gamma, epsilon, act_info);
45 }
constexpr float epsilon
void configure(ITensor *input, ITensor *output, const ITensor *mean, const ITensor *var, const ITensor *beta=nullptr, const ITensor *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
Set the input and output tensors.

References arm_compute::test::validation::act_info, NEBatchNormalizationLayerKernel::configure(), and epsilon.

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For NEON kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 54 of file NEBatchNormalizationLayer.cpp.

55 {
56  NEScheduler::get().schedule(&_norm_kernel, Window::DimY);
57 }
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:96

References Window::DimY, Scheduler::get(), and IScheduler::schedule().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const ITensorInfo mean,
const ITensorInfo var,
const ITensorInfo beta = nullptr,
const ITensorInfo gamma = nullptr,
float  epsilon = 0.001f,
ActivationLayerInfo  act_info = ActivationLayerInfo() 
)
static

Static function to check if given info will lead to a valid configuration of NEBatchNormalizationLayer.

Parameters
[in]inputSource tensor info. In case of output tensor = nullptr, this tensor will store the result. 3 lower dimensions represent a single input with dimensions [width, height, FM]. The rest are optional and used for representing batches. Data types supported: F16/F32.
[in]outputDestination tensor info. Output will have the same number of dimensions as input. Data type supported: same as input
[in]meanMean values tensor info. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]varVariance values tensor info. 1 dimension with size equal to the feature maps [FM]. Data types supported: Same as input
[in]beta(Optional) Beta values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for beta is 0. Data types supported: Same as input
[in]gamma(Optional) Gamma values tensor info. 1 dimension with size equal to the feature maps [FM]. If not provided, default value for gamma is 1. Data types supported: Same as input
[in]epsilon(Optional) Small value to avoid division with zero. Default value is 0.001f.
[in]act_info(Optional) Activation layer information in case of a fused activation. Only RELU, BOUNDED_RELU and LU_BOUNDED_RELU supported.
Returns
a status

Definition at line 47 of file NEBatchNormalizationLayer.cpp.

49 {
51  return Status{};
52 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ITensorInfo *mean, const ITensorInfo *var, const ITensorInfo *beta=nullptr, const ITensorInfo *gamma=nullptr, float epsilon=0.001f, ActivationLayerInfo act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of NEBatchNormalizationLaye...
constexpr float epsilon
Status class.
Definition: Error.h:52

References arm_compute::test::validation::act_info, ARM_COMPUTE_RETURN_ON_ERROR, epsilon, and NEBatchNormalizationLayerKernel::validate().


The documentation for this class was generated from the following files: