ArmNN
 20.11
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< 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 87 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

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

◆ GetFileNameFromCsvRow()

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

Definition at line 102 of file QuantizationDataSet.cpp.

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

103 {
104  std::string fileName = armnn::stringUtils::StringTrim(tokens[2]);
105 
106  if (!fs::exists(fileName))
107  {
108  throw armnn::ParseException(fmt::format("File [{}] provided on CSV row {} does not exist.",
109  fileName, lineIndex));
110  }
111 
112  if (fileName.empty())
113  {
114  throw armnn::ParseException(fmt::format("Filename cannot be empty on CSV row {} ", lineIndex));
115  }
116  return fileName;
117 }
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 72 of file QuantizationDataSet.cpp.

Referenced by GetFileNameFromCsvRow().

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

◆ 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 }