ArmNN  NotReleased
armnnQuantizer Namespace Reference

Classes

class  CommandLineProcessor
 
class  InputLayerVisitor
 Visitor class implementation to gather the TensorInfo for LayerBindingID for creation of ConstTensor for Refine. More...
 
class  QuantizationDataSet
 
class  QuantizationInput
 QuantizationInput for specific pass ID, can list a corresponding raw data file for each LayerBindingId. More...
 

Functions

bool ValidateOutputDirectory (std::string &dir)
 
bool ValidateProvidedFile (const std::string &inputFileName)
 
bool ValidateQuantizationScheme (const std::string &scheme)
 
void AddInputData (unsigned int passId, armnn::LayerBindingId bindingId, const std::string &inputFilePath, std::map< unsigned int, QuantizationInput > &passIdToQuantizationInput)
 
unsigned int GetPassIdFromCsvRow (std::vector< armnnUtils::CsvRow > csvRows, unsigned int rowIndex)
 
armnn::LayerBindingId GetBindingIdFromCsvRow (std::vector< armnnUtils::CsvRow > csvRows, unsigned int rowIndex)
 
std::string GetFileNameFromCsvRow (std::vector< armnnUtils::CsvRow > csvRows, unsigned int rowIndex)
 

Function Documentation

◆ AddInputData()

void armnnQuantizer::AddInputData ( unsigned int  passId,
armnn::LayerBindingId  bindingId,
const std::string &  inputFilePath,
std::map< unsigned int, QuantizationInput > &  passIdToQuantizationInput 
)

Definition at line 29 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

33 {
34  auto iterator = passIdToQuantizationInput.find(passId);
35  if (iterator == passIdToQuantizationInput.end())
36  {
37  QuantizationInput input(passId, bindingId, inputFilePath);
38  passIdToQuantizationInput.emplace(passId, input);
39  }
40  else
41  {
42  auto existingQuantizationInput = iterator->second;
43  existingQuantizationInput.AddEntry(bindingId, inputFilePath);
44  }
45 }

◆ GetBindingIdFromCsvRow()

armnn::LayerBindingId armnnQuantizer::GetBindingIdFromCsvRow ( std::vector< armnnUtils::CsvRow csvRows,
unsigned int  rowIndex 
)

Definition at line 88 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

89 {
90  armnn::LayerBindingId bindingId;
91  try
92  {
93  bindingId = std::stoi(csvRows[rowIndex].values[1]);
94  }
95  catch (const std::invalid_argument&)
96  {
97  throw armnn::ParseException("Binding ID [" + csvRows[rowIndex].values[0] + "]" +
98  " is not correct format on CSV row " + std::to_string(rowIndex));
99  }
100  return bindingId;
101 }
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:168

◆ GetFileNameFromCsvRow()

std::string armnnQuantizer::GetFileNameFromCsvRow ( std::vector< armnnUtils::CsvRow csvRows,
unsigned int  rowIndex 
)

Definition at line 103 of file QuantizationDataSet.cpp.

References AddInputData(), GetBindingIdFromCsvRow(), GetPassIdFromCsvRow(), and CsvReader::ParseFile().

104 {
105  std::string fileName = csvRows[rowIndex].values[2];
106 
107  if (!boost::filesystem::exists(fileName))
108  {
109  throw armnn::ParseException("File [ " + fileName + "] provided on CSV row " + std::to_string(rowIndex) +
110  " does not exist.");
111  }
112 
113  if (fileName.empty())
114  {
115  throw armnn::ParseException("Filename cannot be empty on CSV row " + std::to_string(rowIndex));
116  }
117  return fileName;
118 }

◆ GetPassIdFromCsvRow()

unsigned int armnnQuantizer::GetPassIdFromCsvRow ( std::vector< armnnUtils::CsvRow csvRows,
unsigned int  rowIndex 
)

Definition at line 73 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

74 {
75  unsigned int passId;
76  try
77  {
78  passId = static_cast<unsigned int>(std::stoi(csvRows[rowIndex].values[0]));
79  }
80  catch (const std::invalid_argument&)
81  {
82  throw armnn::ParseException("Pass ID [" + csvRows[rowIndex].values[0] + "]" +
83  " is not correct format on CSV row " + std::to_string(rowIndex));
84  }
85  return passId;
86 }

◆ ValidateOutputDirectory()

bool armnnQuantizer::ValidateOutputDirectory ( std::string &  dir)

Definition at line 17 of file CommandLineProcessor.cpp.

Referenced by CommandLineProcessor::ProcessCommandLine().

18 {
19  if (dir.empty())
20  {
21  std::cerr << "No output directory specified" << std::endl;
22  return false;
23  }
24 
25  if (dir[dir.length() - 1] != '/')
26  {
27  dir += "/";
28  }
29 
30  if (!boost::filesystem::exists(dir))
31  {
32  std::cerr << "Output directory [" << dir << "] does not exist" << std::endl;
33  return false;
34  }
35 
36  if (!boost::filesystem::is_directory(dir))
37  {
38  std::cerr << "Given output directory [" << dir << "] is not a directory" << std::endl;
39  return false;
40  }
41 
42  return true;
43 }

◆ ValidateProvidedFile()

bool armnnQuantizer::ValidateProvidedFile ( const std::string &  inputFileName)

Definition at line 45 of file CommandLineProcessor.cpp.

Referenced by CommandLineProcessor::ProcessCommandLine().

46 {
47  if (!boost::filesystem::exists(inputFileName))
48  {
49  std::cerr << "Provided file [" << inputFileName << "] does not exist" << std::endl;
50  return false;
51  }
52 
53  if (boost::filesystem::is_directory(inputFileName))
54  {
55  std::cerr << "Given file [" << inputFileName << "] is a directory" << std::endl;
56  return false;
57  }
58 
59  return true;
60 }

◆ ValidateQuantizationScheme()

bool armnnQuantizer::ValidateQuantizationScheme ( const std::string &  scheme)

Definition at line 62 of file CommandLineProcessor.cpp.

Referenced by CommandLineProcessor::ProcessCommandLine().

63 {
64  if (scheme.empty())
65  {
66  std::cerr << "No Quantization Scheme specified" << std::endl;
67  return false;
68  }
69 
70  std::vector<std::string> supportedSchemes = {
71  "QAsymm8",
72  "QSymm16"
73  };
74 
75  auto iterator = std::find(supportedSchemes.begin(), supportedSchemes.end(), scheme);
76  if (iterator == supportedSchemes.end())
77  {
78  std::cerr << "Quantization Scheme [" << scheme << "] is not supported" << std::endl;
79  return false;
80  }
81 
82  return true;
83 }