aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFinn Williams <Finn.Williams@arm.com>2019-11-06 16:54:53 +0000
committerJim Flynn Arm <jim.flynn@arm.com>2019-11-08 12:44:53 +0000
commit70f609bc754e77d99f78ccce863f8e6332bbf8d5 (patch)
tree082f9338e351cdef771252fc659d1317faf374b6
parent8bf442e9d121323d48525ab80c45fa816ba0c82c (diff)
downloadarmnn-70f609bc754e77d99f78ccce863f8e6332bbf8d5.tar.gz
MLCE-144 Fix cts MAX_POOL_2D_V1_0 tests
Signed-off-by: Finn Williams <Finn.Williams@arm.com> Change-Id: I2da66efca40bc21d417efc42a225877d94e31428
-rw-r--r--src/backends/backendsCommon/test/layerTests/Pooling2dTestImpl.cpp12
-rw-r--r--src/backends/reference/workloads/Pooling2d.cpp35
2 files changed, 31 insertions, 16 deletions
diff --git a/src/backends/backendsCommon/test/layerTests/Pooling2dTestImpl.cpp b/src/backends/backendsCommon/test/layerTests/Pooling2dTestImpl.cpp
index fcc898026a..a7fbfefcb0 100644
--- a/src/backends/backendsCommon/test/layerTests/Pooling2dTestImpl.cpp
+++ b/src/backends/backendsCommon/test/layerTests/Pooling2dTestImpl.cpp
@@ -224,17 +224,17 @@ LayerTestResult<T, 4> SimpleMaxPooling2dSize3x3Stride2x4TestCommon(
0.0f, 9.0f, 7.0f, 9.0f, 9.0f, 3.0f,
0.0f, 8.0f, 9.0f, 9.0f, 9.0f, 9.0f,
- 0.0f, 0.0f, 0.0f, 0.0f,-3.0f, 0.0f,
- 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
- 0.0f,-1.0f,-1.0f,-1.0f,-1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 0.0f,-3.0f,-3.0f,
+ 0.0f,-1.0f, 0.0f, 0.0f, 0.0f,-2.0f,
+ 0.0f,-1.0f,-1.0f,-1.0f,-1.0f,-1.0f,
0.0f, 8.0f, 8.0f, 8.0f, 8.0f, 8.0f,
0.0f, 9.0f, 7.0f, 9.0f, 9.0f, 3.0f,
0.0f, 8.0f, 9.0f, 9.0f, 9.0f, 9.0f,
- 0.0f, 0.0f, 0.0f, 0.0f,-3.0f, 0.0f,
- 0.0f,-1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
- 0.0f,-1.0f,-1.0f,-1.0f,-1.0f, 0.0f
+ 0.0f, 0.0f, 0.0f, 0.0f,-3.0f,-3.0f,
+ 0.0f,-1.0f, 0.0f, 0.0f, 0.0f,-2.0f,
+ 0.0f,-1.0f,-1.0f,-1.0f,-1.0f,-1.0f
},
qScale, qOffset));
}
diff --git a/src/backends/reference/workloads/Pooling2d.cpp b/src/backends/reference/workloads/Pooling2d.cpp
index f2532cac03..cf83f8ce2b 100644
--- a/src/backends/reference/workloads/Pooling2d.cpp
+++ b/src/backends/reference/workloads/Pooling2d.cpp
@@ -107,9 +107,9 @@ namespace
}
}
- bool OnPaddingOnly(int start, int end, int maxRange, int padding)
+ bool OnPaddingOnly(int start, int end, int maxRange)
{
- if (end <= 0 || start > (maxRange - padding))
+ if (end <= 0 || start > maxRange)
{
return true;
}
@@ -187,34 +187,49 @@ void Pooling2d(Decoder<float>& rInputDecoder,
{
for (int yOutput = 0; yOutput < heightOutput; yOutput++)
{
+ // Calculate values independent of the x axis
+ int hstart = (yOutput * strideY) - padTop;
+ int hend = hstart + poolHeight;
+ // Clamp the pooling region inside the valid input area (which includes the padding).
+ // This is necessary because the final pooling in a row may overlap beyond the padding.
+ hend = std::min(hend, heightInput + padBottom);
+
+ int height = hend - hstart;
+ bool hclamped = ClampRange(hstart, hend, heightInput);
+
for (int xOutput = 0; xOutput < widthOutput; xOutput++)
{
- int hstart = (yOutput * strideY) - padTop;
int wstart = (xOutput * strideX) - padLeft;
- int hend = hstart + poolHeight;
int wend = wstart + poolWidth;
// Clamp the pooling region inside the valid input area (which includes the padding).
// This is necessary because the final pooling in a row may overlap beyond the padding.
- hend = std::min(hend, heightInput + padBottom);
wend = std::min(wend, widthInput + padRight);
float result = defaultInitializer;
- float poolAreaSize = boost::numeric_cast<float>((hend - hstart) * (wend - wstart));
+ float poolAreaSize = boost::numeric_cast<float>(height * (wend - wstart));
// Special case: when the pooling kernel is over a padding region and the padding
// size is larger or equal to the kernel and the kernel only covers
// padding and no real values, then we initialize the result as zero
// by convention. This is because we need to choose a value here and
// all values we have are padding, which we ignore.
- if (OnPaddingOnly(hstart, hend, heightInput, padBottom) ||
- OnPaddingOnly(wstart, wend, widthInput, padRight))
+ if (OnPaddingOnly(hstart, hend, heightInput) ||
+ OnPaddingOnly(wstart, wend, widthInput))
{
result = 0.0f;
+
+ unsigned int outputIndex = dataLayout.GetIndex(outputShape,
+ boost::numeric_cast<unsigned int>(n),
+ boost::numeric_cast<unsigned int>(c),
+ boost::numeric_cast<unsigned int>(yOutput),
+ boost::numeric_cast<unsigned int>(xOutput));
+ rOutputEncoder[outputIndex];
+ rOutputEncoder.Set(result);
+ continue;
}
- bool clamped = ClampRange(wstart, wend, widthInput);
- clamped |= ClampRange(hstart, hend, heightInput);
+ bool clamped = hclamped |= ClampRange(wstart, wend, widthInput);
if (clamped && params.m_PaddingMethod == PaddingMethod::Exclude)
{