From 4fcda0101ec3d110c1d6d7bee5c83416b645528a Mon Sep 17 00:00:00 2001 From: telsoa01 Date: Fri, 9 Mar 2018 14:13:49 +0000 Subject: Release 18.02 Change-Id: Id3c11dc5ee94ef664374a988fcc6901e9a232fa6 --- src/armnnCaffeParser/test/TestAdd.cpp | 70 ++++++++++++ src/armnnCaffeParser/test/TestConcat.cpp | 73 +++++++++++++ src/armnnCaffeParser/test/TestDropout.cpp | 53 +++++++++ src/armnnCaffeParser/test/TestInPlace.cpp | 98 +++++++++++++++++ src/armnnCaffeParser/test/TestInputs.cpp | 120 +++++++++++++++++++++ src/armnnCaffeParser/test/TestMul.cpp | 73 +++++++++++++ .../test/TestMultiInputsOutputs.cpp | 54 ++++++++++ src/armnnCaffeParser/test/TestPooling2d.cpp | 54 ++++++++++ src/armnnCaffeParser/test/TestSplit.cpp | 47 ++++++++ 9 files changed, 642 insertions(+) create mode 100644 src/armnnCaffeParser/test/TestAdd.cpp create mode 100644 src/armnnCaffeParser/test/TestConcat.cpp create mode 100644 src/armnnCaffeParser/test/TestDropout.cpp create mode 100644 src/armnnCaffeParser/test/TestInPlace.cpp create mode 100644 src/armnnCaffeParser/test/TestInputs.cpp create mode 100644 src/armnnCaffeParser/test/TestMul.cpp create mode 100644 src/armnnCaffeParser/test/TestMultiInputsOutputs.cpp create mode 100644 src/armnnCaffeParser/test/TestPooling2d.cpp create mode 100644 src/armnnCaffeParser/test/TestSplit.cpp (limited to 'src/armnnCaffeParser/test') diff --git a/src/armnnCaffeParser/test/TestAdd.cpp b/src/armnnCaffeParser/test/TestAdd.cpp new file mode 100644 index 0000000000..7d91924638 --- /dev/null +++ b/src/armnnCaffeParser/test/TestAdd.cpp @@ -0,0 +1,70 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(CaffeParser) + +struct AddFixture : public ParserPrototxtFixture +{ + AddFixture() + { + m_Prototext = "name: \"MinimalAdd\"\n" + "layer {\n" + " name: \"data\"\n" + " type: \"Input\"\n" + " top: \"data\"\n" + " input_param { shape: { dim: 1 dim: 1 dim: 4 dim: 4 } }\n" + "}\n" + "layer {\n" + " bottom: \"data\"\n" + " top: \"pool1\"\n" + " name: \"pool1\"\n" + " type: \"Pooling\"\n" + " pooling_param {\n" + " kernel_size: 2\n" + " stride: 2\n" + " pool: MAX\n" + " }\n" + "}\n" + "layer {\n" + " bottom: \"data\"\n" + " top: \"pool2\"\n" + " name: \"pool2\"\n" + " type: \"Pooling\"\n" + " pooling_param {\n" + " kernel_size: 2\n" + " stride: 2\n" + " pool: MAX\n" + " }\n" + "}\n" + "layer {\n" + " bottom: \"pool1\"\n" + " bottom: \"pool2\"\n" + " top: \"add\"\n" + " name: \"add\"\n" + " type: \"Eltwise\"\n" + "}\n"; + SetupSingleInputSingleOutput("data", "add"); + } +}; + +BOOST_FIXTURE_TEST_CASE(ParseAdd, AddFixture) +{ + RunTest<4>( + { + 0, 1, 0, 0, + 0, 0, 0, 0, + 0, 0, 1, 0, + 1, 0, 1, 1 + }, + { + 2, 0, + 2, 2 + }); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnCaffeParser/test/TestConcat.cpp b/src/armnnCaffeParser/test/TestConcat.cpp new file mode 100644 index 0000000000..441c28c837 --- /dev/null +++ b/src/armnnCaffeParser/test/TestConcat.cpp @@ -0,0 +1,73 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(CaffeParser) + +struct ConcatFixture : public ParserPrototxtFixture +{ + ConcatFixture() + { + m_Prototext = "name: \"Concat\"\n" + "layer {\n" + " name: \"data\"\n" + " type: \"Input\"\n" + " top: \"data\"\n" + " input_param { shape: { dim: 1 dim: 1 dim: 4 dim: 4 } }\n" + "}\n" + "layer {\n" + " bottom: \"data\"\n" + " top: \"pool1\"\n" + " name: \"pool1\"\n" + " type: \"Pooling\"\n" + " pooling_param {\n" + " kernel_size: 2\n" + " stride: 2\n" + " pool: MAX\n" + " }\n" + "}\n" + "layer {\n" + " bottom: \"data\"\n" + " top: \"pool2\"\n" + " name: \"pool2\"\n" + " type: \"Pooling\"\n" + " pooling_param {\n" + " kernel_size: 2\n" + " stride: 2\n" + " pool: MAX\n" + " }\n" + "}\n" + "layer {\n" + " bottom: \"pool1\"\n" + " bottom: \"pool2\"\n" + " top: \"concat\"\n" + " name: \"concat\"\n" + " type: \"Concat\"\n" + "}\n"; + SetupSingleInputSingleOutput("data", "concat"); + } +}; + +BOOST_FIXTURE_TEST_CASE(ParseConcat, ConcatFixture) +{ + RunTest<4>( + { + 0, 1, 0, 0, + 0, 0, 0, 0, + 0, 0, 1, 0, + 1, 0, 1, 1 + }, + { + 1, 0, + 1, 1, + + 1, 0, + 1, 1 + }); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnCaffeParser/test/TestDropout.cpp b/src/armnnCaffeParser/test/TestDropout.cpp new file mode 100644 index 0000000000..16f2c2728c --- /dev/null +++ b/src/armnnCaffeParser/test/TestDropout.cpp @@ -0,0 +1,53 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// + +#include +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(CaffeParser) + +struct DropoutFixture : public ParserPrototxtFixture +{ + DropoutFixture() + { + m_Prototext = "name: \"DropoutFixture\"\n" + "layer {\n" + " name: \"data\"\n" + " type: \"Input\"\n" + " top: \"data\"\n" + " input_param { shape: { dim: 1 dim: 1 dim: 2 dim: 2 } }\n" + "}\n" + "layer {\n" + " bottom: \"data\"\n" + " top: \"drop1\"\n" + " name: \"drop1\"\n" + " type: \"Dropout\"\n" + "}\n" + "layer {\n" + " bottom: \"drop1\"\n" + " bottom: \"drop1\"\n" + " top: \"add\"\n" + " name: \"add\"\n" + " type: \"Eltwise\"\n" + "}\n"; + SetupSingleInputSingleOutput("data", "add"); + } +}; + +BOOST_FIXTURE_TEST_CASE(ParseDropout, DropoutFixture) +{ + RunTest<4>( + { + 1, 2, + 3, 4, + }, + { + 2, 4, + 6, 8 + }); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnCaffeParser/test/TestInPlace.cpp b/src/armnnCaffeParser/test/TestInPlace.cpp new file mode 100644 index 0000000000..3954baa75b --- /dev/null +++ b/src/armnnCaffeParser/test/TestInPlace.cpp @@ -0,0 +1,98 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(CaffeParser) + +// The pooling layer should take its input from the relu, not the add directly. +struct InPlaceFixture : public ParserPrototxtFixture +{ + InPlaceFixture() + { + m_Prototext = R"( +name: "InPlace" +layer { + name: "data" + type: "Input" + top: "data" + input_param { shape: { dim: 1 dim: 1 dim: 1 dim: 1 } } +} +layer { + bottom: "data" + bottom: "data" + top: "add" + name: "add" + type: "Eltwise" +} +layer { + name: "relu" + type: "ReLU" + bottom: "add" + top: "relu" + phase: TEST +} +layer { + name: "pool" + type: "Pooling" + bottom: "relu" + top: "pool" + phase: TEST + pooling_param { + pool: MAX + kernel_size: 1 + stride: 1 + } +} + )"; + SetupSingleInputSingleOutput("data", "pool"); + } +}; + +BOOST_FIXTURE_TEST_CASE(ParseInPlace, InPlaceFixture) +{ + RunTest<1>({ -1.0f }, { 0.0f }); +} + +// The requested output of the network is a layer which has an activation attached. +// The output of the network should therefore actually be the activation layer. +struct InPlaceOutputFixture : public ParserPrototxtFixture +{ + InPlaceOutputFixture() + { + m_Prototext = R"( +name: "InPlace" +layer { + name: "data" + type: "Input" + top: "data" + input_param { shape: { dim: 1 dim: 1 dim: 1 dim: 1 } } +} +layer { + bottom: "data" + bottom: "data" + top: "add" + name: "add" + type: "Eltwise" +} +layer { + name: "relu" + type: "ReLU" + bottom: "add" + top: "add" + phase: TEST +} + )"; + SetupSingleInputSingleOutput("data", "add"); + } +}; + +BOOST_FIXTURE_TEST_CASE(InPlaceOutput, InPlaceOutputFixture) +{ + RunTest<1>({ -1.0f }, { 0.0f }); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnCaffeParser/test/TestInputs.cpp b/src/armnnCaffeParser/test/TestInputs.cpp new file mode 100644 index 0000000000..f0e2343a33 --- /dev/null +++ b/src/armnnCaffeParser/test/TestInputs.cpp @@ -0,0 +1,120 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "armnn/IRuntime.hpp" +#include "armnn/INetwork.hpp" +#include "armnn/Exceptions.hpp" + +#include "test/TensorHelpers.hpp" + +#include + +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(CaffeParser) + + +BOOST_AUTO_TEST_CASE(InputShapes) +{ + std::string explicitInput = "name: \"Minimal\"\n" + "layer {\n" + " name: \"data\"\n" + " type: \"Input\"\n" + " top: \"data\"\n" + " input_param { shape: { dim: 1 dim: 2 dim: 3 dim: 4 } }\n" + "}"; + std::string implicitInput = "name: \"Minimal\"\n" + "input: \"data\" \n" + "input_dim: 1 \n" + "input_dim: 2 \n" + "input_dim: 3 \n" + "input_dim: 4 \n"; + std::string implicitInputNoShape = "name: \"Minimal\"\n" + "input: \"data\" \n"; + + armnn::IRuntimePtr runtime(armnn::IRuntime::Create(armnn::Compute::CpuRef)); + armnnCaffeParser::ICaffeParserPtr parser(armnnCaffeParser::ICaffeParser::Create()); + armnn::INetworkPtr network(nullptr, nullptr); + armnn::NetworkId netId; + + // Check everything works normally + { + network = parser->CreateNetworkFromString(explicitInput.c_str(), {}, { "data" }); + BOOST_TEST(network.get()); + runtime->LoadNetwork(netId, Optimize(*network, runtime->GetDeviceSpec())); + + armnnCaffeParser::BindingPointInfo inputBindingInfo = parser->GetNetworkInputBindingInfo("data"); + armnn::TensorInfo inputTensorInfo = inputBindingInfo.second; + BOOST_TEST((inputTensorInfo == runtime->GetInputTensorInfo(netId, inputBindingInfo.first))); + + BOOST_TEST(inputTensorInfo.GetShape()[0] == 1); + BOOST_TEST(inputTensorInfo.GetShape()[1] == 2); + BOOST_TEST(inputTensorInfo.GetShape()[2] == 3); + BOOST_TEST(inputTensorInfo.GetShape()[3] == 4); + } + + // Check everything works with implicit input + { + network = parser->CreateNetworkFromString(implicitInput.c_str(), {}, { "data" }); + BOOST_TEST(network.get()); + runtime->LoadNetwork(netId, Optimize(*network, runtime->GetDeviceSpec())); + + armnnCaffeParser::BindingPointInfo inputBindingInfo = parser->GetNetworkInputBindingInfo("data"); + armnn::TensorInfo inputTensorInfo = inputBindingInfo.second; + BOOST_TEST((inputTensorInfo == runtime->GetInputTensorInfo(netId, inputBindingInfo.first))); + + BOOST_TEST(inputTensorInfo.GetShape()[0] == 1); + BOOST_TEST(inputTensorInfo.GetShape()[1] == 2); + BOOST_TEST(inputTensorInfo.GetShape()[2] == 3); + BOOST_TEST(inputTensorInfo.GetShape()[3] == 4); + } + + // Check everything works with implicit and passing shape + { + network = parser->CreateNetworkFromString(implicitInput.c_str(), { {"data", { 2, 2, 3, 4 } } }, { "data" }); + BOOST_TEST(network.get()); + runtime->LoadNetwork(netId, Optimize(*network, runtime->GetDeviceSpec())); + + armnnCaffeParser::BindingPointInfo inputBindingInfo = parser->GetNetworkInputBindingInfo("data"); + armnn::TensorInfo inputTensorInfo = inputBindingInfo.second; + BOOST_TEST((inputTensorInfo == runtime->GetInputTensorInfo(netId, inputBindingInfo.first))); + + BOOST_TEST(inputTensorInfo.GetShape()[0] == 2); + BOOST_TEST(inputTensorInfo.GetShape()[1] == 2); + BOOST_TEST(inputTensorInfo.GetShape()[2] == 3); + BOOST_TEST(inputTensorInfo.GetShape()[3] == 4); + } + + // Check everything works with implicit (no shape) and passing shape + { + network = parser->CreateNetworkFromString(implicitInputNoShape.c_str(), {{"data", {2, 2, 3, 4} }}, { "data" }); + BOOST_TEST(network.get()); + runtime->LoadNetwork(netId, Optimize(*network, runtime->GetDeviceSpec())); + + armnnCaffeParser::BindingPointInfo inputBindingInfo = parser->GetNetworkInputBindingInfo("data"); + armnn::TensorInfo inputTensorInfo = inputBindingInfo.second; + BOOST_TEST((inputTensorInfo == runtime->GetInputTensorInfo(netId, inputBindingInfo.first))); + + BOOST_TEST(inputTensorInfo.GetShape()[0] == 2); + BOOST_TEST(inputTensorInfo.GetShape()[1] == 2); + BOOST_TEST(inputTensorInfo.GetShape()[2] == 3); + BOOST_TEST(inputTensorInfo.GetShape()[3] == 4); + } + + // Check exception on incompatible shapes + { + BOOST_CHECK_THROW(parser->CreateNetworkFromString(implicitInput.c_str(), {{"data",{ 2, 2, 3, 2 }}}, {"data"}), + armnn::ParseException); + } + + // Check exception when no shape available + { + BOOST_CHECK_THROW(parser->CreateNetworkFromString(implicitInputNoShape.c_str(), {}, { "data" }), + armnn::ParseException); + } +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnCaffeParser/test/TestMul.cpp b/src/armnnCaffeParser/test/TestMul.cpp new file mode 100644 index 0000000000..b53318e81e --- /dev/null +++ b/src/armnnCaffeParser/test/TestMul.cpp @@ -0,0 +1,73 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(CaffeParser) + +struct MulFixture : public ParserPrototxtFixture +{ + MulFixture() + { + m_Prototext = "name: \"MinimalMul\"\n" + "layer {\n" + " name: \"data\"\n" + " type: \"Input\"\n" + " top: \"data\"\n" + " input_param { shape: { dim: 1 dim: 1 dim: 4 dim: 4 } }\n" + "}\n" + "layer {\n" + " bottom: \"data\"\n" + " top: \"pool1\"\n" + " name: \"pool1\"\n" + " type: \"Pooling\"\n" + " pooling_param {\n" + " kernel_size: 2\n" + " stride: 2\n" + " pool: MAX\n" + " }\n" + "}\n" + "layer {\n" + " bottom: \"data\"\n" + " top: \"pool2\"\n" + " name: \"pool2\"\n" + " type: \"Pooling\"\n" + " pooling_param {\n" + " kernel_size: 2\n" + " stride: 2\n" + " pool: MAX\n" + " }\n" + "}\n" + "layer {\n" + " bottom: \"pool1\"\n" + " bottom: \"pool2\"\n" + " top: \"mul\"\n" + " name: \"mul\"\n" + " type: \"Eltwise\"\n" + " eltwise_param {\n" + " operation: 0\n" + " }\n" + "}\n"; + SetupSingleInputSingleOutput("data", "mul"); + } +}; + +BOOST_FIXTURE_TEST_CASE(ParseMul, MulFixture) +{ + RunTest<4>( + { + 0, 1, 0, 0, + 0, 0, 0, 0, + 0, 0, 1, 0, + 1, 0, 1, 1 + }, + { + 1, 0, + 1, 1 + }); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnCaffeParser/test/TestMultiInputsOutputs.cpp b/src/armnnCaffeParser/test/TestMultiInputsOutputs.cpp new file mode 100644 index 0000000000..cd87246bee --- /dev/null +++ b/src/armnnCaffeParser/test/TestMultiInputsOutputs.cpp @@ -0,0 +1,54 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(CaffeParser) + +struct MultiInputsOutputsFixture : public ParserPrototxtFixture +{ + MultiInputsOutputsFixture() + { + m_Prototext = R"( +name: "MultiInputsOutputs" +layer { + name: "input1" + type: "Input" + top: "input1" + input_param { shape: { dim: 1 } } +} +layer { + name: "input2" + type: "Input" + top: "input2" + input_param { shape: { dim: 1 } } +} +layer { + bottom: "input1" + bottom: "input2" + top: "add1" + name: "add1" + type: "Eltwise" +} +layer { + bottom: "input2" + bottom: "input1" + top: "add2" + name: "add2" + type: "Eltwise" +} + )"; + Setup({ }, { "add1", "add2" }); + } +}; + +BOOST_FIXTURE_TEST_CASE(MultiInputsOutputs, MultiInputsOutputsFixture) +{ + RunTest<1>({ { "input1",{ 12.0f } },{ "input2",{ 13.0f } } }, + { { "add1",{ 25.0f } },{ "add2",{ 25.0f } } }); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnCaffeParser/test/TestPooling2d.cpp b/src/armnnCaffeParser/test/TestPooling2d.cpp new file mode 100644 index 0000000000..25cd124648 --- /dev/null +++ b/src/armnnCaffeParser/test/TestPooling2d.cpp @@ -0,0 +1,54 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(CaffeParser) + +struct GlobalPoolingFixture : public ParserPrototxtFixture +{ + GlobalPoolingFixture() + { + m_Prototext = "name: \"GlobalPooling\"\n" + "layer {\n" + " name: \"data\"\n" + " type: \"Input\"\n" + " top: \"data\"\n" + " input_param { shape: { dim: 1 dim: 3 dim: 2 dim: 2 } }\n" + "}\n" + "layer {\n" + " bottom: \"data\"\n" + " top: \"pool1\"\n" + " name: \"pool1\"\n" + " type: \"Pooling\"\n" + " pooling_param {\n" + " pool: AVE\n" + " global_pooling: true\n" + " }\n" + "}\n"; + SetupSingleInputSingleOutput("data", "pool1"); + } +}; + +BOOST_FIXTURE_TEST_CASE(GlobalPooling, GlobalPoolingFixture) +{ + RunTest<4>( + { + 1,3, + 5,7, + + 2,2, + 2,2, + + 4,4, + 6,6 + }, + { + 4, 2, 5 + }); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/armnnCaffeParser/test/TestSplit.cpp b/src/armnnCaffeParser/test/TestSplit.cpp new file mode 100644 index 0000000000..c2f29fb4f3 --- /dev/null +++ b/src/armnnCaffeParser/test/TestSplit.cpp @@ -0,0 +1,47 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// See LICENSE file in the project root for full license information. +// +#include +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "ParserPrototxtFixture.hpp" + +BOOST_AUTO_TEST_SUITE(CaffeParser) + +struct SplitFixture : public ParserPrototxtFixture +{ + SplitFixture() + { + m_Prototext = R"( +name: "Split" +layer { + name: "data" + type: "Input" + top: "data" + input_param { shape: { dim: 1 dim: 1 dim: 1 dim: 1 } } +} +layer { + name: "split" + type: "Split" + bottom: "data" + top: "split_top0" + top: "split_top1" +} +layer { + bottom: "split_top0" + bottom: "split_top1" + top: "add" + name: "add" + type: "Eltwise" +} + )"; + SetupSingleInputSingleOutput("data", "add"); + } +}; + +BOOST_FIXTURE_TEST_CASE(Split, SplitFixture) +{ + RunTest<1>({ 1.0f }, { 2.0f }); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1