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);
38 template<
typename Container,
typename Delegate>
39 void ForEachValue(
const Container& c, Delegate delegate);
42 void WriteToFile(
const std::vector<T>& values);
44 std::string m_OutputBinding;
47 std::string m_OutputTensorFile;
48 bool m_DequantizeOutput;
51 using TContainer = mapbox::util::variant<std::vector<float>, std::vector<int>, std::vector<unsigned char>>;
55 unsigned int numElements,
56 const std::string& dataTypeStr,
66 bool ValidatePath(
const std::string& file,
const bool expectFile);
74 bool ValidatePaths(
const std::vector<std::string>& fileVec,
const bool expectFile);
76 template<
typename T,
typename TParseElementFunc>
77 std::vector<T>
ParseArrayImpl(std::istream& stream, TParseElementFunc parseElementFunc,
const char* chars =
"\t ,:")
79 std::vector<T> result;
82 while (std::getline(stream, line))
85 for (
const std::string& token : tokens)
91 result.push_back(parseElementFunc(token));
93 catch (
const std::exception&)
95 ARMNN_LOG(error) <<
"'" << token <<
"' is not a valid number. It has been ignored.";
104 template <
typename T,
typename TParseElementFunc>
106 unsigned int numElements,
108 TParseElementFunc parseFunction)
110 const bool readFromFile = dataFile.
has_value() && !dataFile.
value().empty();
112 std::ifstream inputTensorFile;
115 inputTensorFile = std::ifstream(dataFile.
value());
118 tensorData = readFromFile ?
119 ParseArrayImpl<T>(inputTensorFile, parseFunction) :
120 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)
mapbox::util::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char > > TContainer
#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)
std::pair< float, int32_t > QuantizationParams
void PopulateTensorWithDataGeneric(std::vector< T > &tensorData, unsigned int numElements, const armnn::Optional< std::string > &dataFile, TParseElementFunc parseFunction)