ONE - On-device Neural Engine
Loading...
Searching...
No Matches
arm_compute::misc::shape_calculator Namespace Reference

Functions

TensorShape compute_transposeconv_upsampled_shape (const ITensorInfo &input, const ITensorInfo &weights, const PadStrideInfo &info, std::pair< unsigned int, unsigned int > &out_dims, unsigned int invalid_right, unsigned int invalid_bottom, unsigned int &pad_left, unsigned int &pad_right, unsigned int &pad_top, unsigned int &pad_bottom)
 
TensorShape compute_transposeconv_output_shape (const std::pair< unsigned int, unsigned int > &out_dims, const ITensorInfo &input, const ITensorInfo &weights)
 
TensorShape compute_depth_to_space_shape_ex (const ITensorInfo *input, int block)
 
TensorShape compute_space_to_depth_shape_ex (const ITensorInfo *input, int32_t block_shape)
 
TensorShape compute_gather_shape_ex (const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)
 
TensorShape compute_onehot_shape_ex (const TensorShape &indices_shape, uint32_t depth, uint32_t actual_axis)
 

Function Documentation

◆ compute_depth_to_space_shape_ex()

TensorShape arm_compute::misc::shape_calculator::compute_depth_to_space_shape_ex ( const ITensorInfo *  input,
int  block 
)
inline

Calculate the depth to space output shape of a tensor

Parameters
[in]inputInput tensor info
[in]blockBlock shape value
Returns
the calculated shape

Definition at line 155 of file ShapeCalculatorEx.h.

156{
157 ARM_COMPUTE_ERROR_ON(block < 2);
158
159 const DataLayout data_layout = input->data_layout();
160 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
161 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
162 const int idx_channel =
163 get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
164
165 TensorShape output_shape{input->tensor_shape()};
166 output_shape.set(idx_width, input->dimension(idx_width) * block);
167 output_shape.set(idx_height, input->dimension(idx_height) * block);
168 output_shape.set(idx_channel, input->dimension(idx_channel) / (block * block));
169
170 return output_shape;
171}
const luci_interpreter::RuntimeShape output_shape

References output_shape.

◆ compute_gather_shape_ex()

TensorShape arm_compute::misc::shape_calculator::compute_gather_shape_ex ( const TensorShape &  input_shape,
const TensorShape &  indices_shape,
uint32_t  actual_axis 
)
inline

Calculate the gather output shape of a tensor

Parameters
[in]input_shapeInput tensor shape
[in]indices_shapeIndices tensor shape
[in]actual_axisThe axis to be gathered
Returns
the calculated shape

Definition at line 205 of file ShapeCalculatorEx.h.

207{
208 ARM_COMPUTE_ERROR_ON(indices_shape.num_dimensions() > 3);
209 ARM_COMPUTE_ERROR_ON(input_shape.num_dimensions() > 4);
210 ARM_COMPUTE_ERROR_ON(input_shape.num_dimensions() + indices_shape.num_dimensions() - 1 > 4);
211 ARM_COMPUTE_ERROR_ON(actual_axis >= input_shape.num_dimensions());
212
213 TensorShape output_shape = input_shape;
214 if (indices_shape.num_dimensions() == 1)
215 {
216 output_shape[actual_axis] = indices_shape[0];
217 }
218 else if (indices_shape.num_dimensions() > 1)
219 {
220 output_shape.shift_right(indices_shape.num_dimensions() - 1);
221
222 for (uint32_t i = 0, o = 0; o < output_shape.num_dimensions(); ++o, ++i)
223 {
224 if (o == actual_axis)
225 {
226 ++i;
227 for (uint32_t in = 0; in < indices_shape.num_dimensions(); ++in, ++o)
228 {
229 output_shape[o] = indices_shape[in];
230 }
231 }
232 else
233 {
234 output_shape[o] = input_shape[i];
235 }
236 }
237 }
238 return output_shape;
239}

References output_shape.

Referenced by arm_compute::NEGatherKernelEx::configure(), and arm_compute::NEGatherKernelEx::validate().

◆ compute_onehot_shape_ex()

TensorShape arm_compute::misc::shape_calculator::compute_onehot_shape_ex ( const TensorShape &  indices_shape,
uint32_t  depth,
uint32_t  actual_axis 
)
inline

Calculate the gather output shape of a tensor

Parameters
[in]input_shapeInput tensor shape
[in]indices_shapeIndices tensor shape
[in]actual_axisThe axis to be gathered
Returns
the calculated shape

Definition at line 249 of file ShapeCalculatorEx.h.

251{
252 ARM_COMPUTE_ERROR_ON(indices_shape.num_dimensions() > 3);
253 ARM_COMPUTE_ERROR_ON(actual_axis > indices_shape.num_dimensions());
254
255 TensorShape output_shape;
256 output_shape.set(actual_axis, depth);
257
258 unsigned int i_shift = 0;
259 for (unsigned int i = 0; i < indices_shape.num_dimensions(); ++i)
260 {
261 if (i == actual_axis)
262 {
263 i_shift++;
264 }
265 output_shape.set(i + i_shift, indices_shape[i]);
266 }
267
268 return output_shape;
269}

References output_shape.

◆ compute_space_to_depth_shape_ex()

TensorShape arm_compute::misc::shape_calculator::compute_space_to_depth_shape_ex ( const ITensorInfo *  input,
int32_t  block_shape 
)
inline

Calculate the space to batch output shape of a tensor

Parameters
[in]inputInput tensor info
[in]block_shapeBlock shape value
Returns
the calculated shape

Definition at line 180 of file ShapeCalculatorEx.h.

181{
182 ARM_COMPUTE_ERROR_ON(block_shape < 2);
183 TensorShape output_shape{input->tensor_shape()};
184
185 const DataLayout data_layout = input->data_layout();
186 const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
187 const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
188 const int idx_depth = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
189
190 output_shape.set(idx_width, input->tensor_shape()[idx_width] * block_shape);
191 output_shape.set(idx_height, input->tensor_shape()[idx_height] * block_shape);
192 output_shape.set(idx_depth, input->tensor_shape()[idx_depth] / (block_shape * block_shape));
193
194 return output_shape;
195}

References output_shape.

◆ compute_transposeconv_output_shape()

TensorShape arm_compute::misc::shape_calculator::compute_transposeconv_output_shape ( const std::pair< unsigned int, unsigned int > &  out_dims,
const ITensorInfo &  input,
const ITensorInfo &  weights 
)
inline

Calculate the output shape of the transpose convolution layer

Parameters
[in]out_dimsOutput x and y shape dimensions
[in]inputInput tensor info
[in]weightsWeights tensor shape
Returns
the calculated shape

Definition at line 128 of file ShapeCalculatorEx.h.

130{
131 const TensorShape input_shape{input.tensor_shape()};
132 const TensorShape weights_shape{weights.tensor_shape()};
133
134 const DataLayout data_layout = input.data_layout();
135 const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
136 const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
137 const int channel_idx =
138 get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
139 const int batch_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::BATCHES);
140
141 TensorShape out_shape{input_shape};
142 out_shape.set(width_idx, out_dims.first);
143 out_shape.set(height_idx, out_dims.second);
144 out_shape.set(channel_idx, weights_shape[batch_idx]);
145 return out_shape;
146}

Referenced by arm_compute::CLDirectTransposeConvLayer::configure(), arm_compute::NETransposeConvLayer::configure(), arm_compute::NETransposeConvLayer::validate(), and arm_compute::CLDirectTransposeConvLayer::validate().

◆ compute_transposeconv_upsampled_shape()

TensorShape arm_compute::misc::shape_calculator::compute_transposeconv_upsampled_shape ( const ITensorInfo &  input,
const ITensorInfo &  weights,
const PadStrideInfo &  info,
std::pair< unsigned int, unsigned int > &  out_dims,
unsigned int  invalid_right,
unsigned int  invalid_bottom,
unsigned int &  pad_left,
unsigned int &  pad_right,
unsigned int &  pad_top,
unsigned int &  pad_bottom 
)
inline

Calculate the upsampled output shape used for transpose convolution

Parameters
[in]inputInput tensor info
[in]weightsWeights tensor shape
[in]infoPadding and stride info
[in]out_dimsOutput shape dimensions
[in]invalid_rightThe number of zeros added to right edge of the output.
[in]invalid_bottomThe number of zeros added to bottom edge of the output.
[out]pad_leftPadding on left
[out]pad_rightPadding on right
[out]pad_topPadding on top
[out]pad_bottomPadding on bottom
Returns
the calculated shape

Definition at line 74 of file ShapeCalculatorEx.h.

79{
80 unsigned int sx = info.stride().first;
81 unsigned int sy = info.stride().second;
82 const DataLayout data_layout = input.data_layout();
83 const size_t idx_w = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
84 const size_t idx_h = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
85
86 // Find the upsampled dimensions
87 // transpose conv out:
88 // tconv_out + pad = 1 + (in - 1) * stride + invalid
89 // tconv_out = 1 + (in - 1) * stride + invalid - pad
90 // upsample out:
91 // upsample_out = 1 + (in - 1) * stride
92 unsigned int out_x = (input.dimension(idx_w) - 1) * sx + 1;
93 unsigned int out_y = (input.dimension(idx_h) - 1) * sy + 1;
94
95 // Find the padding needed for the convolution with stride 1 in order to match output shape
96 // upsample+pad out:
97 // upsample_out + pad = tconv_out + kernel - 1
98 // pad = tconv_out + kernel - 1 - upsample_out
99 unsigned int padx = out_dims.first - (out_x - weights.dimension(idx_w) + 1);
100 unsigned int pady = out_dims.second - (out_y - weights.dimension(idx_h) + 1);
101 out_x += padx;
102 out_y += pady;
103
104 unsigned int padx_all_except_invallid = padx + info.pad_left() + info.pad_right() - invalid_right;
105 unsigned int pady_all_except_invallid =
106 pady + info.pad_top() + info.pad_bottom() - invalid_bottom;
107 pad_left = (padx_all_except_invallid + 1) / 2 - info.pad_left();
108 pad_right = pady_all_except_invallid / 2 - info.pad_right() + invalid_right;
109 pad_top = (padx_all_except_invallid + 1) / 2 - info.pad_top();
110 pad_bottom = pady_all_except_invallid / 2 - info.pad_bottom() + invalid_bottom;
111
112 TensorShape scale_out_shape(input.tensor_shape());
113 scale_out_shape.set(idx_w, out_x);
114 scale_out_shape.set(idx_h, out_y);
115
116 return scale_out_shape;
117}
volatile const char info[]

References info.

Referenced by arm_compute::CLDirectTransposeConvLayer::configure(), arm_compute::NETransposeConvLayer::configure(), arm_compute::NETransposeConvLayer::validate(), and arm_compute::CLDirectTransposeConvLayer::validate().