Compute Library
 21.08
TopNPredictionsAccessor Class Referencefinal

Result accessor class. More...

#include <GraphUtils.h>

Collaboration diagram for TopNPredictionsAccessor:
[legend]

Public Member Functions

 TopNPredictionsAccessor (const std::string &labels_path, size_t top_n=5, std::ostream &output_stream=std::cout)
 Constructor. More...
 
 TopNPredictionsAccessor (TopNPredictionsAccessor &&)=default
 Allow instances of this class to be move constructed. More...
 
 TopNPredictionsAccessor (const TopNPredictionsAccessor &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
TopNPredictionsAccessoroperator= (const TopNPredictionsAccessor &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) 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

Result accessor class.

Definition at line 376 of file GraphUtils.h.

Constructor & Destructor Documentation

◆ TopNPredictionsAccessor() [1/3]

TopNPredictionsAccessor ( const std::string &  labels_path,
size_t  top_n = 5,
std::ostream &  output_stream = std::cout 
)

Constructor.

Parameters
[in]labels_pathPath to labels text file.
[in]top_n(Optional) Number of output classes to print
[out]output_stream(Optional) Output stream

Definition at line 584 of file GraphUtils.cpp.

References ARM_COMPUTE_ERROR_VAR, arm_compute::test::validation::b, ITensor::buffer(), arm_compute::test::validation::reference::copy(), ITensorInfo::dimension(), arm_compute::mlgo::parser::end(), ITensor::info(), and ITensorInfo::offset_first_element_in_bytes().

585  : _labels(), _output_stream(output_stream), _top_n(top_n)
586 {
587  _labels.clear();
588 
589  std::ifstream ifs;
590 
591  try
592  {
593  ifs.exceptions(std::ifstream::badbit);
594  ifs.open(labels_path, std::ios::in | std::ios::binary);
595 
596  for(std::string line; !std::getline(ifs, line).fail();)
597  {
598  _labels.emplace_back(line);
599  }
600  }
601  catch(const std::ifstream::failure &e)
602  {
603  ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", labels_path.c_str(), e.what());
604  }
605 }
#define ARM_COMPUTE_ERROR_VAR(msg,...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:346

◆ TopNPredictionsAccessor() [2/3]

Allow instances of this class to be move constructed.

◆ TopNPredictionsAccessor() [3/3]

Prevent instances of this class from being copied (As this class contains pointers)

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 641 of file GraphUtils.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::F32, ITensor::info(), and arm_compute::QASYMM8.

642 {
644  ARM_COMPUTE_ERROR_ON(_labels.size() != tensor.info()->dimension(0));
645 
646  switch(tensor.info()->data_type())
647  {
648  case DataType::QASYMM8:
649  access_predictions_tensor<uint8_t>(tensor);
650  break;
651  case DataType::F32:
652  access_predictions_tensor<float>(tensor);
653  break;
654  default:
655  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
656  }
657 
658  return false;
659 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
quantized, asymmetric fixed-point 8-bit number unsigned
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:786

◆ operator=()

TopNPredictionsAccessor& operator= ( const TopNPredictionsAccessor )
delete

Prevent instances of this class from being copied (As this class contains pointers)


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