ArmNN
 21.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 = mapbox::util::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 150 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 32 of file InferenceTest.inl.

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

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

Member Function Documentation

◆ ProcessResult()

TestCaseResult ProcessResult ( const InferenceTestOptions params)
overridevirtual

Implements IInferenceTestCase.

Definition at line 115 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.

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

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