10 #include <boost/numeric/conversion/cast.hpp> 23 inline float Lerp(
float a,
float b,
float w)
25 return w * b + (1.f - w) * a;
28 inline double EuclideanDistance(
float Xa,
float Ya,
const unsigned int Xb,
const unsigned int Yb)
30 return std::sqrt(pow(Xa - boost::numeric_cast<float>(Xb), 2) + pow(Ya - boost::numeric_cast<float>(Yb), 2));
47 const unsigned int batchSize = inputInfo.
GetShape()[0];
60 / boost::numeric_cast<float>(outputHeight - sizeOffset);
62 / boost::numeric_cast<float>(outputWidth - sizeOffset);
67 for (
unsigned int n = 0; n < batchSize; ++n)
69 for (
unsigned int c = 0; c < channelCount; ++c)
71 for (
unsigned int y = 0; y < outputHeight; ++y)
77 const float fiy = floorf(iy);
81 const float yw = iy - fiy;
83 for (
unsigned int x = 0; x < outputWidth; ++x)
87 const float fix = floorf(ix);
91 const float xw = ix - fix;
94 const unsigned int x1 = std::min(x0 + 1, inputWidth - 1u);
95 const unsigned int y1 = std::min(y0 + 1, inputHeight - 1u);
97 float interpolatedValue;
102 in[dataLayout.
GetIndex(inputShape, n, c, y0, x0)];
103 float input1 = in.
Get();
104 in[dataLayout.
GetIndex(inputShape, n, c, y0, x1)];
105 float input2 = in.
Get();
106 in[dataLayout.
GetIndex(inputShape, n, c, y1, x0)];
107 float input3 = in.
Get();
108 in[dataLayout.
GetIndex(inputShape, n, c, y1, x1)];
109 float input4 = in.
Get();
111 const float ly0 = Lerp(input1, input2, xw);
112 const float ly1 = Lerp(input3, input4, xw);
113 interpolatedValue = Lerp(ly0, ly1, yw);
119 auto distance00 = EuclideanDistance(fix, fiy, x0, y0);
120 auto distance01 = EuclideanDistance(fix, fiy, x0, y1);
121 auto distance10 = EuclideanDistance(fix, fiy, x1, y0);
122 auto distance11 = EuclideanDistance(fix, fiy, x1, y1);
124 auto minimum = std::min( { distance00, distance01, distance10, distance11 } );
126 unsigned int xNearest = 0;
127 unsigned int yNearest = 0;
134 else if (
minimum == distance01)
139 else if (
minimum == distance10)
144 else if (
minimum == distance11)
154 in[dataLayout.
GetIndex(inputShape, n, c, yNearest, xNearest)];
155 interpolatedValue = in.
Get();
160 std::to_string(static_cast<int>(resizeMethod)));
162 out[dataLayout.
GetIndex(outputShape, n, c, y, x)];
163 out.
Set(interpolatedValue);
unsigned int GetWidthIndex() const
const TensorShape & GetShape() const
virtual void Set(IType right)=0
Copyright (c) 2020 ARM Limited.
unsigned int GetHeightIndex() const
virtual IType Get() const =0
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
unsigned int GetIndex(const armnn::TensorShape &shape, unsigned int batchIndex, unsigned int channelIndex, unsigned int heightIndex, unsigned int widthIndex) const
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
void Resize(Decoder< float > &in, const TensorInfo &inputInfo, Encoder< float > &out, const TensorInfo &outputInfo, DataLayoutIndexed dataLayout, armnn::ResizeMethod resizeMethod, bool alignCorners)
unsigned int GetChannelsIndex() const