ArmNN
 20.02
ClassifierTestCase< TTestCaseDatabase, TModel > Class Template Reference

#include <InferenceTest.hpp>

Inheritance diagram for ClassifierTestCase< TTestCaseDatabase, TModel >:
InferenceModelTestCase< TModel > IInferenceTestCase

Public Member Functions

 ClassifierTestCase (int &numInferencesRef, int &numCorrectInferencesRef, const std::vector< unsigned int > &validationPredictions, std::vector< unsigned int > *validationPredictionsOut, TModel &model, unsigned int testCaseId, unsigned int label, std::vector< typename TModel::DataType > modelInput)
 
virtual TestCaseResult ProcessResult (const InferenceTestOptions &params) override
 
- Public Member Functions inherited from InferenceModelTestCase< TModel >
 InferenceModelTestCase (TModel &model, unsigned int testCaseId, const std::vector< TContainer > &inputs, const std::vector< unsigned int > &outputSizes)
 
virtual void Run () override
 
- Public Member Functions inherited from IInferenceTestCase
virtual ~IInferenceTestCase ()
 

Additional Inherited Members

- Public Types inherited from InferenceModelTestCase< TModel >
using TContainer = boost::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char > >
 
- Protected Member Functions inherited from InferenceModelTestCase< TModel >
unsigned int GetTestCaseId () const
 
const std::vector< TContainer > & GetOutputs () const
 

Detailed Description

template<typename TTestCaseDatabase, typename TModel>
class armnn::test::ClassifierTestCase< TTestCaseDatabase, TModel >

Definition at line 149 of file InferenceTest.hpp.

Constructor & Destructor Documentation

◆ ClassifierTestCase()

ClassifierTestCase ( int &  numInferencesRef,
int &  numCorrectInferencesRef,
const std::vector< unsigned int > &  validationPredictions,
std::vector< unsigned int > *  validationPredictionsOut,
TModel &  model,
unsigned int  testCaseId,
unsigned int  label,
std::vector< typename TModel::DataType >  modelInput 
)

Definition at line 33 of file InferenceTest.inl.

References armnn::Dequantize, and armnn::IgnoreUnused().

43  model, testCaseId, std::vector<TContainer>{ modelInput }, { model.GetOutputSize() })
44  , m_Label(label)
45  , m_QuantizationParams(model.GetQuantizationParams())
46  , m_NumInferencesRef(numInferencesRef)
47  , m_NumCorrectInferencesRef(numCorrectInferencesRef)
48  , m_ValidationPredictions(validationPredictions)
49  , m_ValidationPredictionsOut(validationPredictionsOut)
50 {
51 }

Member Function Documentation

◆ ProcessResult()

TestCaseResult ProcessResult ( const InferenceTestOptions params)
overridevirtual

Implements IInferenceTestCase.

Definition at line 116 of file InferenceTest.inl.

References ARMNN_LOG, armnn::error, armnn::test::Failed, InferenceModelTestCase< TModel >::GetOutputs(), InferenceModelTestCase< TModel >::GetTestCaseId(), armnn::info, InferenceTestOptions::m_IterationCount, armnn::numeric_cast(), and armnn::test::Ok.

117 {
118  auto& output = this->GetOutputs()[0];
119  const auto testCaseId = this->GetTestCaseId();
120 
121  ClassifierResultProcessor resultProcessor(m_QuantizationParams.first, m_QuantizationParams.second);
122  boost::apply_visitor(resultProcessor, output);
123 
124  ARMNN_LOG(info) << "= Prediction values for test #" << testCaseId;
125  auto it = resultProcessor.GetResultMap().rbegin();
126  for (int i=0; i<5 && it != resultProcessor.GetResultMap().rend(); ++i)
127  {
128  ARMNN_LOG(info) << "Top(" << (i+1) << ") prediction is " << it->second <<
129  " with value: " << (it->first);
130  ++it;
131  }
132 
133  unsigned int prediction = 0;
134  boost::apply_visitor([&](auto&& value)
135  {
136  prediction = boost::numeric_cast<unsigned int>(
137  std::distance(value.begin(), std::max_element(value.begin(), value.end())));
138  },
139  output);
140 
141  // If we're just running the defaultTestCaseIds, each one must be classified correctly.
142  if (params.m_IterationCount == 0 && prediction != m_Label)
143  {
144  ARMNN_LOG(error) << "Prediction for test case " << testCaseId << " (" << prediction << ")" <<
145  " is incorrect (should be " << m_Label << ")";
146  return TestCaseResult::Failed;
147  }
148 
149  // If a validation file was provided as input, it checks that the prediction matches.
150  if (!m_ValidationPredictions.empty() && prediction != m_ValidationPredictions[testCaseId])
151  {
152  ARMNN_LOG(error) << "Prediction for test case " << testCaseId << " (" << prediction << ")" <<
153  " doesn't match the prediction in the validation file (" << m_ValidationPredictions[testCaseId] << ")";
154  return TestCaseResult::Failed;
155  }
156 
157  // If a validation file was requested as output, it stores the predictions.
158  if (m_ValidationPredictionsOut)
159  {
160  m_ValidationPredictionsOut->push_back(prediction);
161  }
162 
163  // Updates accuracy stats.
164  m_NumInferencesRef++;
165  if (prediction == m_Label)
166  {
167  m_NumCorrectInferencesRef++;
168  }
169 
170  return TestCaseResult::Ok;
171 }
const std::vector< TContainer > & GetOutputs() const
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
The test completed without any errors.

The documentation for this class was generated from the following files: