14 #include <fmt/format.h> 22 template<
typename TParser>
36 const std::string& inputName,
37 const std::string& outputName);
40 const std::string& inputName,
41 const std::string& outputName);
42 void Setup(
const std::map<std::string, armnn::TensorShape>& inputShapes,
43 const std::vector<std::string>& requestedOutputs);
46 const std::map<std::string,armnn::TensorShape>& inputShapes,
47 const std::vector<std::string>& requestedOutputs);
52 template <std::
size_t NumOutputDimensions>
53 void RunTest(
const std::vector<float>& inputData,
const std::vector<float>& expectedOutputData);
57 template <std::
size_t NumOutputDimensions>
58 void RunComparisonTest(
const std::map<std::string, std::vector<float>>& inputData,
59 const std::map<std::string, std::vector<uint8_t>>& expectedOutputData);
63 template <std::
size_t NumOutputDimensions,
typename T =
float>
64 void RunTest(
const std::map<std::string, std::vector<float>>& inputData,
65 const std::map<std::string, std::vector<T>>& expectedOutputData);
68 std::unique_ptr<TParser, void(*)(TParser* parser)>
m_Parser;
84 template<
typename TParser>
86 const std::string& outputName)
91 Setup({ }, { outputName });
94 template<
typename TParser>
96 const std::string& inputName,
97 const std::string& outputName)
102 Setup({ { inputName, inputTensorShape } }, { outputName });
105 template<
typename TParser>
108 const std::string& inputName,
109 const std::string& outputName)
116 Setup({ { inputName, inputTensorShape } }, { outputName });
119 template<
typename TParser>
121 const std::vector<std::string>& requestedOutputs)
123 std::string errorMessage;
131 throw armnn::Exception(fmt::format(
"LoadNetwork failed with error: '{0}' {1}",
137 template<
typename TParser>
140 std::string errorMessage;
148 throw armnn::Exception(fmt::format(
"LoadNetwork failed with error: '{0}' {1}",
154 template<
typename TParser>
156 const std::map<std::string,armnn::TensorShape>& inputShapes,
157 const std::vector<std::string>& requestedOutputs)
165 template<
typename TParser>
166 template <std::
size_t NumOutputDimensions>
168 const std::vector<float>& expectedOutputData)
173 template<
typename TParser>
174 template <std::
size_t NumOutputDimensions>
176 const std::map<std::string, std::vector<uint8_t>>&
179 RunTest<NumOutputDimensions, uint8_t>(inputData, expectedOutputData);
182 template<
typename TParser>
183 template <std::
size_t NumOutputDimensions,
typename T>
185 const std::map<std::string, std::vector<T>>& expectedOutputData)
189 for (
auto&& it : inputData)
192 inputTensors.push_back({ bindingInfo.first,
armnn::ConstTensor(bindingInfo.second, it.second.data()) });
196 std::map<std::string, boost::multi_array<T, NumOutputDimensions>> outputStorage;
198 for (
auto&& it : expectedOutputData)
201 outputStorage.emplace(it.first, MakeTensor<T, NumOutputDimensions>(bindingInfo.second));
202 outputTensors.push_back(
203 { bindingInfo.first,
armnn::Tensor(bindingInfo.second, outputStorage.at(it.first).data()) });
209 for (
auto&& it : expectedOutputData)
212 if (bindingInfo.second.GetNumElements() != it.second.size())
214 throw armnn::Exception(fmt::format(
"Output tensor {0} is expected to have {1} elements. " 215 "{2} elements supplied. {3}",
217 bindingInfo.second.GetNumElements(),
226 if (bindingInfo.second.GetShape().GetNumDimensions() == NumOutputDimensions &&
235 std::stringstream message;
236 message <<
"Output tensor " << it.first <<
" is expected to have " 237 << bindingInfo.second.GetShape() <<
"shape. " 246 throw armnn::Exception(fmt::format(
"Output tensor {0} is expected to have {1} dimensions. " 247 "{2} dimensions supplied. {3}",
249 bindingInfo.second.GetShape().GetNumDimensions(),
255 auto outputExpected = MakeTensor<T, NumOutputDimensions>(bindingInfo.second, it.second);
256 if (std::is_same<T, uint8_t>::value)
258 BOOST_TEST(
CompareTensors(outputExpected, outputStorage[it.first],
true));
262 BOOST_TEST(
CompareTensors(outputExpected, outputStorage[it.first]));
CPU Execution: Reference C++ kernels.
boost::test_tools::predicate_result CompareTensors(const boost::multi_array< T, n > &a, const boost::multi_array< T, n > &b, bool compareBoolean=false, bool isDynamic=false)
armnn::TensorShape m_SingleOutputShape
This will store the output shape so it don't need to be passed to the single-input-single-output over...
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
void RunComparisonTest(const std::map< std::string, std::vector< float >> &inputData, const std::map< std::string, std::vector< uint8_t >> &expectedOutputData)
Executes the network with the given input tensor and checks the result against the given output tenso...
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Copyright (c) 2021 ARM Limited and Contributors.
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
std::unique_ptr< TParser, void(*)(TParser *parser)> m_Parser
armnn::IOptimizedNetworkPtr SetupOptimizedNetwork(const std::map< std::string, armnn::TensorShape > &inputShapes, const std::vector< std::string > &requestedOutputs)
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
std::string m_SingleInputName
If the single-input-single-output overload of Setup() is called, these will store the input and outpu...
void RunTest(const std::vector< float > &inputData, const std::vector< float > &expectedOutputData)
Executes the network with the given input tensor and checks the result against the given output tenso...
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
std::string m_SingleOutputName
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
armnn::NetworkId m_NetworkIdentifier
armnn::IRuntimePtr m_Runtime
std::pair< armnn::LayerBindingId, armnn::TensorInfo > BindingPointInfo
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)
Parses and loads the network defined by the m_Prototext string.
Base class for all ArmNN exceptions so that users can filter to just those.
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr