36 template <
typename T,
typename TB>
41 const unsigned int pad_left = info.
pad_left();
42 const unsigned int pad_right = info.
pad_right();
43 const unsigned int pad_top = info.
pad_top();
44 const unsigned int pad_bottom = info.
pad_bottom();
45 const int stride_x = info.
stride().first;
46 const int stride_y = info.
stride().second;
49 const int weights_upper_dims = weights.
shape().total_size() / (weights_width *
weights_height);
57 unsigned int out_x = (src.
shape().x() - 1) * stride_x + 1;
58 unsigned int out_y = (src.
shape().y() - 1) * stride_y + 1;
61 unsigned int deconv_pad_x = output_shape.
x() - (out_x - weights_width + 1);
62 unsigned int deconv_pad_y = output_shape.
y() - (out_y - weights_height + 1);
63 out_x += deconv_pad_x;
64 out_y += deconv_pad_y;
66 unsigned int deconv_pad_left = pad_right > pad_left ? pad_right - pad_left : 0;
67 unsigned int deconv_pad_right = pad_left > pad_right ? pad_left - pad_right : 0;
68 deconv_pad_x -= deconv_pad_left + deconv_pad_right;
70 deconv_pad_left += deconv_pad_x / 2;
71 deconv_pad_right += deconv_pad_x / 2;
73 unsigned int deconv_pad_top = pad_bottom > pad_top ? pad_bottom - pad_top : 0;
74 unsigned int deconv_pad_bottom = pad_top > pad_bottom ? pad_top - pad_bottom : 0;
75 deconv_pad_y -= deconv_pad_top + deconv_pad_bottom;
77 deconv_pad_top += deconv_pad_y / 2;
78 deconv_pad_bottom += deconv_pad_y / 2;
81 scaled_shape.
set(0, out_x);
82 scaled_shape.
set(1, out_y);
85 const int width_in = src.
shape().x();
86 const int height_in = src.
shape().y();
87 const int width_scaled = scaled.shape().x();
88 const int height_scaled = scaled.shape().y();
89 const int num_2d_slices = src.
shape().total_size() / (width_in * height_in);
93 const auto quantized_zero =
static_cast<T
>(src.
quantization_info().uniform().offset);
94 std::fill_n(scaled.data(), scaled.num_elements(), quantized_zero);
98 std::fill_n(scaled.data(), scaled.num_elements(), T(0));
104 #pragma omp parallel for 106 for(
int ud = 0; ud < weights_upper_dims; ++ud)
113 weights_flipped[offset + (weights_height - 1 - y) * weights_width + (weights_width - 1 - x)] = weights[offset + y * weights_width + x];
118 #pragma omp parallel for 122 const int offset_slice_in =
slice * width_in * height_in;
123 const int offset_slice_out =
slice * width_scaled * height_scaled;
124 const int start_x = deconv_pad_left;
125 const int start_y = deconv_pad_top;
126 const int end_x = width_scaled - deconv_pad_right;
127 const int end_y = height_scaled - deconv_pad_bottom;
129 for(
int yi = start_y, in_y = 0; yi < end_y; yi += stride_y, in_y++)
131 for(
int xi = start_x, in_x = 0; xi < end_x; xi += stride_x, in_x++)
133 const T *in = src.
data() + offset_slice_in + in_y * width_in + in_x;
134 T *out = scaled.data() + offset_slice_out + xi + yi * width_scaled;
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
SimpleTensor< T > deconvolution_layer(const SimpleTensor< T > &src, const SimpleTensor< T > &weights, const SimpleTensor< TB > &bias, const TensorShape &output_shape, const PadStrideInfo &info, QuantizationInfo out_qinfo)
Deconvolution reference implementation.
DataType data_type() const override
Data type of the tensor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
TensorShape shape() const override
Shape of the tensor.
unsigned int pad_top() const
Get the top padding.
const size_t weights_height
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
T x() const
Alias to access the size of the first dimension.
Quantization information.
quantized, asymmetric fixed-point 8-bit number unsigned
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
unsigned int pad_right() const
Get the right padding.
Padding and stride information class.
Simple tensor object that stores elements in a consecutive chunk of memory.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
SimpleTensor< T > convolution_layer(const SimpleTensor< T > &src, const SimpleTensor< TW > &weights, const SimpleTensor< TB > &bias, const TensorShape &output_shape, const PadStrideInfo &info, const Size2D &dilation, unsigned int num_groups, QuantizationInfo out_quant_info)
Class for specifying the size of an image or rectangle.
T y() const
Alias to access the size of the second dimension.
quantized, asymmetric fixed-point 8-bit number signed
QuantizationInfo quantization_info() const override
Quantization info in case of asymmetric quantized type.
unsigned int pad_bottom() const
Get the bottom padding.
const size_t weights_width
unsigned int pad_left() const
Get the left padding.
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
const T * data() const
Constant pointer to the underlying buffer.