From 32521430ad67172d372721979e8a32b7d4317620 Mon Sep 17 00:00:00 2001 From: Pablo Tello Date: Thu, 15 Nov 2018 14:43:10 +0000 Subject: COMPMID-1750: Add PriorBox operator to graph API. Change-Id: I5d2ed5dcc342abff8124762f7bdee587cdf20032 --- utils/GraphUtils.cpp | 6 +++--- utils/GraphUtils.h | 6 ++++-- utils/Utils.h | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) (limited to 'utils') diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp index 19fba4c0bf..2f1df7aef2 100644 --- a/utils/GraphUtils.cpp +++ b/utils/GraphUtils.cpp @@ -77,8 +77,8 @@ void TFPreproccessor::preprocess(ITensor &tensor) }); } -CaffePreproccessor::CaffePreproccessor(std::array mean, bool bgr) - : _mean(mean), _bgr(bgr) +CaffePreproccessor::CaffePreproccessor(std::array mean, float scale, bool bgr) + : _mean(mean), _scale(scale), _bgr(bgr) { if(_bgr) { @@ -96,7 +96,7 @@ void CaffePreproccessor::preprocess(ITensor &tensor) execute_window_loop(window, [&](const Coordinates & id) { const float value = *reinterpret_cast(tensor.ptr_to_element(id)) - _mean[id[channel_idx]]; - *reinterpret_cast(tensor.ptr_to_element(id)) = value; + *reinterpret_cast(tensor.ptr_to_element(id)) = value * _scale; }); } diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h index a6d670d761..d7f24afdd8 100644 --- a/utils/GraphUtils.h +++ b/utils/GraphUtils.h @@ -63,14 +63,16 @@ public: /** Default Constructor * * @param mean Mean array in RGB ordering + * @param scale Scale value * @param bgr Boolean specifying if the preprocessing should assume BGR format */ - CaffePreproccessor(std::array mean = std::array { { 0, 0, 0 } }, bool bgr = true); + CaffePreproccessor(std::array mean = std::array { { 0, 0, 0 } }, float scale = 1.f, bool bgr = true); void preprocess(ITensor &tensor) override; private: std::array _mean; - bool _bgr; + float _scale; + bool _bgr; }; /** TF preproccessor */ diff --git a/utils/Utils.h b/utils/Utils.h index 92ab1a30b9..8cac857178 100644 --- a/utils/Utils.h +++ b/utils/Utils.h @@ -607,7 +607,6 @@ void save_to_ppm(T &tensor, const std::string &ppm_filename) /** Template helper function to save a tensor image to a NPY file. * * @note Only F32 data type supported. - * @note Only works with 2D tensors. * @note If the input tensor is a CLTensor, the function maps and unmaps the image * * @param[in] tensor The tensor to save as NPY file @@ -627,9 +626,9 @@ void save_to_npy(T &tensor, const std::string &npy_filename, bool fortran_order) std::vector shape(tensor.info()->num_dimensions()); - for(unsigned int i = 0; i < tensor.info()->num_dimensions(); ++i) + for(unsigned int i = 0, j = tensor.info()->num_dimensions() - 1; i < tensor.info()->num_dimensions(); ++i, --j) { - shape[i] = tensor.info()->tensor_shape()[i]; + shape[i] = tensor.info()->tensor_shape()[!fortran_order ? j : i]; } // Map buffer if creating a CLTensor @@ -802,12 +801,13 @@ int compare_tensor(ITensor &tensor1, ITensor &tensor2) map(tensor1, true); map(tensor2, true); + Iterator itensor1(&tensor1, window); Iterator itensor2(&tensor2, window); execute_window_loop(window, [&](const Coordinates & id) { - if(std::abs(*reinterpret_cast(itensor1.ptr()) - *reinterpret_cast(itensor2.ptr())) > 0.00001) + if(std::abs(*reinterpret_cast(itensor1.ptr()) - *reinterpret_cast(itensor2.ptr())) > 0.0001) { ++num_mismatches; } -- cgit v1.2.1