Compute Library
 20.05
UpsampleLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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 #include "UpsampleLayer.h"
25 
28 
29 namespace arm_compute
30 {
31 namespace test
32 {
33 namespace validation
34 {
35 namespace reference
36 {
37 template <typename T>
39 {
42 
43  TensorShape output_shape = src.shape();
44  output_shape.set(0, src.shape().x() * info.x());
45  output_shape.set(1, src.shape().y() * info.y());
46 
47  // Create reference
48  const int stride_x = info.x();
49  const int stride_y = info.y();
50  int width_out = output_shape.x();
51  int height_out = output_shape.y();
52  SimpleTensor<T> out{ output_shape, src.data_type(), 1, src.quantization_info() };
53 
54  const int width_in = src.shape().x();
55  const int height_in = src.shape().y();
56  const int num_2d_slices = src.shape().total_size() / (width_in * height_in);
57 
58  for(int slice = 0; slice < num_2d_slices; ++slice)
59  {
60  const int offset_slice_in = slice * width_in * height_in;
61  const int offset_slice_out = slice * height_out * width_out;
62  for(int y = 0; y < height_out; ++y)
63  {
64  for(int x = 0; x < width_out; ++x)
65  {
66  const int out_offset = y * width_out + x;
67  const int in_offset = (y / stride_y) * width_in + x / stride_x;
68 
69  T *_out = out.data() + offset_slice_out + out_offset;
70  const T *in = src.data() + offset_slice_in + in_offset;
71  *_out = *in;
72  }
73  }
74  }
75  return out;
76 }
77 
79  const Size2D &info, const InterpolationPolicy policy);
81  const Size2D &info, const InterpolationPolicy policy);
83  const Size2D &info, const InterpolationPolicy policy);
85  const Size2D &info, const InterpolationPolicy policy);
86 } // namespace reference
87 } // namespace validation
88 } // namespace test
89 } // namespace arm_compute
InterpolationPolicy
Interpolation method.
Definition: Types.h:369
Shape of a tensor.
Definition: TensorShape.h:39
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Output values are defined to match the source pixel whose center is nearest to the sample position.
Copyright (c) 2017-2020 ARM Limited.
T x() const
Alias to access the size of the first dimension.
Definition: Dimensions.h:81
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
SimpleTensor< T > upsample_layer(const SimpleTensor< T > &src, const Size2D &info, const InterpolationPolicy policy)
Simple tensor object that stores elements in a consecutive chunk of memory.
Definition: SimpleTensor.h:59
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true)
Accessor to set the value of one of the dimensions.
Definition: TensorShape.h:78
T y() const
Alias to access the size of the second dimension.
Definition: Dimensions.h:86
cast configure & src
Definition: Cast.cpp:169
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)