ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PoolingSpec Class Reference

#include <PoolingSpec.h>

Public Member Functions

 PoolingSpec (const ::caffe::PoolingParameter &param)
 
const nncc::core::ADT::tensor::Shapeifm_shape (void) const
 
void ifm_shape (const nncc::core::ADT::tensor::Shape &shape)
 
PoolingMethod method (void) const
 
uint32_t window_height (void) const
 
uint32_t window_width (void) const
 
uint32_t vertical_pad (void) const
 
uint32_t horizontal_pad (void) const
 
uint32_t vertical_stride (void) const
 
uint32_t horizontal_stride (void) const
 
nncc::core::ADT::tensor::Shape ofm_shape (void) const
 

Detailed Description

Definition at line 30 of file PoolingSpec.h.

Constructor & Destructor Documentation

◆ PoolingSpec()

PoolingSpec::PoolingSpec ( const ::caffe::PoolingParameter &  param)

Definition at line 23 of file PoolingSpec.cpp.

23 : _param(param)
24{
25 // DO NOTHING
26}

Member Function Documentation

◆ horizontal_pad()

uint32_t PoolingSpec::horizontal_pad ( void  ) const

Definition at line 87 of file PoolingSpec.cpp.

88{
89 // NOTE The input of Pooling SHOULD BE a rank-4 tensor.
90 // Reference: PoolingLayer<Dtype>::Reshape in pooling_layer.cpp
91 auto raw_padding = build_raw_padding().with(_param);
92 auto spatial_padding = build_spatial_padding(2 /* SPATIAL RANK */).with(raw_padding);
93 return spatial_padding.value(1 /* W */);
94}
SpatialPaddingBuilder build_spatial_padding(uint32_t spatial_rank)
RawPaddingBuilder build_raw_padding(void)
uint32_t & value(uint32_t n)
Definition Padding.h:39
RawPadding with(const ::caffe::ConvolutionParameter &) const
SpatialPadding with(const RawPadding &raw) const

References build_raw_padding(), build_spatial_padding(), PaddingBase< Derived >::value(), RawPaddingBuilder::with(), and SpatialPaddingBuilder::with().

Referenced by ofm_shape().

◆ horizontal_stride()

uint32_t PoolingSpec::horizontal_stride ( void  ) const

Definition at line 111 of file PoolingSpec.cpp.

112{
113 if (_param.has_stride_w())
114 {
115 return _param.stride_w();
116 }
117
118 if (_param.has_stride())
119 {
120 return _param.stride();
121 }
122
123 return 1;
124}

Referenced by ofm_shape().

◆ ifm_shape() [1/2]

void PoolingSpec::ifm_shape ( const nncc::core::ADT::tensor::Shape shape)
inline

Definition at line 37 of file PoolingSpec.h.

37{ _ifm_shape = shape; }

◆ ifm_shape() [2/2]

const nncc::core::ADT::tensor::Shape & PoolingSpec::ifm_shape ( void  ) const
inline

Definition at line 36 of file PoolingSpec.h.

36{ return _ifm_shape; }

Referenced by caffeimport::PoolingBuilder::build().

◆ method()

PoolingMethod PoolingSpec::method ( void  ) const

Definition at line 28 of file PoolingSpec.cpp.

29{
30 if (!_param.has_pool())
31 {
32 // Default pooling method is MAX
33 // Reference: http://caffe.berkeleyvision.org/tutorial/layers/pooling.html
34 return PoolingMethod::Max;
35 }
36
37 std::map<::caffe::PoolingParameter_PoolMethod, PoolingMethod> methods;
38
39 // NOTE STOCHASTIC Pooling is not supported, yet
40 // TODO Support STOCHASTIC Pooling
41 methods[::caffe::PoolingParameter_PoolMethod_MAX] = PoolingMethod::Max;
42 methods[::caffe::PoolingParameter_PoolMethod_AVE] = PoolingMethod::Avg;
43
44 assert(_param.has_pool());
45 return methods.at(_param.pool());
46}

References Avg, and Max.

◆ ofm_shape()

nncc::core::ADT::tensor::Shape PoolingSpec::ofm_shape ( void  ) const

Definition at line 126 of file PoolingSpec.cpp.

127{
129
130 // NOTE Caffe supports only pooling over rank-4 tensor
131 assert(_ifm_shape.rank() == 4);
132 res.resize(4);
133
134 // N (= the number of bacths) SHOULD be same
135 res.dim(0) = _ifm_shape.dim(0);
136 // C (= the number of chaanels) SHOULD be same
137 res.dim(1) = _ifm_shape.dim(1);
138
139 // H and W are derived from IFM, Window, and Padding
140 const auto effective_input_height = _ifm_shape.dim(2) + 2 * vertical_pad() - window_height();
141 const auto effective_input_width = _ifm_shape.dim(3) + 2 * horizontal_pad() - window_width();
142 // TODO Remove the following asserts
143 assert(effective_input_height % vertical_stride() == 0);
144 assert(effective_input_width % horizontal_stride() == 0);
145 res.dim(2) = effective_input_height / vertical_stride() + 1;
146 res.dim(3) = effective_input_width / horizontal_stride() + 1;
147 return res;
148}
uint32_t window_height(void) const
uint32_t vertical_pad(void) const
uint32_t horizontal_pad(void) const
uint32_t window_width(void) const
uint32_t vertical_stride(void) const
uint32_t horizontal_stride(void) const
uint32_t & dim(uint32_t axis)
Definition Shape.cpp:42
Shape & resize(uint32_t size)
Definition Shape.cpp:36
uint32_t rank(void) const
Definition Shape.cpp:35

References nncc::core::ADT::tensor::Shape::dim(), horizontal_pad(), horizontal_stride(), nncc::core::ADT::tensor::Shape::rank(), nncc::core::ADT::tensor::Shape::resize(), vertical_pad(), vertical_stride(), window_height(), and window_width().

◆ vertical_pad()

uint32_t PoolingSpec::vertical_pad ( void  ) const

Definition at line 78 of file PoolingSpec.cpp.

79{
80 // NOTE The input of Pooling SHOULD BE a rank-4 tensor.
81 // Reference: PoolingLayer<Dtype>::Reshape in pooling_layer.cpp
82 auto raw_padding = build_raw_padding().with(_param);
83 auto spatial_padding = build_spatial_padding(2 /* SPATIAL RANK */).with(raw_padding);
84 return spatial_padding.value(0 /* H */);
85}

References build_raw_padding(), build_spatial_padding(), PaddingBase< Derived >::value(), RawPaddingBuilder::with(), and SpatialPaddingBuilder::with().

Referenced by ofm_shape().

◆ vertical_stride()

uint32_t PoolingSpec::vertical_stride ( void  ) const

Definition at line 96 of file PoolingSpec.cpp.

97{
98 if (_param.has_stride_h())
99 {
100 return _param.stride_h();
101 }
102
103 if (_param.has_stride())
104 {
105 return _param.stride();
106 }
107
108 return 1;
109}

Referenced by ofm_shape().

◆ window_height()

uint32_t PoolingSpec::window_height ( void  ) const

Definition at line 48 of file PoolingSpec.cpp.

49{
50 // NOTE Global pooling is not supported, yet
51 // TODO Support global pooling
52 assert(!_param.global_pooling());
53
54 if (_param.has_kernel_h())
55 {
56 return _param.kernel_h();
57 }
58
59 assert(_param.has_kernel_size());
60 return _param.kernel_size();
61}

Referenced by ofm_shape().

◆ window_width()

uint32_t PoolingSpec::window_width ( void  ) const

Definition at line 63 of file PoolingSpec.cpp.

64{
65 // NOTE Global pooling is not supported, yet
66 // TODO Support global pooling
67 assert(!_param.global_pooling());
68
69 if (_param.has_kernel_w())
70 {
71 return _param.kernel_w();
72 }
73
74 assert(_param.has_kernel_size());
75 return _param.kernel_size();
76}

Referenced by ofm_shape().


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