ArmNN
 21.02
armnnQuantizer Namespace Reference

Classes

class  CommandLineProcessor
 
class  InputLayerStrategy
 Visitor class implementation to gather the TensorInfo for LayerBindingID for creation of ConstTensor for Refine. More...
 
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< std::string > tokens, unsigned int lineIndex)
 
armnn::LayerBindingId GetBindingIdFromCsvRow (std::vector< std::string > tokens, unsigned int lineIndex)
 
std::string GetFileNameFromCsvRow (std::vector< std::string > tokens, unsigned int lineIndex)
 

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 28 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

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

◆ GetBindingIdFromCsvRow()

armnn::LayerBindingId armnnQuantizer::GetBindingIdFromCsvRow ( std::vector< std::string >  tokens,
unsigned int  lineIndex 
)

Definition at line 117 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

118 {
119  armnn::LayerBindingId bindingId;
120  try
121  {
122  bindingId = std::stoi(tokens[1]);
123  }
124  catch (const std::invalid_argument&)
125  {
126  throw armnn::ParseException(fmt::format("Binding ID [{}] is not correct format on CSV row {}",
127  tokens[1], lineIndex));
128  }
129  return bindingId;
130 }
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:210

◆ GetFileNameFromCsvRow()

std::string armnnQuantizer::GetFileNameFromCsvRow ( std::vector< std::string >  tokens,
unsigned int  lineIndex 
)

Definition at line 132 of file QuantizationDataSet.cpp.

References AddInputData(), GetBindingIdFromCsvRow(), GetPassIdFromCsvRow(), armnn::stringUtils::StringTokenizer(), and armnn::stringUtils::StringTrim().

133 {
134  std::string fileName = armnn::stringUtils::StringTrim(tokens[2]);
135 
136  if (!fs::exists(fileName))
137  {
138  throw armnn::ParseException(fmt::format("File [{}] provided on CSV row {} does not exist.",
139  fileName, lineIndex));
140  }
141 
142  if (fileName.empty())
143  {
144  throw armnn::ParseException(fmt::format("Filename cannot be empty on CSV row {} ", lineIndex));
145  }
146  return fileName;
147 }
std::string & StringTrim(std::string &str, const std::string &chars="\\\")
Trim from both the start and the end of a string.
Definition: StringUtils.hpp:77

◆ GetPassIdFromCsvRow()

unsigned int armnnQuantizer::GetPassIdFromCsvRow ( std::vector< std::string >  tokens,
unsigned int  lineIndex 
)

Definition at line 102 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

103 {
104  unsigned int passId;
105  try
106  {
107  passId = static_cast<unsigned int>(std::stoi(tokens[0]));
108  }
109  catch (const std::invalid_argument&)
110  {
111  throw armnn::ParseException(fmt::format("Pass ID [{}] is not correct format on CSV row {}",
112  tokens[0], lineIndex));
113  }
114  return passId;
115 }

◆ ValidateOutputDirectory()

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

Definition at line 14 of file CommandLineProcessor.cpp.

Referenced by CommandLineProcessor::ProcessCommandLine().

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

◆ ValidateProvidedFile()

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

Definition at line 42 of file CommandLineProcessor.cpp.

Referenced by CommandLineProcessor::ProcessCommandLine().

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

◆ ValidateQuantizationScheme()

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

Definition at line 59 of file CommandLineProcessor.cpp.

Referenced by CommandLineProcessor::ProcessCommandLine().

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