diff options
author | telsoa01 <telmo.soares@arm.com> | 2018-03-09 14:13:49 +0000 |
---|---|---|
committer | telsoa01 <telmo.soares@arm.com> | 2018-03-09 14:13:49 +0000 |
commit | 4fcda0101ec3d110c1d6d7bee5c83416b645528a (patch) | |
tree | c9a70aeb2887006160c1b3d265c27efadb7bdbae /src/armnnCaffeParser/test/TestInputs.cpp | |
download | armnn-4fcda0101ec3d110c1d6d7bee5c83416b645528a.tar.gz |
Release 18.02
Change-Id: Id3c11dc5ee94ef664374a988fcc6901e9a232fa6
Diffstat (limited to 'src/armnnCaffeParser/test/TestInputs.cpp')
-rw-r--r-- | src/armnnCaffeParser/test/TestInputs.cpp | 120 |
1 files changed, 120 insertions, 0 deletions
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 <boost/test/unit_test.hpp> +#include "armnnCaffeParser/ICaffeParser.hpp" +#include "armnn/IRuntime.hpp" +#include "armnn/INetwork.hpp" +#include "armnn/Exceptions.hpp" + +#include "test/TensorHelpers.hpp" + +#include <string> + +#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() |