Compute Library
 21.02
NEInstanceNormalizationLayer Class Reference

Basic function to perform a Instance normalization. More...

#include <NEInstanceNormalizationLayer.h>

Collaboration diagram for NEInstanceNormalizationLayer:
[legend]

Public Member Functions

 NEInstanceNormalizationLayer (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Constructor. More...
 
 NEInstanceNormalizationLayer (const NEInstanceNormalizationLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEInstanceNormalizationLayeroperator= (const NEInstanceNormalizationLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEInstanceNormalizationLayer (NEInstanceNormalizationLayer &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
NEInstanceNormalizationLayeroperator= (NEInstanceNormalizationLayer &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
 ~NEInstanceNormalizationLayer ()
 Default destructor. More...
 
void configure (ITensor *input, ITensor *output, float gamma=1.0f, float beta=0.0f, float epsilon=1e-12f)
 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, float gamma=1.0f, float beta=0.0f, float epsilon=1e-12f)
 Static function to check if given info will lead to a valid configuration of NEInstanceNormalizationLayer. More...
 

Detailed Description

Basic function to perform a Instance normalization.

This function runs the following kernels:

  1. NEInstanceNormalizationLayerKernel

Definition at line 46 of file NEInstanceNormalizationLayer.h.

Constructor & Destructor Documentation

◆ NEInstanceNormalizationLayer() [1/3]

NEInstanceNormalizationLayer ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Constructor.

Definition at line 35 of file NEInstanceNormalizationLayer.cpp.

36  : _memory_group(std::move(memory_manager)), _normalization_kernel(), _is_nchw(false), _permute_input(), _permute_output(), _permuted_input(), _permuted_output()
37 {
38 }

◆ NEInstanceNormalizationLayer() [2/3]

Prevent instances of this class from being copied (As this class contains pointers)

◆ NEInstanceNormalizationLayer() [3/3]

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ ~NEInstanceNormalizationLayer()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( ITensor input,
ITensor output,
float  gamma = 1.0f,
float  beta = 0.0f,
float  epsilon = 1e-12f 
)

Set the input and output tensors.

Parameters
[in,out]inputSource tensor. In case of output tensor = nullptr this tensor will store the result of the normalization. Data types supported: F16/F32. Data layout supported: NHWC, NCHW
[out]outputDestination tensor. Data types and data layouts supported: same as input.
[in]gamma(Optional) The scale scalar value applied to the normalized tensor. Defaults to 1.0
[in]beta(Optional) The offset scalar value applied to the normalized tensor. Defaults to 0.0
[in]epsilon(Optional) Lower bound value for the normalization. Defaults to 1e-12

Definition at line 40 of file NEInstanceNormalizationLayer.cpp.

References TensorAllocator::allocate(), Tensor::allocator(), NEPermute::configure(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), arm_compute::quantization::epsilon, ITensor::info(), Tensor::info(), MemoryGroup::manage(), arm_compute::NCHW, ITensorInfo::set_data_layout(), and arm_compute::U.

41 {
42  const DataLayout data_layout = input->info()->data_layout();
43  const auto kernel_descriptor = InstanceNormalizationLayerKernelInfo{ gamma, beta, epsilon, true };
44 
45  // Configure Kernels
46  _is_nchw = data_layout == DataLayout::NCHW;
47 
48  _normalization_kernel = std::make_unique<NEInstanceNormalizationLayerKernel>();
49 
50  if(!_is_nchw)
51  {
52  _memory_group.manage(&_permuted_input);
53  _memory_group.manage(&_permuted_output);
54 
55  // Configure the function to transform the input tensor from NHWC -> NCHW
56  _permute_input.configure(input, &_permuted_input, PermutationVector(1U, 2U, 0U));
57  _permuted_input.info()->set_data_layout(DataLayout::NCHW);
58 
59  _normalization_kernel->configure(&_permuted_input, &_permuted_output, kernel_descriptor);
60  _permuted_output.info()->set_data_layout(DataLayout::NCHW);
61 
62  _permute_output.configure(&_permuted_output, output != nullptr ? output : input, PermutationVector(2U, 0U, 1U));
63  _permuted_input.allocator()->allocate();
64  _permuted_output.allocator()->allocate();
65  }
66  else
67  {
68  _normalization_kernel->configure(input, output, kernel_descriptor);
69  }
70 }
Strides PermutationVector
Permutation vector.
Definition: Types.h:49
const DataLayout data_layout
Definition: Im2Col.cpp:151
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
ITensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: Tensor.cpp:33
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
virtual ITensorInfo & set_data_layout(const DataLayout &data_layout)=0
Set the data layout of the tensor.
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
Num samples, channels, height, width.
void configure(const ITensor *input, ITensor *output, const PermutationVector &perm)
Configure the permute Neon kernel.
Definition: NEPermute.cpp:49
DataLayout
[DataLayout enum definition]
Definition: Types.h:120

◆ operator=() [1/2]

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ 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 79 of file NEInstanceNormalizationLayer.cpp.

References Window::DimZ, Scheduler::get(), NEPermute::run(), and IScheduler::schedule().

80 {
81  MemoryGroupResourceScope scope_mg(_memory_group);
82 
83  // Permute input
84  if(!_is_nchw)
85  {
86  _permute_input.run();
87  }
88 
89  NEScheduler::get().schedule(_normalization_kernel.get(), Window::DimZ);
90 
91  // Permute output
92  if(!_is_nchw)
93  {
94  _permute_output.run();
95  }
96 }
void run() override
Run the kernels contained in the function.
Definition: NEPermute.cpp:67
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
float  gamma = 1.0f,
float  beta = 0.0f,
float  epsilon = 1e-12f 
)
static

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

Parameters
[in]inputSource tensor info. Data types supported: F16/F32. Data layout supported: NHWC, NCHW
[in]outputDestination tensor info. Data types and data layouts supported: same as input.
[in]gamma(Optional) The scale scalar value applied to the normalized tensor. Defaults to 1.0
[in]beta(Optional) The offset scalar value applied to the normalized tensor. Defaults to 0.0
[in]epsilon(Optional) Lower bound value for the normalization. Defaults to 1e-12
Returns
a status

Definition at line 72 of file NEInstanceNormalizationLayer.cpp.

References ICloneable< T >::clone(), arm_compute::quantization::epsilon, arm_compute::NCHW, and NEInstanceNormalizationLayerKernel::validate().

73 {
74  return NEInstanceNormalizationLayerKernel::validate(&input->clone()->set_data_layout(DataLayout::NCHW),
75  &output->clone()->set_data_layout(DataLayout::NCHW),
76  InstanceNormalizationLayerKernelInfo{ gamma, beta, epsilon, true });
77 }
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const InstanceNormalizationLayerKernelInfo &info)
Static function to check if given info will lead to a valid configuration of NEInstanceNormalizationL...
Num samples, channels, height, width.

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