Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 3 | * |
| 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 | |
| 27 | #include "arm_compute/runtime/NEON/functions/NEDeconvolutionLayerUpsample.h" |
| 28 | #include "arm_compute/runtime/NEON/functions/NEDirectConvolutionLayer.h" |
| 29 | |
| 30 | #include "arm_compute/core/Types.h" |
| 31 | #include "arm_compute/runtime/IFunction.h" |
| 32 | #include "arm_compute/runtime/IMemoryManager.h" |
| 33 | #include "arm_compute/runtime/MemoryGroup.h" |
| 34 | #include "arm_compute/runtime/Tensor.h" |
| 35 | |
| 36 | #include <memory> |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | /** Function to run the deconvolution layer. |
| 41 | * |
| 42 | * The operation is similar to convolution but it's implemented by up-sampling the inputs with zeros insertions between the inputs and convolving |
| 43 | * the kernels on the up-sampled result. |
| 44 | * |
| 45 | * Before the Deconvolution is done, up-scaling the first 2D with zeros is performed. The relation between input to |
| 46 | * output is as follows: |
| 47 | * width_output = round((width_input − 1) ∗ upscale_x − 2 ∗ padding_x + kernel_x + a_x ) |
| 48 | * height_output = round((height_input − 1) ∗ upscale_y − 2 ∗ padding_y + kernel_y + a_y ) |
| 49 | * |
| 50 | * where |
| 51 | * width is the size of the first input dimension. |
| 52 | * height 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 | * ax and ay the number of zeros added to the top and right edges of the input. |
| 57 | * upscale_x and upscale_y how much to scale the X and Y axis. |
| 58 | * |
| 59 | * This function calls the following NEON kernels: |
| 60 | * |
| 61 | * -# @ref NEDeconvolutionLayerUpsampleKernel |
| 62 | * -# @ref NEDirectConvolutionLayer |
| 63 | * |
| 64 | */ |
| 65 | class NEDeconvolutionLayer : public IFunction |
| 66 | { |
| 67 | public: |
| 68 | /** Constructor */ |
| 69 | NEDeconvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
| 70 | /** Set the input, weights, biases and output tensors. |
Anthony Barbier | f202e50 | 2017-11-23 18:02:04 +0000 | [diff] [blame] | 71 | * |
| 72 | * @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. |
| 73 | * @param[in] weights The 4d weights with dimensions [width, height, OFM, IFM]. Data type supported: Same as @p input. |
| 74 | * @param[in] bias Optional, ignored if NULL. The biases have one dimension. Data type supported: Same as @p input. |
| 75 | * @param[out] output Output tensor. The output has the same number of dimensions as the @p input. |
| 76 | * @param[in] info Contains padding and policies to be used in the deconvolution, this is decribed in @ref PadStrideInfo. |
| 77 | * @param[in] ax The number of zeros added to right edge of the input. |
| 78 | * @param[in] ay The number of zeros added to top edge of the input. |
| 79 | * @param[in] upscalex How much to scale the X axis. |
| 80 | * @param[in] upscaley How much to scale the Y axis. |
| 81 | * |
| 82 | */ |
Pablo Tello | f5f34bb | 2017-08-22 13:34:13 +0100 | [diff] [blame] | 83 | void configure(ITensor *input, const ITensor *weights, const ITensor *bias, ITensor *output, const PadStrideInfo &info, |
| 84 | unsigned int ax, unsigned int ay, float upscalex, float upscaley); |
| 85 | |
| 86 | // Inherited methods overridden: |
| 87 | void run() override; |
| 88 | |
| 89 | private: |
| 90 | MemoryGroup _memory_group; |
| 91 | NEDeconvolutionLayerUpsample _scale_f; |
| 92 | NEDirectConvolutionLayer _conv_f; |
| 93 | Tensor _scaled_output; |
| 94 | }; |
| 95 | } // arm_compute |
| 96 | #endif /* __ARM_COMPUTE_NEDECONVOLUTIONLAYER_H__ */ |