blob: 7767b73e105fd589a0c70deaeb11d72c17f5140f [file] [log] [blame]
Michalis Spyrou780db4e2017-11-23 09:49:51 +00001/*
Georgios Pinitasced7a8d2018-02-01 16:31:33 +00002 * Copyright (c) 2017-2018 ARM Limited.
Michalis Spyrou780db4e2017-11-23 09:49:51 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#ifndef __ARM_COMPUTE_CLDECONVOLUTIONLAYER_H__
25#define __ARM_COMPUTE_CLDECONVOLUTIONLAYER_H__
26
Georgios Pinitasced7a8d2018-02-01 16:31:33 +000027#include "arm_compute/runtime/CL/functions/CLConvolutionLayer.h"
Michalis Spyrou780db4e2017-11-23 09:49:51 +000028#include "arm_compute/runtime/CL/functions/CLDeconvolutionLayerUpsample.h"
Michalis Spyrou780db4e2017-11-23 09:49:51 +000029
30#include "arm_compute/runtime/CL/CLMemoryGroup.h"
31#include "arm_compute/runtime/CL/CLTensor.h"
32#include "arm_compute/runtime/IFunction.h"
33#include "arm_compute/runtime/IMemoryManager.h"
34
35#include <memory>
36
37namespace arm_compute
38{
39class ICLTensor;
40/** Function to run the deconvolution layer.
41 *
42 * Deconvolution Layer is the backward pass of Convolution Layer. First we transform the input depending on the stride and pad info and then perform a 1x1
43 * convolution pass. Input stride defines how many zeroes we should put between each element of the input, pad is the amount of padding and finally a is a user
44 * specified value where a < stride - 1, that increases the padding top and right of the input image.
45 *
46 * The relation between input to output is as follows:
47 * width_output = round((width_input − 1) ∗ (stride_x - 1) − 2 ∗ padding_x + kernel_x + inner_border_right )
48 * height_output = round((height_input − 1) ∗ (stride_y - 1) − 2 ∗ padding_y + kernel_y + inner_border_top )
49 *
50 * where:
51 * width_input is the size of the first input dimension.
52 * height_input is the size of the second input dimension.
53 * width_output is the size of the first output dimension.
54 * height_output is the size of the second output dimension.
55 * kernel_x and kernel_y are the convolution sizes in x and y.
56 * inner_border_right and inner_border_top the number of zeros added to the right and top edges of the input.
57 * stride_x and stride_y is the input stride of the first and second dimension.
58 *
59 */
60class CLDeconvolutionLayer : public IFunction
61{
62public:
63 /** Constructor */
64 CLDeconvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
65 /** Set the input, weights, biases and output tensors.
66 *
Georgios Pinitas793f87d2018-05-18 20:08:58 +010067 * @param[in,out] input Input tensor. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: F16/F32.
Michalis Spyroua8ca2b02018-04-04 11:03:51 +010068 * @param[in] weights The 4d weights with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000069 * @param[in] bias (Optional) The biases have one dimension. Data type supported: Same as @p input.
70 * @param[out] output Output tensor. The output has the same number of dimensions as the @p input.
71 * @param[in] info Contains padding and policies to be used in the deconvolution, this is decribed in @ref PadStrideInfo.
72 * @param[in] inner_border_right The number of zeros added to right edge of the input.
73 * @param[in] inner_border_top The number of zeros added to top edge of the input.
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +010074 * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref CLWeightsReshapeKernel.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000075 *
76 */
77 void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *bias, ICLTensor *output, const PadStrideInfo &info,
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +010078 unsigned int inner_border_right, unsigned int inner_border_top, const WeightsInfo &weights_info = WeightsInfo());
Michalis Spyrou780db4e2017-11-23 09:49:51 +000079 /** Static function to check if given info will lead to a valid configuration of @ref CLDeconvolutionLayer
80 *
Georgios Pinitas793f87d2018-05-18 20:08:58 +010081 * @param[in] input Input tensor info. 3 lower dimensions represent a single input, and an optional 4th dimension for batch of inputs. Data types supported: F16/F32.
Michalis Spyroua8ca2b02018-04-04 11:03:51 +010082 * @param[in] weights The 4d weights info with dimensions [width, height, IFM, OFM]. Data type supported: Same as @p input.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000083 * @param[in] bias (Optional) The biases have one dimension. Data type supported: Same as @p input.
84 * @param[in] output Output tensor info. The output has the same number of dimensions as the @p input.
85 * @param[in] info Contains padding and policies to be used in the deconvolution, this is decribed in @ref PadStrideInfo.
86 * @param[in] inner_border_right The number of zeros added to right edge of the input.
87 * @param[in] inner_border_top The number of zeros added to top edge of the input.
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +010088 * @param[in] weights_info (Optional) Weights information needed for @ref CLConvolutionLayer, specifies if the weights tensor has been reshaped with @ref CLWeightsReshapeKernel.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000089 *
90 * @return a status
91 */
92 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *bias, ITensorInfo *output, const PadStrideInfo &info,
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +010093 unsigned int inner_border_right, unsigned int inner_border_top, const WeightsInfo &weights_info = WeightsInfo());
Michalis Spyrou780db4e2017-11-23 09:49:51 +000094
95 // Inherited methods overridden:
96 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +010097 void prepare() override;
Michalis Spyrou780db4e2017-11-23 09:49:51 +000098
99private:
100 CLMemoryGroup _memory_group;
101 CLDeconvolutionLayerUpsample _scale_f;
Georgios Pinitasced7a8d2018-02-01 16:31:33 +0000102 CLConvolutionLayer _conv_f;
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000103 CLTensor _scaled_output;
Georgios Pinitas72219332018-06-05 14:56:06 +0100104 bool _is_prepared;
Michalis Spyrou780db4e2017-11-23 09:49:51 +0000105};
106}
Michele Di Giorgio70ba7d62018-06-06 17:03:36 +0100107#endif /* __ARM_COMPUTE_CLDECONVOLUTIONLAYER_H__ */