Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
Sadik Armagan | a9c2ce1 | 2020-07-14 10:02:22 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 5 | |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 6 | #pragma once |
| 7 | |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 8 | #include "CsvReader.hpp" |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 9 | #include <armnn/IRuntime.hpp> |
| 10 | #include <armnn/Types.hpp> |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 11 | |
James Ward | 6d9f5c5 | 2020-09-28 11:56:35 +0100 | [diff] [blame] | 12 | #include <mapbox/variant.hpp> |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 13 | |
| 14 | #include <iostream> |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 15 | |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 16 | |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 17 | std::vector<unsigned int> ParseArray(std::istream& stream); |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 18 | |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 19 | /// Splits a given string at every accurance of delimiter into a vector of string |
| 20 | std::vector<std::string> ParseStringList(const std::string& inputString, const char* delimiter); |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 21 | |
James Ward | 6d9f5c5 | 2020-09-28 11:56:35 +0100 | [diff] [blame] | 22 | struct TensorPrinter |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 23 | { |
Georgios Pinitas | 50311ba | 2020-02-18 13:25:23 +0000 | [diff] [blame] | 24 | TensorPrinter(const std::string& binding, |
| 25 | const armnn::TensorInfo& info, |
| 26 | const std::string& outputTensorFile, |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 27 | bool dequantizeOutput); |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 28 | |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 29 | void operator()(const std::vector<float>& values); |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 30 | |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 31 | void operator()(const std::vector<uint8_t>& values); |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 32 | |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 33 | void operator()(const std::vector<int>& values); |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 34 | |
| 35 | private: |
| 36 | template<typename Container, typename Delegate> |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 37 | void ForEachValue(const Container& c, Delegate delegate); |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 38 | |
Sadik Armagan | 7708628 | 2019-09-02 11:46:28 +0100 | [diff] [blame] | 39 | template<typename T> |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 40 | void WriteToFile(const std::vector<T>& values); |
Sadik Armagan | 7708628 | 2019-09-02 11:46:28 +0100 | [diff] [blame] | 41 | |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 42 | std::string m_OutputBinding; |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 43 | float m_Scale; |
| 44 | int m_Offset; |
Sadik Armagan | 7708628 | 2019-09-02 11:46:28 +0100 | [diff] [blame] | 45 | std::string m_OutputTensorFile; |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 46 | bool m_DequantizeOutput; |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
James Ward | 6d9f5c5 | 2020-09-28 11:56:35 +0100 | [diff] [blame] | 49 | using TContainer = mapbox::util::variant<std::vector<float>, std::vector<int>, std::vector<unsigned char>>; |
Aron Virginas-Tar | c82c873 | 2019-10-24 17:07:43 +0100 | [diff] [blame] | 50 | using QuantizationParams = std::pair<float, int32_t>; |
| 51 | |
| 52 | void PopulateTensorWithData(TContainer& tensorData, |
| 53 | unsigned int numElements, |
| 54 | const std::string& dataTypeStr, |
| 55 | const armnn::Optional<QuantizationParams>& qParams, |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 56 | const armnn::Optional<std::string>& dataFile); |
Aron Virginas-Tar | c82c873 | 2019-10-24 17:07:43 +0100 | [diff] [blame] | 57 | |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 58 | /** |
| 59 | * Verifies if the given string is a valid path. Reports invalid paths to std::err. |
| 60 | * @param file string - A string containing the path to check |
| 61 | * @param expectFile bool - If true, checks for a regular file. |
| 62 | * @return bool - True if given string is a valid path., false otherwise. |
| 63 | * */ |
| 64 | bool ValidatePath(const std::string& file, const bool expectFile); |
Aron Virginas-Tar | c82c873 | 2019-10-24 17:07:43 +0100 | [diff] [blame] | 65 | |
Jan Eilers | 4527490 | 2020-10-15 18:34:43 +0100 | [diff] [blame] | 66 | /** |
| 67 | * Verifies if a given vector of strings are valid paths. Reports invalid paths to std::err. |
| 68 | * @param fileVec vector of string - A vector of string containing the paths to check |
| 69 | * @param expectFile bool - If true, checks for a regular file. |
| 70 | * @return bool - True if all given strings are valid paths., false otherwise. |
| 71 | * */ |
| 72 | bool ValidatePaths(const std::vector<std::string>& fileVec, const bool expectFile); |