aboutsummaryrefslogtreecommitdiff
path: root/src/armnnOnnxParser/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnnOnnxParser/test')
-rw-r--r--src/armnnOnnxParser/test/Addition.cpp311
-rw-r--r--src/armnnOnnxParser/test/BatchNorm.cpp342
-rw-r--r--src/armnnOnnxParser/test/Const.cpp87
-rw-r--r--src/armnnOnnxParser/test/Constructor.cpp16
-rw-r--r--src/armnnOnnxParser/test/Conv2D.cpp469
-rw-r--r--src/armnnOnnxParser/test/CreateNetwork.cpp63
-rw-r--r--src/armnnOnnxParser/test/DepthConv.cpp162
-rw-r--r--src/armnnOnnxParser/test/FullyConnected.cpp597
-rw-r--r--src/armnnOnnxParser/test/GetInputsOutputs.cpp255
-rw-r--r--src/armnnOnnxParser/test/Pooling.cpp310
-rw-r--r--src/armnnOnnxParser/test/ProtoxtFixture.cpp81
-rw-r--r--src/armnnOnnxParser/test/Relu.cpp70
-rw-r--r--src/armnnOnnxParser/test/Reshape.cpp110
13 files changed, 2873 insertions, 0 deletions
diff --git a/src/armnnOnnxParser/test/Addition.cpp b/src/armnnOnnxParser/test/Addition.cpp
new file mode 100644
index 0000000000..25519447c6
--- /dev/null
+++ b/src/armnnOnnxParser/test/Addition.cpp
@@ -0,0 +1,311 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct AddMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ AddMainFixture(const std::string& dataType)
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input0"
+ type {
+ tensor_type {
+ elem_type: )" + dataType + R"(
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Input1"
+ type {
+ tensor_type {
+ elem_type: )" + dataType + R"(
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input0"
+ input: "Input1"
+ output: "Output"
+ name: "addition"
+ op_type: "Add"
+ doc_string: ""
+ domain: ""
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ }
+};
+
+struct AddValidFixture : AddMainFixture
+{
+ AddValidFixture() : AddMainFixture("FLOAT") {
+ Setup();
+ }
+};
+
+struct AddInvalidFixture : AddMainFixture
+{
+ AddInvalidFixture() : AddMainFixture("INT32") { }
+};
+
+struct AddValidBroadcastFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ AddValidBroadcastFixture() {
+
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input0"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Input1"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input0"
+ input: "Input1"
+ output: "Output"
+ name: "addition"
+ op_type: "Add"
+ doc_string: ""
+ domain: ""
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+struct AddInvalidBroadcastFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ AddInvalidBroadcastFixture() {
+
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input0"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Input1"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input0"
+ input: "Input1"
+ output: "Output"
+ name: "addition"
+ op_type: "Add"
+ doc_string: ""
+ domain: ""
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(ValidAddTest, AddValidFixture)
+{
+ RunTest<4>({{"Input0", {1.0f, 2.0f, -3.0f, -4.0f}},
+ {"Input1", {1.0f, 2.0f, 3.0, 4.0f}}}, {{"Output", {2.0, 4.0, 0, 0.0}}});
+}
+
+BOOST_FIXTURE_TEST_CASE(IncorrectDataTypeAdd, AddInvalidFixture)
+{
+ BOOST_CHECK_THROW(Setup(), armnn::ParseException);
+}
+
+BOOST_FIXTURE_TEST_CASE(InvalidBroadcastAdd, AddInvalidBroadcastFixture)
+{
+ BOOST_CHECK_THROW(Setup(), armnn::ParseException);
+}
+
+BOOST_FIXTURE_TEST_CASE(ValidBroadcastAdd, AddValidBroadcastFixture)
+{
+ RunTest<4>({{"Input0", {1.0f, 2.0f, -3.0f, -4.0f}},
+ {"Input1", {1.0f, 2.0f, 3.0, 4.0f}}}, {{"Output", {2.0, 4.0, 0, 0.0}}});
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/BatchNorm.cpp b/src/armnnOnnxParser/test/BatchNorm.cpp
new file mode 100644
index 0000000000..b708770895
--- /dev/null
+++ b/src/armnnOnnxParser/test/BatchNorm.cpp
@@ -0,0 +1,342 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct BatchNormalizationMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ BatchNormalizationMainFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "mean"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "var"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "scale"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "bias"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input"
+ input: "scale"
+ input: "bias"
+ input: "mean"
+ input: "var"
+ output: "Output"
+ name: "batchNorm"
+ op_type: "BatchNormalization"
+ attribute {
+ name: "epsilon"
+ f: 0.0010000000475
+ type: FLOAT
+ }
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 5.0
+ name: "mean"
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 2.0
+ name: "var"
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 0.0
+ name: "bias"
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 1.0
+ name: "scale"
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(ValidBatchNormalizationTest, BatchNormalizationMainFixture)
+{
+ RunTest<4>({{"Input", {1, 2, 3, 4, 5, 6, 7, 8, 9}}}, // Input data.
+ {{"Output", {-2.8277204f, -2.12079024f, -1.4138602f,
+ -0.7069301f, 0.0f, 0.7069301f,
+ 1.4138602f, 2.12079024f, 2.8277204f}}}); // Expected output data.
+}
+
+
+struct BatchNormalizationBisFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ BatchNormalizationBisFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "mean"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "var"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "scale"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "bias"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input"
+ input: "scale"
+ input: "bias"
+ input: "mean"
+ input: "var"
+ output: "Output"
+ name: "batchNorm"
+ op_type: "BatchNormalization"
+ attribute {
+ name: "epsilon"
+ f: 0.00001
+ type: FLOAT
+ }
+ }
+ initializer {
+ dims: 2
+ data_type: FLOAT
+ float_data: 0.0
+ float_data: 3.0
+ name: "mean"
+ }
+ initializer {
+ dims: 2
+ data_type: FLOAT
+ float_data: 1.0
+ float_data: 1.5
+ name: "var"
+ }
+ initializer {
+ dims: 2
+ data_type: FLOAT
+ float_data: 0.0
+ float_data: 1.0
+ name: "bias"
+ }
+ initializer {
+ dims: 2
+ data_type: FLOAT
+ float_data: 1.0
+ float_data: 1.5
+ name: "scale"
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(ValidBatchNormalizationBisTest, BatchNormalizationBisFixture)
+{
+ RunTest<4>({{"Input", {-1, 0.0, 1, 2, 3.0, 4.0}}}, // Input data.
+ {{"Output", {-0.999995f, 0.0, 0.999995f,
+ -0.22474074f, 1.0f, 2.2247407f}}}); // Expected output data.
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/Const.cpp b/src/armnnOnnxParser/test/Const.cpp
new file mode 100644
index 0000000000..594998771b
--- /dev/null
+++ b/src/armnnOnnxParser/test/Const.cpp
@@ -0,0 +1,87 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct ConstMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ ConstMainFixture(const std::string& dataType)
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK "
+ producer_version: "2.5.1 "
+ domain: "ai.cntk "
+ model_version: 1
+ graph {
+ name: "CNTKGraph "
+ node {
+ output: "Output"
+ attribute {
+ name: "value"
+ t {
+ dims: 7
+ data_type: )" + dataType + R"(
+ float_data: 0.0
+ float_data: 1.0
+ float_data: 2.0
+ float_data: 3.0
+ float_data: 4.0
+ float_data: 5.0
+ float_data: 6.0
+
+ }
+ type: FLOAT
+ }
+ name: "constantNode"
+ op_type: "Constant"
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 7
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ }
+};
+
+struct ConstValidFixture : ConstMainFixture
+{
+ ConstValidFixture() : ConstMainFixture("FLOAT") {
+ Setup();
+ }
+};
+
+struct ConstInvalidFixture : ConstMainFixture
+{
+ ConstInvalidFixture() : ConstMainFixture("FLOAT16") { }
+};
+
+BOOST_FIXTURE_TEST_CASE(ValidConstTest, ConstValidFixture)
+{
+ RunTest<1>({ }, {{ "Output" , {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0}}});
+}
+
+BOOST_FIXTURE_TEST_CASE(IncorrectDataTypeConst, ConstInvalidFixture)
+{
+ BOOST_CHECK_THROW( Setup(), armnn::ParseException);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/Constructor.cpp b/src/armnnOnnxParser/test/Constructor.cpp
new file mode 100644
index 0000000000..e234dba5ee
--- /dev/null
+++ b/src/armnnOnnxParser/test/Constructor.cpp
@@ -0,0 +1,16 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+BOOST_AUTO_TEST_CASE(Create)
+{
+ armnnOnnxParser::IOnnxParserPtr parser(armnnOnnxParser::IOnnxParser::Create());
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/Conv2D.cpp b/src/armnnOnnxParser/test/Conv2D.cpp
new file mode 100644
index 0000000000..11a5d1eb87
--- /dev/null
+++ b/src/armnnOnnxParser/test/Conv2D.cpp
@@ -0,0 +1,469 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct SimpleConv2DFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ SimpleConv2DFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Weight"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 3
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ dims: 1
+ dims: 3
+ dims: 3
+ data_type: FLOAT
+ float_data: 2
+ float_data: 1
+ float_data: 0
+ float_data: 6
+ float_data: 2
+ float_data: 1
+ float_data: 4
+ float_data: 1
+ float_data: 2
+ name: "Weight"
+ }
+ node {
+ input: "Input"
+ input: "Weight"
+ output: "Output"
+ name: "Convolution"
+ op_type: "Conv"
+ attribute {
+ name: "kernel_shape"
+ ints: 3
+ ints: 3
+ type: INTS
+ }
+ attribute {
+ name: "strides"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ attribute {
+ name: "auto_pad"
+ s: "VALID"
+ type: STRING
+ }
+ attribute {
+ name: "group"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "dilations"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ doc_string: ""
+ domain: ""
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+struct Conv2DWithBiasesFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ Conv2DWithBiasesFixture() {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Weight"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ dims: 1
+ dims: 2
+ dims: 2
+ data_type: FLOAT
+ float_data: 2
+ float_data: 1
+ float_data: 0
+ float_data: 6
+ name: "Weight"
+ }
+ input {
+ name: "Bias"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 4
+ data_type: FLOAT
+ float_data: 10
+ float_data: 0
+ float_data: 0
+ float_data: 0
+ name: "Bias"
+ }
+ node {
+ input: "Input"
+ input: "Weight"
+ input: "Bias"
+ output: "Output"
+ name: "Convolution"
+ op_type: "Conv"
+ attribute {
+ name: "kernel_shape"
+ ints: 2
+ ints: 2
+ type: INTS
+ }
+ attribute {
+ name: "strides"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ attribute {
+ name: "auto_pad"
+ s: "SAME_UPPER"
+ type: STRING
+ }
+ attribute {
+ name: "group"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "dilations"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ doc_string: ""
+ domain: ""
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+
+struct Conv2DDimReducingFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ Conv2DDimReducingFixture() {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Weight"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 2
+ dims: 3
+ dims: 1
+ dims: 1
+ data_type: FLOAT
+ float_data: -1
+ float_data: 2
+ float_data: 0
+ float_data: 1
+ float_data: 0
+ float_data: 0
+ name: "Weight"
+ }
+ node {
+ input: "Input"
+ input: "Weight"
+ output: "Output"
+ name: "Convolution"
+ op_type: "Conv"
+ attribute {
+ name: "kernel_shape"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ attribute {
+ name: "strides"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ attribute {
+ name: "group"
+ i: 1
+ type: INT
+ }
+ attribute {
+ name: "dilations"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ doc_string: ""
+ domain: ""
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(ValidConvTest, SimpleConv2DFixture)
+{
+ RunTest<4>({{"Input", {1.0, 2.0, 3.0,
+ 4.0, 5.0, 6.0,
+ 7.0, 8.0, 9.0}}},
+ {{"Output", {1.0 * 2 + 2.0 * 1 + 3.0 * 0 +
+ 4.0 * 6 + 5.0 * 2 + 6.0 * 1 +
+ 7.0 * 4 + 8.0 * 1 + 9.0 * 2}}});
+}
+
+BOOST_FIXTURE_TEST_CASE(ValidConvWithBiasTest, Conv2DWithBiasesFixture)
+{
+ RunTest<4>({{"Input", {1.0, 2.0,
+ 3.0, 4.0}}},
+ {{"Output", {1.0 * 2 + 2.0 * 1 + 3.0 * 0 + 4 * 6 + 10,
+ 2.0 * 2 + 0 * 1 + 4.0 * 0 + 0 * 6 + 10,
+ 3.0 * 2 + 4.0 * 1 + 0 * 0 + 0 * 6 + 10,
+ 4.0 * 2 + 0 * 1 + 0 * 0 + 0 * 6 + 10}}});
+}
+
+BOOST_FIXTURE_TEST_CASE(ValidConvDimReducTest, Conv2DDimReducingFixture)
+{
+ RunTest<4>({{"Input", {1.0, 2.0, 3.0, 4.0, -1, -2, 3, 4, 1 , 1, 1, 1 }}},
+ {{"Output", {-1 * 1 + 2 * -1, -1 * 2 + 2 * -2,
+ -1 * 3 + 2 * 3, -1 * 4 + 2 * 4,
+ 1, 2, 3, 4}}});
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/CreateNetwork.cpp b/src/armnnOnnxParser/test/CreateNetwork.cpp
new file mode 100644
index 0000000000..d11f7603b2
--- /dev/null
+++ b/src/armnnOnnxParser/test/CreateNetwork.cpp
@@ -0,0 +1,63 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "google/protobuf/stubs/logging.h"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+BOOST_AUTO_TEST_CASE(CreateNetworkFromString)
+{
+ std::string TestModel = R"(
+ ir_version: 3
+ producer_name: "CNTK "
+ producer_version: "2.5.1 "
+ domain: "ai.cntk "
+ model_version: 1
+ graph {
+ name: "CNTKGraph "
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 10
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+
+ armnnOnnxParser::IOnnxParserPtr parser(armnnOnnxParser::IOnnxParser::Create());
+
+ armnn::INetworkPtr network = parser->CreateNetworkFromString(TestModel.c_str());
+ BOOST_TEST(network.get());
+}
+
+BOOST_AUTO_TEST_CASE(CreateNetworkFromStringWithNullptr)
+{
+ armnnOnnxParser::IOnnxParserPtr parser(armnnOnnxParser::IOnnxParser::Create());
+ BOOST_CHECK_THROW(parser->CreateNetworkFromString(""), armnn::InvalidArgumentException );
+}
+
+BOOST_AUTO_TEST_CASE(CreateNetworkWithInvalidString)
+{
+ auto silencer = google::protobuf::LogSilencer(); //get rid of errors from protobuf
+ armnnOnnxParser::IOnnxParserPtr parser(armnnOnnxParser::IOnnxParser::Create());
+ BOOST_CHECK_THROW(parser->CreateNetworkFromString( "I'm not a model so I should raise an error" ),
+ armnn::ParseException );
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/DepthConv.cpp b/src/armnnOnnxParser/test/DepthConv.cpp
new file mode 100644
index 0000000000..64b0778abc
--- /dev/null
+++ b/src/armnnOnnxParser/test/DepthConv.cpp
@@ -0,0 +1,162 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct SimpleDepthConv2DFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ SimpleDepthConv2DFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Weight"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 3
+ dims: 1
+ dims: 2
+ dims: 2
+ data_type: FLOAT
+ float_data: 1
+ float_data: 1
+ float_data: 1
+ float_data: 1
+ float_data: 2
+ float_data: 2
+ float_data: 2
+ float_data: 2
+ float_data: 3
+ float_data: 3
+ float_data: 3
+ float_data: 3
+ name: "Weight"
+ }
+ node {
+ input: "Input"
+ input: "Weight"
+ output: "Output"
+ name: "Convolution"
+ op_type: "Conv"
+ attribute {
+ name: "kernel_shape"
+ ints: 2
+ ints: 2
+ type: INTS
+ }
+ attribute {
+ name: "strides"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ attribute {
+ name: "auto_pad"
+ s: "VALID"
+ type: STRING
+ }
+ attribute {
+ name: "group"
+ i: 3
+ type: INT
+ }
+ attribute {
+ name: "dilations"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ doc_string: ""
+ domain: ""
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 3
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+
+BOOST_FIXTURE_TEST_CASE(ValidDepthConvTest, SimpleDepthConv2DFixture)
+{
+ RunTest<4>({{"Input", { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}}},
+ {{"Output", { 10, 52, 126 }}});
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/FullyConnected.cpp b/src/armnnOnnxParser/test/FullyConnected.cpp
new file mode 100644
index 0000000000..cbb6c355a4
--- /dev/null
+++ b/src/armnnOnnxParser/test/FullyConnected.cpp
@@ -0,0 +1,597 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+// A MatMul in isolation, not connected to an add. Should result in a non-biased FullyConnected layer.
+struct MatMulFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ MatMulFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK "
+ producer_version: "2.5.1 "
+ domain: "ai.cntk "
+ model_version: 1
+ graph {
+ name: "CNTKGraph "
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Const"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 17.0
+ name: "Const"
+ }
+ node {
+ input: "Input"
+ input: "Const"
+ output: "Output"
+ name: "SimpleMatmul"
+ op_type: "MatMul"
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(MatMul, MatMulFixture)
+{
+ RunTest<1>({{"Input", { 2 }}}, {{"Output", { 34 }}});
+}
+
+// In Onnx fully connected layers are expressed as a MatMul followed by an Add.
+// The OnnxParser must detect this case and convert them to a FullyConnected layer.
+struct FullyConnectedFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ FullyConnectedFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK "
+ producer_version: "2.5.1 "
+ domain: "ai.cntk "
+ model_version: 1
+ graph {
+ name: "CNTKGraph "
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Weight"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 2
+ name: "Weight"
+ }
+ input {
+ name: "Bias"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 1
+ name: "Bias"
+ }
+ node {
+ input: "Input"
+ input: "Weight"
+ output: "AddInput"
+ name: "FCMatmul"
+ op_type: "MatMul"
+ }
+ node {
+ input: "AddInput"
+ input: "Bias"
+ output: "Output"
+ name: "FCAdd"
+ op_type: "Add"
+ }
+ value_info {
+ name: "AddInput"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(FullyConnected, FullyConnectedFixture)
+{
+ RunTest<1>({{"Input", { 3 }}}, {{"Output", { 7 }}});
+}
+
+
+// Similar to FullyConnectedFixture, but this time the MatMul's output is used by two Adds. This should result
+// in two FullyConnected layers being created.
+// I
+// |
+// M -- C
+// / \'
+// C-- A A -- C
+// \ /
+// A
+struct MatMulUsedInTwoFcFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ MatMulUsedInTwoFcFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK "
+ producer_version: "2.5.1 "
+ domain: "ai.cntk "
+ model_version: 1
+ graph {
+ name: "CNTKGraph "
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Weight"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 2
+ name: "Weight"
+ }
+ input {
+ name: "Bias"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 1
+ name: "Bias"
+ }
+ input {
+ name: "Bias_1"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 10.0
+ name: "Bias_1"
+ }
+ node {
+ input: "Input"
+ input: "Weight"
+ output: "AddInput"
+ name: "FCMatmul"
+ op_type: "MatMul"
+ }
+ node {
+ input: "AddInput"
+ input: "Bias"
+ output: "AddOutput"
+ name: "FCAdd"
+ op_type: "Add"
+ }
+ node {
+ input: "AddInput"
+ input: "Bias_1"
+ output: "AddOutput_1"
+ name: "FCAdd_1"
+ op_type: "Add"
+ }
+ node {
+ input: "AddOutput"
+ input: "AddOutput_1"
+ output: "Output"
+ name: "FinalAdd"
+ op_type: "Add"
+ }
+ value_info {
+ name: "AddInput"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ value_info {
+ name: "AddOutput"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ value_info {
+ name: "AddOutput_1"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(MatMulUsedInTwoFc, MatMulUsedInTwoFcFixture)
+{
+ RunTest<1>({{"Input", { 3 }}}, {{"Output", { 23 }}});
+}
+
+
+// Similar to MatMulUsedInTwoFc, but this time the Adds are 'staggered' (see diagram), which means that only one
+// FullyConnected layer can be created (the other should just be an Add).
+// I
+// |
+// M -- C1
+// / \'
+// C2 -- A |
+// \ /
+// A
+struct MatMulUsedInTwoFcStaggeredFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ MatMulUsedInTwoFcStaggeredFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK "
+ producer_version: "2.5.1 "
+ domain: "ai.cntk "
+ model_version: 1
+ graph {
+ name: "CNTKGraph "
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Weight"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 2
+ name: "Weight"
+ }
+ input {
+ name: "Bias"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ initializer {
+ dims: 1
+ data_type: FLOAT
+ float_data: 1
+ name: "Bias"
+ }
+ node {
+ input: "Input"
+ input: "Weight"
+ output: "AddInput"
+ name: "MatmulFC&NFC"
+ op_type: "MatMul"
+ }
+ node {
+ input: "AddInput"
+ input: "Bias"
+ output: "AddOutput"
+ name: "FCAdd"
+ op_type: "Add"
+ }
+
+ node {
+ input: "AddInput"
+ input: "AddOutput"
+ output: "Output"
+ name: "FinalAdd"
+ op_type: "Add"
+ }
+ value_info {
+ name: "AddInput"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ value_info {
+ name: "AddOutput"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(MatMulUsedInTwoFcStaggered, MatMulUsedInTwoFcStaggeredFixture)
+{
+ RunTest<1>({{"Input", { 3 }}}, {{"Output", { 13 }}});
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/GetInputsOutputs.cpp b/src/armnnOnnxParser/test/GetInputsOutputs.cpp
new file mode 100644
index 0000000000..2e605a6322
--- /dev/null
+++ b/src/armnnOnnxParser/test/GetInputsOutputs.cpp
@@ -0,0 +1,255 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+#include <boost/test/unit_test.hpp>
+#include "../OnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+#include <onnx/onnx.pb.h>
+#include "google/protobuf/stubs/logging.h"
+
+
+using ModelPtr = std::unique_ptr<onnx::ModelProto>;
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct GetInputsOutputsMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ explicit GetInputsOutputsMainFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input"
+ output: "Output"
+ name: "ActivationLayer"
+ op_type: "Relu"
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+
+BOOST_FIXTURE_TEST_CASE(GetInput, GetInputsOutputsMainFixture)
+{
+ ModelPtr model = armnnOnnxParser::OnnxParser::LoadModelFromString(m_Prototext.c_str());
+ std::vector<std::string> tensors = armnnOnnxParser::OnnxParser::GetInputs(model);
+ BOOST_CHECK_EQUAL(1, tensors.size());
+ BOOST_CHECK_EQUAL("Input", tensors[0]);
+
+}
+
+BOOST_FIXTURE_TEST_CASE(GetOutput, GetInputsOutputsMainFixture)
+{
+ ModelPtr model = armnnOnnxParser::OnnxParser::LoadModelFromString(m_Prototext.c_str());
+ std::vector<std::string> tensors = armnnOnnxParser::OnnxParser::GetOutputs(model);
+ BOOST_CHECK_EQUAL(1, tensors.size());
+ BOOST_CHECK_EQUAL("Output", tensors[0]);
+}
+
+struct GetEmptyInputsOutputsFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ GetEmptyInputsOutputsFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK "
+ producer_version: "2.5.1 "
+ domain: "ai.cntk "
+ model_version: 1
+ graph {
+ name: "CNTKGraph "
+ node {
+ output: "Output"
+ attribute {
+ name: "value"
+ t {
+ dims: 7
+ data_type: FLOAT
+ float_data: 0.0
+ float_data: 1.0
+ float_data: 2.0
+ float_data: 3.0
+ float_data: 4.0
+ float_data: 5.0
+ float_data: 6.0
+
+ }
+ type: FLOAT
+ }
+ name: "constantNode"
+ op_type: "Constant"
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 7
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(GetEmptyInputs, GetEmptyInputsOutputsFixture)
+{
+ ModelPtr model = armnnOnnxParser::OnnxParser::LoadModelFromString(m_Prototext.c_str());
+ std::vector<std::string> tensors = armnnOnnxParser::OnnxParser::GetInputs(model);
+ BOOST_CHECK_EQUAL(0, tensors.size());
+}
+
+BOOST_AUTO_TEST_CASE(GetInputsNullModel)
+{
+ BOOST_CHECK_THROW(armnnOnnxParser::OnnxParser::LoadModelFromString(""), armnn::InvalidArgumentException);
+}
+
+BOOST_AUTO_TEST_CASE(GetOutputsNullModel)
+{
+ auto silencer = google::protobuf::LogSilencer(); //get rid of errors from protobuf
+ BOOST_CHECK_THROW(armnnOnnxParser::OnnxParser::LoadModelFromString("nknnk"), armnn::ParseException);
+}
+
+struct GetInputsMultipleFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ GetInputsMultipleFixture() {
+
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input0"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Input1"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input0"
+ input: "Input1"
+ output: "Output"
+ name: "addition"
+ op_type: "Add"
+ doc_string: ""
+ domain: ""
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(GetInputsMultipleInputs, GetInputsMultipleFixture)
+{
+ ModelPtr model = armnnOnnxParser::OnnxParser::LoadModelFromString(m_Prototext.c_str());
+ std::vector<std::string> tensors = armnnOnnxParser::OnnxParser::GetInputs(model);
+ BOOST_CHECK_EQUAL(2, tensors.size());
+ BOOST_CHECK_EQUAL("Input0", tensors[0]);
+ BOOST_CHECK_EQUAL("Input1", tensors[1]);
+}
+
+
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/Pooling.cpp b/src/armnnOnnxParser/test/Pooling.cpp
new file mode 100644
index 0000000000..8e2f0fee00
--- /dev/null
+++ b/src/armnnOnnxParser/test/Pooling.cpp
@@ -0,0 +1,310 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct PoolingMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ PoolingMainFixture(const std::string& dataType, const std::string& op)
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: )" + dataType + R"(
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input"
+ output: "Output"
+ name: "Pooling"
+ op_type: )" + op + R"(
+ attribute {
+ name: "kernel_shape"
+ ints: 2
+ ints: 2
+ type: INTS
+ }
+ attribute {
+ name: "strides"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ attribute {
+ name: "pads"
+ ints: 0
+ ints: 0
+ ints: 0
+ ints: 0
+ type: INTS
+ }
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ }
+};
+
+struct MaxPoolValidFixture : PoolingMainFixture
+{
+ MaxPoolValidFixture() : PoolingMainFixture("FLOAT", "\"MaxPool\"") {
+ Setup();
+ }
+};
+
+struct MaxPoolInvalidFixture : PoolingMainFixture
+{
+ MaxPoolInvalidFixture() : PoolingMainFixture("FLOAT16", "\"MaxPool\"") { }
+};
+
+BOOST_FIXTURE_TEST_CASE(ValidMaxPoolTest, MaxPoolValidFixture)
+{
+ RunTest<4>({{"Input", {1.0f, 2.0f, 3.0f, -4.0f}}}, {{"Output", {3.0f}}});
+}
+
+struct AvgPoolValidFixture : PoolingMainFixture
+{
+ AvgPoolValidFixture() : PoolingMainFixture("FLOAT", "\"AveragePool\"") {
+ Setup();
+ }
+};
+
+struct PoolingWithPadFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ PoolingWithPadFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input"
+ output: "Output"
+ name: "Pooling"
+ op_type: "AveragePool"
+ attribute {
+ name: "kernel_shape"
+ ints: 4
+ ints: 4
+ type: INTS
+ }
+ attribute {
+ name: "strides"
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ attribute {
+ name: "pads"
+ ints: 1
+ ints: 1
+ ints: 1
+ ints: 1
+ type: INTS
+ }
+ attribute {
+ name: "count_include_pad"
+ i: 1
+ type: INT
+ }
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(AveragePoolValid, AvgPoolValidFixture)
+{
+ RunTest<4>({{"Input", {1.0f, 2.0f, 3.0f, -4.0f}}}, {{"Output", {0.5}}});
+}
+
+BOOST_FIXTURE_TEST_CASE(ValidAvgWithPadTest, PoolingWithPadFixture)
+{
+ RunTest<4>({{"Input", {1.0f, 2.0f, 3.0f, -4.0f}}}, {{"Output", {1.0/8.0}}});
+}
+
+struct GlobalAvgFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ GlobalAvgFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input"
+ output: "Output"
+ name: "Pooling"
+ op_type: "GlobalAveragePool"
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 1
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(GlobalAvgTest, GlobalAvgFixture)
+{
+ RunTest<4>({{"Input", {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0}}}, {{"Output", {10/4.0, 26/4.0}}});
+}
+
+BOOST_FIXTURE_TEST_CASE(IncorrectDataTypeMaxPool, MaxPoolInvalidFixture)
+{
+ BOOST_CHECK_THROW(Setup(), armnn::ParseException);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/ProtoxtFixture.cpp b/src/armnnOnnxParser/test/ProtoxtFixture.cpp
new file mode 100644
index 0000000000..2bfeadf2e3
--- /dev/null
+++ b/src/armnnOnnxParser/test/ProtoxtFixture.cpp
@@ -0,0 +1,81 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct ProtoxtTestFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ ProtoxtTestFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK "
+ producer_version: "2.5.1 "
+ domain: "ai.cntk "
+ model_version: 1
+ graph {
+ name: "CNTKGraph "
+ node {
+ input: "Input"
+ output: "Output"
+ name: "Plus112"
+ op_type: "Add "
+ }
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 1
+ }
+ dim {
+ dim_value: 10
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ // Setup();
+ }
+};
+
+
+BOOST_FIXTURE_TEST_CASE(ProtoxtTest, ProtoxtTestFixture)
+{
+ //TODO : add a test to check if the inputs and outputs are correctly inferred.
+}
+
+BOOST_FIXTURE_TEST_CASE(ProtoxtTestWithBadInputs, ProtoxtTestFixture)
+{
+
+ // BOOST_CHECK_THROW(RunTest<4>({{ "InexistantInput" , {0.0, 1.0, 2.0, 3.0}}},
+ // {{ "InexistantOutput" , {0.0, 1.0, 2.0, 3.0}}}),
+ // armnn::InvalidArgumentException );
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/Relu.cpp b/src/armnnOnnxParser/test/Relu.cpp
new file mode 100644
index 0000000000..991f64c3fc
--- /dev/null
+++ b/src/armnnOnnxParser/test/Relu.cpp
@@ -0,0 +1,70 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct ReluMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ ReluMainFixture()
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input"
+ output: "Output"
+ name: "ActivationLayer"
+ op_type: "Relu"
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ Setup();
+ }
+};
+
+BOOST_FIXTURE_TEST_CASE(ValidReluTest, ReluMainFixture)
+{
+ RunTest<1>({{"Input", { -1.0f, -0.5f, 1.25f, -3.0f}}},
+ {{ "Output", { 0.0f, 0.0f, 1.25f, 0.0f}}});
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/armnnOnnxParser/test/Reshape.cpp b/src/armnnOnnxParser/test/Reshape.cpp
new file mode 100644
index 0000000000..a740bb0ff3
--- /dev/null
+++ b/src/armnnOnnxParser/test/Reshape.cpp
@@ -0,0 +1,110 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// See LICENSE file in the project root for full license information.
+//
+
+#include <boost/test/unit_test.hpp>
+#include "armnnOnnxParser/IOnnxParser.hpp"
+#include "ParserPrototxtFixture.hpp"
+
+BOOST_AUTO_TEST_SUITE(OnnxParser)
+
+struct ReshapeMainFixture : public armnnUtils::ParserPrototxtFixture<armnnOnnxParser::IOnnxParser>
+{
+ ReshapeMainFixture(const std::string& dataType)
+ {
+ m_Prototext = R"(
+ ir_version: 3
+ producer_name: "CNTK"
+ producer_version: "2.5.1"
+ domain: "ai.cntk"
+ model_version: 1
+ graph {
+ name: "CNTKGraph"
+ input {
+ name: "Input"
+ type {
+ tensor_type {
+ elem_type: )" + dataType + R"(
+ shape {
+ dim {
+ dim_value: 4
+ }
+ }
+ }
+ }
+ }
+ input {
+ name: "Shape"
+ type {
+ tensor_type {
+ elem_type: INT64
+ shape {
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ node {
+ input: "Input"
+ input: "Shape"
+ output: "Output"
+ name: "reshape"
+ op_type: "Reshape"
+
+ }
+ initializer {
+ dims: 2
+ data_type: INT64
+ int64_data: 2
+ int64_data: 2
+ name: "Shape"
+ }
+ output {
+ name: "Output"
+ type {
+ tensor_type {
+ elem_type: FLOAT
+ shape {
+ dim {
+ dim_value: 2
+ }
+ dim {
+ dim_value: 2
+ }
+ }
+ }
+ }
+ }
+ }
+ opset_import {
+ version: 7
+ })";
+ }
+};
+
+struct ReshapeValidFixture : ReshapeMainFixture
+{
+ ReshapeValidFixture() : ReshapeMainFixture("FLOAT") {
+ Setup();
+ }
+};
+
+struct ReshapeInvalidFixture : ReshapeMainFixture
+{
+ ReshapeInvalidFixture() : ReshapeMainFixture("FLOAT16") { }
+};
+
+BOOST_FIXTURE_TEST_CASE(ValidReshapeTest, ReshapeValidFixture)
+{
+ RunTest<2>({{"Input", { 0.0f, 1.0f, 2.0f, 3.0f }}}, {{"Output", { 0.0f, 1.0f, 2.0f, 3.0f }}});
+}
+
+BOOST_FIXTURE_TEST_CASE(IncorrectDataTypeReshape, ReshapeInvalidFixture)
+{
+ BOOST_CHECK_THROW(Setup(), armnn::ParseException);
+}
+
+BOOST_AUTO_TEST_SUITE_END()