From 6940dd720ebb6b3d1df8ca203ab696daefe58189 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Fri, 20 Mar 2020 12:25:56 +0000 Subject: renamed Documentation folder 20.02 and added .nojekyll file Signed-off-by: Jim Flynn --- ...assarmnn_utils_1_1_model_accuracy_checker.xhtml | 264 +++++++++++++++++++++ 1 file changed, 264 insertions(+) create mode 100644 20.02/classarmnn_utils_1_1_model_accuracy_checker.xhtml (limited to '20.02/classarmnn_utils_1_1_model_accuracy_checker.xhtml') diff --git a/20.02/classarmnn_utils_1_1_model_accuracy_checker.xhtml b/20.02/classarmnn_utils_1_1_model_accuracy_checker.xhtml new file mode 100644 index 0000000000..8cebf6339a --- /dev/null +++ b/20.02/classarmnn_utils_1_1_model_accuracy_checker.xhtml @@ -0,0 +1,264 @@ + + + + + + + + + + + + + +ArmNN: ModelAccuracyChecker Class Reference + + + + + + + + + + + + + + + + +
+
+ + + + ArmNN + + + +
+
+  20.02 +
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+ +
+
ModelAccuracyChecker Class Reference
+
+
+ +

#include <ModelAccuracyChecker.hpp>

+ + + + + + + + + + + + +

+Public Member Functions

 ModelAccuracyChecker (const std::map< std::string, std::string > &validationLabelSet, const std::vector< LabelCategoryNames > &modelOutputLabels)
 Constructor for a model top k accuracy checker. More...
 
float GetAccuracy (unsigned int k)
 Get Top K accuracy. More...
 
template<typename TContainer >
void AddImageResult (const std::string &imageName, std::vector< TContainer > outputTensor)
 Record the prediction result of an image. More...
 
+

Detailed Description

+
+

Definition at line 45 of file ModelAccuracyChecker.hpp.

+

Constructor & Destructor Documentation

+ +

◆ ModelAccuracyChecker()

+ +
+
+ + + + + + + + + + + + + + + + + + +
ModelAccuracyChecker (const std::map< std::string, std::string > & validationLabelSet,
const std::vector< LabelCategoryNames > & modelOutputLabels 
)
+
+ +

Constructor for a model top k accuracy checker.

+
Parameters
+ + + +
[in]validationLabelSetMapping from names of images to be validated, to category names of their corresponding ground-truth labels.
[in]modelOutputLabelsMapping from output nodes to the category names of their corresponding labels Note that an output node can have multiple category names.
+
+
+ +

Definition at line 17 of file ModelAccuracyChecker.cpp.

+
19  : m_GroundTruthLabelSet(validationLabels)
20  , m_ModelOutputLabels(modelOutputLabels)
21 {}
+
+
+

Member Function Documentation

+ +

◆ AddImageResult()

+ +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + +
void AddImageResult (const std::string & imageName,
std::vector< TContaineroutputTensor 
)
+
+inline
+
+ +

Record the prediction result of an image.

+
Parameters
+ + + +
[in]imageNameName of the image.
[in]outputTensorOutput tensor of the network running imageName.
+
+
+ +

Definition at line 73 of file ModelAccuracyChecker.hpp.

+ +

Referenced by BOOST_FIXTURE_TEST_CASE().

+
74  {
75  // Increment the total number of images processed
76  ++m_ImagesProcessed;
77 
78  std::map<int, float> confidenceMap;
79  auto& output = outputTensor[0];
80 
81  // Create a map of all predictions
82  boost::apply_visitor([&confidenceMap](auto && value)
83  {
84  int index = 0;
85  for (const auto & o : value)
86  {
87  if (o > 0)
88  {
89  confidenceMap.insert(std::pair<int, float>(index, static_cast<float>(o)));
90  }
91  ++index;
92  }
93  },
94  output);
95 
96  // Create a comparator for sorting the map in order of highest probability
97  typedef std::function<bool(std::pair<int, float>, std::pair<int, float>)> Comparator;
98 
99  Comparator compFunctor =
100  [](std::pair<int, float> element1, std::pair<int, float> element2)
101  {
102  return element1.second > element2.second;
103  };
104 
105  // Do the sorting and store in an ordered set
106  std::set<std::pair<int, float>, Comparator> setOfPredictions(
107  confidenceMap.begin(), confidenceMap.end(), compFunctor);
108 
109  const std::string correctLabel = m_GroundTruthLabelSet.at(imageName);
110 
111  unsigned int index = 1;
112  for (std::pair<int, float> element : setOfPredictions)
113  {
114  if (index >= m_TopK.size())
115  {
116  break;
117  }
118  // Check if the ground truth label value is included in the topi prediction.
119  // Note that a prediction can have multiple prediction labels.
120  const LabelCategoryNames predictionLabels = m_ModelOutputLabels[static_cast<size_t>(element.first)];
121  if (std::find(predictionLabels.begin(), predictionLabels.end(), correctLabel) != predictionLabels.end())
122  {
123  ++m_TopK[index];
124  break;
125  }
126  ++index;
127  }
128  }
std::vector< std::string > LabelCategoryNames
+
+
+
+ +

◆ GetAccuracy()

+ +
+
+ + + + + + + + +
float GetAccuracy (unsigned int k)
+
+ +

Get Top K accuracy.

+
Parameters
+ + +
[in]kThe number of top predictions to use for validating the ground-truth label. For example, if k is 3, then a prediction is considered correct as long as the ground-truth appears in the top 3 predictions.
+
+
+
Returns
The accuracy, according to the top k th predictions.
+ +

Definition at line 23 of file ModelAccuracyChecker.cpp.

+ +

References ARMNN_LOG, and armnn::warning.

+ +

Referenced by BOOST_FIXTURE_TEST_CASE().

+
24 {
25  if (k > 10)
26  {
27  ARMNN_LOG(warning) << "Accuracy Tool only supports a maximum of Top 10 Accuracy. "
28  "Printing Top 10 Accuracy result!";
29  k = 10;
30  }
31  unsigned int total = 0;
32  for (unsigned int i = k; i > 0; --i)
33  {
34  total += m_TopK[i];
35  }
36  return static_cast<float>(total * 100) / static_cast<float>(m_ImagesProcessed);
37 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:163
+
+
+
+
The documentation for this class was generated from the following files: +
+
+ + + + -- cgit v1.2.1