Compute Library
 21.08
ValidationOutputAccessor Class Referencefinal

Output Accessor used for network validation. More...

#include <GraphUtils.h>

Collaboration diagram for ValidationOutputAccessor:
[legend]

Public Member Functions

 ValidationOutputAccessor (const std::string &image_list, std::ostream &output_stream=std::cout, unsigned int start=0, unsigned int end=0)
 Default Constructor. More...
 
void reset ()
 Reset accessor state. More...
 
bool access_tensor (ITensor &tensor) override
 Interface to be implemented to access a given tensor. More...
 
- Public Member Functions inherited from ITensorAccessor
virtual ~ITensorAccessor ()=default
 Default virtual destructor. More...
 

Detailed Description

Output Accessor used for network validation.

Definition at line 290 of file GraphUtils.h.

Constructor & Destructor Documentation

◆ ValidationOutputAccessor()

ValidationOutputAccessor ( const std::string &  image_list,
std::ostream &  output_stream = std::cout,
unsigned int  start = 0,
unsigned int  end = 0 
)

Default Constructor.

Parameters
[in]image_listFile containing all the images and labels results
[out]output_stream(Optional) Output stream (Defaults to the standard output stream)
[in]start(Optional) Start range
[in]end(Optional) End range
Note
Range is defined as [start, end]

Definition at line 384 of file GraphUtils.cpp.

References ARM_COMPUTE_ERROR_VAR, ARM_COMPUTE_EXIT_ON_MSG, and arm_compute::mlgo::parser::end().

388  : _results(), _output_stream(output_stream), _offset(0), _positive_samples_top1(0), _positive_samples_top5(0)
389 {
390  ARM_COMPUTE_EXIT_ON_MSG(start > end, "Invalid validation range!");
391 
392  std::ifstream ifs;
393  try
394  {
395  ifs.exceptions(std::ifstream::badbit);
396  ifs.open(image_list, std::ios::in | std::ios::binary);
397 
398  // Parse image correctly classified labels
399  unsigned int counter = 0;
400  for(std::string line; !std::getline(ifs, line).fail() && counter <= end; ++counter)
401  {
402  // Add label if within range
403  if(counter >= start)
404  {
405  std::stringstream linestream(line);
406  std::string image_name;
407  int result;
408 
409  linestream >> image_name >> result;
410  _results.emplace_back(result);
411  }
412  }
413  }
414  catch(const std::ifstream::failure &e)
415  {
416  ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", image_list.c_str(), e.what());
417  }
418 }
#define ARM_COMPUTE_ERROR_VAR(msg,...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:346
#define ARM_COMPUTE_EXIT_ON_MSG(cond, msg)
If the condition is true, the given message is printed and program exits.
Definition: Error.h:379
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290

Member Function Documentation

◆ access_tensor()

bool access_tensor ( ITensor tensor)
overridevirtual

Interface to be implemented to access a given tensor.

Parameters
[in]tensorTensor to be accessed
Returns
True if access is successful else false

Implements ITensorAccessor.

Definition at line 427 of file GraphUtils.cpp.

References ARM_COMPUTE_ERROR, arm_compute::test::validation::b, ITensor::buffer(), ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::mlgo::parser::end(), arm_compute::F16, arm_compute::F32, ITensor::info(), ITensorInfo::offset_first_element_in_bytes(), and arm_compute::QASYMM8.

428 {
429  bool ret = _offset < _results.size();
430  if(ret)
431  {
432  // Get results
433  std::vector<size_t> tensor_results;
434  switch(tensor.info()->data_type())
435  {
436  case DataType::QASYMM8:
437  tensor_results = access_predictions_tensor<uint8_t>(tensor);
438  break;
439  case DataType::F16:
440  tensor_results = access_predictions_tensor<half>(tensor);
441  break;
442  case DataType::F32:
443  tensor_results = access_predictions_tensor<float>(tensor);
444  break;
445  default:
446  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
447  }
448 
449  // Check if tensor results are within top-n accuracy
450  size_t correct_label = _results[_offset++];
451 
452  aggregate_sample(tensor_results, _positive_samples_top1, 1, correct_label);
453  aggregate_sample(tensor_results, _positive_samples_top5, 5, correct_label);
454  }
455 
456  // Report top_n accuracy
457  if(_offset >= _results.size())
458  {
459  report_top_n(1, _results.size(), _positive_samples_top1);
460  report_top_n(5, _results.size(), _positive_samples_top5);
461  }
462 
463  return ret;
464 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
1 channel, 1 F16 per channel
quantized, asymmetric fixed-point 8-bit number unsigned
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.

◆ reset()

void reset ( )

Reset accessor state.

Definition at line 420 of file GraphUtils.cpp.

421 {
422  _offset = 0;
423  _positive_samples_top1 = 0;
424  _positive_samples_top5 = 0;
425 }

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