13 #include <mapbox/variant.hpp> 19 std::vector<unsigned int>
ParseArray(std::istream& stream);
22 std::vector<std::string>
ParseStringList(
const std::string& inputString,
const char* delimiter);
28 const std::string& outputTensorFile,
29 bool dequantizeOutput);
31 void operator()(
const std::vector<float>& values);
33 void operator()(
const std::vector<uint8_t>& values);
35 void operator()(
const std::vector<int>& values);
37 void operator()(
const std::vector<int8_t>& values);
40 template<
typename Container,
typename Delegate>
41 void ForEachValue(
const Container& c, Delegate delegate);
44 void WriteToFile(
const std::vector<T>& values);
46 std::string m_OutputBinding;
49 std::string m_OutputTensorFile;
50 bool m_DequantizeOutput;
54 mapbox::util::variant<std::vector<float>, std::vector<int>, std::vector<unsigned char>, std::vector<int8_t>>;
58 unsigned int numElements,
59 const std::string& dataTypeStr,
69 bool ValidatePath(
const std::string& file,
const bool expectFile);
77 bool ValidatePaths(
const std::vector<std::string>& fileVec,
const bool expectFile);
79 template<
typename T,
typename TParseElementFunc>
80 std::vector<T>
ParseArrayImpl(std::istream& stream, TParseElementFunc parseElementFunc,
const char* chars =
"\t ,:")
82 std::vector<T> result;
85 while (std::getline(stream, line))
88 for (
const std::string& token : tokens)
94 result.push_back(parseElementFunc(token));
96 catch (
const std::exception&)
98 ARMNN_LOG(error) <<
"'" << token <<
"' is not a valid number. It has been ignored.";
107 template <
typename T,
typename TParseElementFunc>
109 unsigned int numElements,
111 TParseElementFunc parseFunction)
113 const bool readFromFile = dataFile.
has_value() && !dataFile.
value().empty();
115 std::ifstream inputTensorFile;
118 inputTensorFile = std::ifstream(dataFile.
value());
121 tensorData = readFromFile ?
122 ParseArrayImpl<T>(inputTensorFile, parseFunction) :
123 std::vector<T>(numElements, static_cast<T>(0));
std::vector< std::string > StringTokenizer(const std::string &str, const char *delimiters, bool tokenCompression=true)
Function to take a string and a list of delimiters and split the string into tokens based on those de...
bool ValidatePath(const std::string &file, const bool expectFile)
Verifies if the given string is a valid path.
void operator()(const std::vector< float > &values)
#define ARMNN_LOG(severity)
std::vector< unsigned int > ParseArray(std::istream &stream)
std::vector< std::string > ParseStringList(const std::string &inputString, const char *delimiter)
Splits a given string at every accurance of delimiter into a vector of string.
bool has_value() const noexcept
std::vector< T > ParseArrayImpl(std::istream &stream, TParseElementFunc parseElementFunc, const char *chars="\,:")
bool ValidatePaths(const std::vector< std::string > &fileVec, const bool expectFile)
Verifies if a given vector of strings are valid paths.
TensorPrinter(const std::string &binding, const armnn::TensorInfo &info, const std::string &outputTensorFile, bool dequantizeOutput)
void PopulateTensorWithData(TContainer &tensorData, unsigned int numElements, const std::string &dataTypeStr, const armnn::Optional< QuantizationParams > &qParams, const armnn::Optional< std::string > &dataFile)
mapbox::util::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char >, std::vector< int8_t > > TContainer
std::pair< float, int32_t > QuantizationParams
void PopulateTensorWithDataGeneric(std::vector< T > &tensorData, unsigned int numElements, const armnn::Optional< std::string > &dataFile, TParseElementFunc parseFunction)