ArmNN
 20.05
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
 QuantizationDataSet is a structure which is created after parsing a quantization CSV file. More...
 
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 30 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

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

◆ GetBindingIdFromCsvRow()

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

Definition at line 89 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

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

◆ GetFileNameFromCsvRow()

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

Definition at line 104 of file QuantizationDataSet.cpp.

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

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

◆ GetPassIdFromCsvRow()

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

Definition at line 74 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

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

◆ 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  {
72  "QAsymmS8",
73  "QAsymmU8",
74  "QSymm16"
75  };
76 
77  auto iterator = std::find(supportedSchemes.begin(), supportedSchemes.end(), scheme);
78  if (iterator == supportedSchemes.end())
79  {
80  std::cerr << "Quantization Scheme [" << scheme << "] is not supported" << std::endl;
81  return false;
82  }
83 
84  return true;
85 }