blob: 091a928db652f9ebca52695ca247277c3830636c [file] [log] [blame]
Pablo Tellof5f34bb2017-08-22 13:34:13 +01001/*
Michalis Spyrou780db4e2017-11-23 09:49:51 +00002 * Copyright (c) 2017, 2018 ARM Limited.
Pablo Tellof5f34bb2017-08-22 13:34:13 +01003 *
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_NEDECONVOLUTIONLAYER_H__
25#define __ARM_COMPUTE_NEDECONVOLUTIONLAYER_H__
26
Pablo Tellof5f34bb2017-08-22 13:34:13 +010027#include "arm_compute/runtime/NEON/functions/NEDirectConvolutionLayer.h"
28
29#include "arm_compute/core/Types.h"
30#include "arm_compute/runtime/IFunction.h"
31#include "arm_compute/runtime/IMemoryManager.h"
32#include "arm_compute/runtime/MemoryGroup.h"
33#include "arm_compute/runtime/Tensor.h"
34
35#include <memory>
36
37namespace arm_compute
38{
39/** Function to run the deconvolution layer.
40 *
Michalis Spyrou780db4e2017-11-23 09:49:51 +000041 * Deconvolution Layer is the backward pass of Convolution Layer. First we transform the input depending on the stride and pad info and then perfrom a 1x1
42 * convolution pass. Input stride defines how many zeroes we should put between each element of the input, pad is the amount of padding and finaly a is a user
43 * specified value where a < stride - 1 that increases the padding top and right of the input image.
Pablo Tellof5f34bb2017-08-22 13:34:13 +010044 *
Michalis Spyrou780db4e2017-11-23 09:49:51 +000045 * The relation between input to output is as follows:
46 * width_output = round((width_input − 1) ∗ (stride_x - 1) − 2 ∗ padding_x + kernel_x + inner_border_right )
47 * height_output = round((height_input − 1) ∗ (stride_y - 1) − 2 ∗ padding_y + kernel_y + inner_border_top )
Pablo Tellof5f34bb2017-08-22 13:34:13 +010048 *
49 * where
50 * width is the size of the first input dimension.
51 * height is the size of the second input dimension.
52 * width_output is the size of the first output dimension.
53 * height_output is the size of the second output dimension.
54 * kernel_x and kernel_y are the convolution sizes in x and y.
Michalis Spyrou780db4e2017-11-23 09:49:51 +000055 * inner_border_right and inner_border_top the number of zeros added to the top and right edges of the input.
56 * stride_x and stride_y is the input stride of the first and second dimension.
Pablo Tellof5f34bb2017-08-22 13:34:13 +010057 *
58 * This function calls the following NEON kernels:
59 *
Pablo Tellof5f34bb2017-08-22 13:34:13 +010060 * -# @ref NEDirectConvolutionLayer
61 *
62 */
63class NEDeconvolutionLayer : public IFunction
64{
65public:
Michalis Spyrou780db4e2017-11-23 09:49:51 +000066 /** Default constructor */
Pablo Tellof5f34bb2017-08-22 13:34:13 +010067 NEDeconvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Michalis Spyrou780db4e2017-11-23 09:49:51 +000068
69 /** Prevent instances of this class from being copied (As this class contains pointers) */
70 NEDeconvolutionLayer(const NEDeconvolutionLayer &) = delete;
71 /** Prevent instances of this class from being copied (As this class contains pointers) */
72 NEDeconvolutionLayer &operator=(const NEDeconvolutionLayer &) = delete;
73 /** Allow instances of this class to be moved */
74 NEDeconvolutionLayer(NEDeconvolutionLayer &&) = default;
75 /** Allow instances of this class to be moved */
76 NEDeconvolutionLayer &operator=(NEDeconvolutionLayer &&) = default;
77 /** Default destructor */
78 virtual ~NEDeconvolutionLayer() = default;
Pablo Tellof5f34bb2017-08-22 13:34:13 +010079 /** Set the input, weights, biases and output tensors.
Anthony Barbierf202e502017-11-23 18:02:04 +000080 *
Michalis Spyrou780db4e2017-11-23 09:49:51 +000081 * @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: F32.
82 * @param[in] weights The 4d weights with dimensions [width, height, OFM, IFM]. Data type supported: Same as @p input.
83 * @param[in] bias Optional, ignored if NULL. The biases have one dimension. Data type supported: Same as @p input.
84 * @param[out] output Output tensor. 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.
Anthony Barbierf202e502017-11-23 18:02:04 +000088 *
89 */
Pablo Tellof5f34bb2017-08-22 13:34:13 +010090 void configure(ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, const PadStrideInfo &info,
Michalis Spyrou780db4e2017-11-23 09:49:51 +000091 unsigned int inner_border_right, unsigned int inner_border_top);
Pablo Tellof5f34bb2017-08-22 13:34:13 +010092
93 // Inherited methods overridden:
94 void run() override;
95
96private:
Michalis Spyrou780db4e2017-11-23 09:49:51 +000097 MemoryGroup _memory_group;
98 NEDirectConvolutionLayer _conv_f;
99 Tensor _scaled_output;
100 ITensor *_input;
101 PadStrideInfo _info;
102 std::pair<unsigned int, unsigned int> _inner_border;
Pablo Tellof5f34bb2017-08-22 13:34:13 +0100103};
104} // arm_compute
105#endif /* __ARM_COMPUTE_NEDECONVOLUTIONLAYER_H__ */