ArmNN
 21.02
Conv2D.cpp File Reference
#include <boost/test/unit_test.hpp>
#include "ParserFlatbuffersFixture.hpp"
#include "../TfLiteParser.hpp"
#include <sstream>

Go to the source code of this file.

Functions

 BOOST_FIXTURE_TEST_CASE (ParseSimpleConv2D, SimpleConv2DFixture)
 
 BOOST_FIXTURE_TEST_CASE (ParseConv2DWithBias, SimpleConv2DWithBiasesFixture)
 
 BOOST_FIXTURE_TEST_CASE (ParseDynamicConv2DWithBias, DynamicConv2DWithBiasesFixture)
 
 BOOST_FIXTURE_TEST_CASE (ParseConv2D_112x112_out, Conv2DShapeTestFixture)
 
 BOOST_FIXTURE_TEST_CASE (ParseConv2DAndReluWithBias, ReluConv2DWithBiasesFixture)
 
 BOOST_FIXTURE_TEST_CASE (ParseConv2DAndRelu6WithBias, Relu6Conv2DWithBiasesFixture)
 

Function Documentation

◆ BOOST_FIXTURE_TEST_CASE() [1/6]

BOOST_FIXTURE_TEST_CASE ( ParseSimpleConv2D  ,
SimpleConv2DFixture   
)

Definition at line 90 of file Conv2D.cpp.

91 {
92  RunTest<4, armnn::DataType::QAsymmU8>(
93  0,
94  {
95  1, 2, 3,
96  4, 5, 6,
97  7, 8, 9,
98  },
99  // because of the output scaling we need to take half of the values
100  {
101  (1*2 + 2*1 + 3*0 +
102  4*6 + 5*2 + 6*1 +
103  7*4 + 8*1 + 9*2) /2
104  });
105 }

◆ BOOST_FIXTURE_TEST_CASE() [2/6]

BOOST_FIXTURE_TEST_CASE ( ParseConv2DWithBias  ,
SimpleConv2DWithBiasesFixture   
)

Definition at line 220 of file Conv2D.cpp.

221 {
222  RunTest<4, armnn::DataType::QAsymmU8>(
223  0,
224  {
225  1, 2,
226  3, 4,
227  },
228  // because of the output scaling we need to take half of the values
229  {
230  (1*2 + 2*1 + 3*0 + 4*6 + 10)/2,
231  (2*2 + 0*1 + 4*0 + 0*6 + 10)/2,
232  (3*2 + 4*1 + 0*0 + 0*6 + 10)/2,
233  (4*2 + 0*1 + 0*0 + 0*6 + 10)/2
234  });
235 }

◆ BOOST_FIXTURE_TEST_CASE() [3/6]

BOOST_FIXTURE_TEST_CASE ( ParseDynamicConv2DWithBias  ,
DynamicConv2DWithBiasesFixture   
)

Definition at line 250 of file Conv2D.cpp.

References armnn::QAsymmU8.

251 {
252  RunTest<4,
254  armnn::DataType::QAsymmU8>(0,
255  { { "inputTensor", { 1, 2, 3, 4, } } },
256  { { "outputTensor", { (1*2 + 2*1 + 3*0 + 4*6 + 10)/2,
257  (2*2 + 0*1 + 4*0 + 0*6 + 10)/2,
258  (3*2 + 4*1 + 0*0 + 0*6 + 10)/2,
259  (4*2 + 0*1 + 0*0 + 0*6 + 10)/2} } },
260  true);
261 }

◆ BOOST_FIXTURE_TEST_CASE() [4/6]

BOOST_FIXTURE_TEST_CASE ( ParseConv2D_112x112_out  ,
Conv2DShapeTestFixture   
)

Definition at line 291 of file Conv2D.cpp.

292 {
293 }

◆ BOOST_FIXTURE_TEST_CASE() [5/6]

BOOST_FIXTURE_TEST_CASE ( ParseConv2DAndReluWithBias  ,
ReluConv2DWithBiasesFixture   
)

Definition at line 313 of file Conv2D.cpp.

314 {
315  uint8_t bias = 16;
316  uint8_t outZero = 20;
317  uint8_t fz = 4; // filter zero point
318 
319  RunTest<4, armnn::DataType::QAsymmU8>(
320  0,
321  {
322  1, 2,
323  4, 8,
324  },
325  // factors to consider:
326  // - the filter zero point is non zero, hence the (x-fz)
327  // - the output scale is 2 hence the /2
328  // - output zero point is non zero, hence the +outZero
329  // - RELU cuts negative values and then we add the output zero point
330  {
331  std::max(outZero, static_cast<uint8_t>((1*(2-fz) + 2*(1-fz) + 4*(0-fz) + 8*(6-fz) + bias)/2 + outZero)),
332  std::max(outZero, static_cast<uint8_t>((2*(2-fz) + 0*(1-fz) + 8*(0-fz) + 0*(6-fz) + bias)/2 + outZero)),
333  std::max(outZero, static_cast<uint8_t>((4*(2-fz) + 8*(1-fz) + 0*(0-fz) + 0*(6-fz) + bias)/2 + outZero)),
334  std::max(outZero, static_cast<uint8_t>((8*(2-fz) + 0*(1-fz) + 0*(0-fz) + 0*(6-fz) + bias)/2 + outZero))
335  });
336 }

◆ BOOST_FIXTURE_TEST_CASE() [6/6]

BOOST_FIXTURE_TEST_CASE ( ParseConv2DAndRelu6WithBias  ,
Relu6Conv2DWithBiasesFixture   
)

Definition at line 356 of file Conv2D.cpp.

References BOOST_AUTO_TEST_SUITE_END().

357 {
358  uint8_t relu6Min = 6 / 2; // divide by output scale
359 
360  RunTest<4, armnn::DataType::QAsymmU8>(
361  0,
362  {
363  1, 2,
364  4, 1,
365  },
366  // factors to consider:
367  // - the output scale is 2 hence the /2
368  // - RELU6 cuts output values at +6
369  {
370  std::min(relu6Min, static_cast<uint8_t>((1*2 + 2*1 + 4*0 + 1*6)/2)),
371  std::min(relu6Min, static_cast<uint8_t>((2*2 + 0*1 + 1*0 + 0*6)/2)),
372  std::min(relu6Min, static_cast<uint8_t>((4*2 + 1*1 + 0*0 + 0*6)/2)),
373  std::min(relu6Min, static_cast<uint8_t>((1*2 + 0*1 + 0*0 + 0*6)/2))
374  });
375 }