arm_compute v19.11
diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp
index 00165cd..71bfc37 100644
--- a/utils/GraphUtils.cpp
+++ b/utils/GraphUtils.cpp
@@ -28,9 +28,14 @@
#include "arm_compute/core/Types.h"
#include "arm_compute/graph/Logger.h"
#include "arm_compute/runtime/SubTensor.h"
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-parameter"
#include "utils/ImageLoader.h"
+#pragma GCC diagnostic pop
#include "utils/Utils.h"
+#include <inttypes.h>
#include <iomanip>
#include <limits>
@@ -63,17 +68,33 @@
}
void TFPreproccessor::preprocess(ITensor &tensor)
{
+ if(tensor.info()->data_type() == DataType::F32)
+ {
+ preprocess_typed<float>(tensor);
+ }
+ else if(tensor.info()->data_type() == DataType::F16)
+ {
+ preprocess_typed<half>(tensor);
+ }
+ else
+ {
+ ARM_COMPUTE_ERROR("NOT SUPPORTED!");
+ }
+}
+
+template <typename T>
+void TFPreproccessor::preprocess_typed(ITensor &tensor)
+{
Window window;
window.use_tensor_dimensions(tensor.info()->tensor_shape());
const float range = _max_range - _min_range;
-
execute_window_loop(window, [&](const Coordinates & id)
{
- const float value = *reinterpret_cast<float *>(tensor.ptr_to_element(id));
- float res = value / 255.f; // Normalize to [0, 1]
- res = res * range + _min_range; // Map to [min_range, max_range]
- *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = res;
+ const T value = *reinterpret_cast<T *>(tensor.ptr_to_element(id));
+ float res = value / 255.f; // Normalize to [0, 1]
+ res = res * range + _min_range; // Map to [min_range, max_range]
+ *reinterpret_cast<T *>(tensor.ptr_to_element(id)) = res;
});
}
@@ -88,15 +109,31 @@
void CaffePreproccessor::preprocess(ITensor &tensor)
{
+ if(tensor.info()->data_type() == DataType::F32)
+ {
+ preprocess_typed<float>(tensor);
+ }
+ else if(tensor.info()->data_type() == DataType::F16)
+ {
+ preprocess_typed<half>(tensor);
+ }
+ else
+ {
+ ARM_COMPUTE_ERROR("NOT SUPPORTED!");
+ }
+}
+
+template <typename T>
+void CaffePreproccessor::preprocess_typed(ITensor &tensor)
+{
Window window;
window.use_tensor_dimensions(tensor.info()->tensor_shape());
-
const int channel_idx = get_data_layout_dimension_index(tensor.info()->data_layout(), DataLayoutDimension::CHANNEL);
execute_window_loop(window, [&](const Coordinates & id)
{
- const float value = *reinterpret_cast<float *>(tensor.ptr_to_element(id)) - _mean[id[channel_idx]];
- *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = value * _scale;
+ const T value = *reinterpret_cast<T *>(tensor.ptr_to_element(id)) - T(_mean[id[channel_idx]]);
+ *reinterpret_cast<T *>(tensor.ptr_to_element(id)) = value * T(_scale);
});
}
@@ -186,6 +223,19 @@
return false;
}
+#ifdef ARM_COMPUTE_ASSERTS_ENABLED
+PrintAccessor::PrintAccessor(std::ostream &output_stream, IOFormatInfo io_fmt)
+ : _output_stream(output_stream), _io_fmt(io_fmt)
+{
+}
+
+bool PrintAccessor::access_tensor(ITensor &tensor)
+{
+ tensor.print(_output_stream, _io_fmt);
+ return false;
+}
+#endif /* ARM_COMPUTE_ASSERTS_ENABLED */
+
SaveNumPyAccessor::SaveNumPyAccessor(std::string npy_name, const bool is_fortran)
: _npy_name(std::move(npy_name)), _is_fortran(is_fortran)
{
@@ -222,9 +272,9 @@
{
std::tie(permuted_shape, perm) = compute_permutation_parameters(tensor.info()->tensor_shape(), tensor.info()->data_layout());
}
- ARM_COMPUTE_EXIT_ON_MSG(image_loader->width() != permuted_shape.x() || image_loader->height() != permuted_shape.y(),
- "Failed to load image file: dimensions [%d,%d] not correct, expected [%d,%d].",
- image_loader->width(), image_loader->height(), permuted_shape.x(), permuted_shape.y());
+ ARM_COMPUTE_EXIT_ON_MSG_VAR(image_loader->width() != permuted_shape.x() || image_loader->height() != permuted_shape.y(),
+ "Failed to load image file: dimensions [%d,%d] not correct, expected [%" PRIu32 ",%" PRIu32 "].",
+ image_loader->width(), image_loader->height(), permuted_shape.x(), permuted_shape.y());
// Fill the tensor with the PPM content (BGR)
image_loader->fill_planar_tensor(tensor, _bgr);
@@ -274,7 +324,7 @@
}
catch(const std::ifstream::failure &e)
{
- ARM_COMPUTE_ERROR("Accessing %s: %s", image_list.c_str(), e.what());
+ ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", image_list.c_str(), e.what());
}
}
@@ -298,9 +348,9 @@
std::tie(permuted_shape, perm) = compute_permutation_parameters(tensor.info()->tensor_shape(),
tensor.info()->data_layout());
}
- ARM_COMPUTE_EXIT_ON_MSG(jpeg.width() != permuted_shape.x() || jpeg.height() != permuted_shape.y(),
- "Failed to load image file: dimensions [%d,%d] not correct, expected [%d,%d].",
- jpeg.width(), jpeg.height(), permuted_shape.x(), permuted_shape.y());
+ ARM_COMPUTE_EXIT_ON_MSG_VAR(jpeg.width() != permuted_shape.x() || jpeg.height() != permuted_shape.y(),
+ "Failed to load image file: dimensions [%d,%d] not correct, expected [%" PRIu32 ",%" PRIu32 "].",
+ jpeg.width(), jpeg.height(), permuted_shape.x(), permuted_shape.y());
// Fill the tensor with the JPEG content (BGR)
jpeg.fill_planar_tensor(tensor, _bgr);
@@ -347,7 +397,7 @@
}
catch(const std::ifstream::failure &e)
{
- ARM_COMPUTE_ERROR("Accessing %s: %s", image_list.c_str(), e.what());
+ ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", image_list.c_str(), e.what());
}
}
@@ -370,6 +420,9 @@
case DataType::QASYMM8:
tensor_results = access_predictions_tensor<uint8_t>(tensor);
break;
+ case DataType::F16:
+ tensor_results = access_predictions_tensor<half>(tensor);
+ break;
case DataType::F32:
tensor_results = access_predictions_tensor<float>(tensor);
break;
@@ -460,7 +513,7 @@
}
catch(const std::ifstream::failure &e)
{
- ARM_COMPUTE_ERROR("Accessing %s: %s", labels_path.c_str(), e.what());
+ ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", labels_path.c_str(), e.what());
}
}
@@ -531,7 +584,7 @@
}
catch(const std::ifstream::failure &e)
{
- ARM_COMPUTE_ERROR("Accessing %s: %s", labels_path.c_str(), e.what());
+ ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", labels_path.c_str(), e.what());
}
}