aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorGiorgio Arena <giorgio.arena@arm.com>2017-12-21 19:50:06 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:43:42 +0000
commita66eaa2a374a50b798159d95431c946fdda22a24 (patch)
tree8d321b8280d9151890d161da3779438c50e05fb1 /utils
parent621965e3e9ef301d2668c60702f5fb79daea8d26 (diff)
downloadComputeLibrary-a66eaa2a374a50b798159d95431c946fdda22a24.tar.gz
COMPMID-752 Creating an example for QASYMM8 MobileNet
Change-Id: Ic76b3b6adaff8c84ba4d2ca5283d9291c69344f0 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/114466 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Pablo Tello <pablo.tello@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/GraphUtils.cpp32
-rw-r--r--utils/GraphUtils.h5
-rw-r--r--utils/Utils.h3
3 files changed, 30 insertions, 10 deletions
diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp
index b9be9d4085..6b3dffc1a4 100644
--- a/utils/GraphUtils.cpp
+++ b/utils/GraphUtils.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -140,16 +140,14 @@ TopNPredictionsAccessor::TopNPredictionsAccessor(const std::string &labels_path,
}
}
-bool TopNPredictionsAccessor::access_tensor(ITensor &tensor)
+template <typename T>
+void TopNPredictionsAccessor::access_predictions_tensor(ITensor &tensor)
{
- ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&tensor, 1, DataType::F32);
- ARM_COMPUTE_ERROR_ON(_labels.size() != tensor.info()->dimension(0));
-
// Get the predicted class
- std::vector<float> classes_prob;
+ std::vector<T> classes_prob;
std::vector<size_t> index;
- const auto output_net = reinterpret_cast<float *>(tensor.buffer() + tensor.info()->offset_first_element_in_bytes());
+ const auto output_net = reinterpret_cast<T *>(tensor.buffer() + tensor.info()->offset_first_element_in_bytes());
const size_t num_classes = tensor.info()->dimension(0);
classes_prob.resize(num_classes);
@@ -170,10 +168,28 @@ bool TopNPredictionsAccessor::access_tensor(ITensor &tensor)
for(size_t i = 0; i < _top_n; ++i)
{
_output_stream << std::fixed << std::setprecision(4)
- << classes_prob[index.at(i)]
+ << +classes_prob[index.at(i)]
<< " - [id = " << index.at(i) << "]"
<< ", " << _labels[index.at(i)] << std::endl;
}
+}
+
+bool TopNPredictionsAccessor::access_tensor(ITensor &tensor)
+{
+ ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&tensor, 1, DataType::F32, DataType::QASYMM8);
+ ARM_COMPUTE_ERROR_ON(_labels.size() != tensor.info()->dimension(0));
+
+ switch(tensor.info()->data_type())
+ {
+ case DataType::QASYMM8:
+ access_predictions_tensor<uint8_t>(tensor);
+ break;
+ case DataType::F32:
+ access_predictions_tensor<float>(tensor);
+ break;
+ default:
+ ARM_COMPUTE_ERROR("NOT SUPPORTED!");
+ }
return false;
}
diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h
index ae6ecad881..e97bbf1c49 100644
--- a/utils/GraphUtils.h
+++ b/utils/GraphUtils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 ARM Limited.
+ * Copyright (c) 2017-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -128,6 +128,9 @@ public:
bool access_tensor(ITensor &tensor) override;
private:
+ template <typename T>
+ void access_predictions_tensor(ITensor &tensor);
+
std::vector<std::string> _labels;
std::ostream &_output_stream;
size_t _top_n;
diff --git a/utils/Utils.h b/utils/Utils.h
index 01e5137669..ff4c4c99fd 100644
--- a/utils/Utils.h
+++ b/utils/Utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016, 2018 ARM Limited.
+ * Copyright (c) 2016-2018 ARM Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -138,6 +138,7 @@ inline std::string get_typestring(DataType data_type)
switch(data_type)
{
case DataType::U8:
+ case DataType::QASYMM8:
return no_endianness + "u" + support::cpp11::to_string(sizeof(uint8_t));
case DataType::S8:
return no_endianness + "i" + support::cpp11::to_string(sizeof(int8_t));