diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2018-01-10 15:33:28 +0000 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:43:42 +0000 |
commit | 652bde553f506caac4c563988dc9baf746f9584d (patch) | |
tree | 931d17bdfa70e9968cd434cfa53db8919bb534ea /utils | |
parent | f72f9367d1eddee91f15a64952b99ee6b80b821d (diff) | |
download | ComputeLibrary-652bde553f506caac4c563988dc9baf746f9584d.tar.gz |
COMPMID-674 - Create Google InceptionV3 example
Change-Id: I389e0d4104b7dde60b7cdd612a83f3328517e44c
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115804
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'utils')
-rw-r--r-- | utils/GraphUtils.cpp | 21 | ||||
-rw-r--r-- | utils/GraphUtils.h | 46 |
2 files changed, 50 insertions, 17 deletions
diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp index 6b3dffc1a4..2ff40b7fbb 100644 --- a/utils/GraphUtils.cpp +++ b/utils/GraphUtils.cpp @@ -30,13 +30,7 @@ #include "arm_compute/runtime/CL/CLTensor.h" #endif /* ARM_COMPUTE_CL */ -#include "arm_compute/core/Error.h" -#include "arm_compute/core/PixelValue.h" - -#include <algorithm> #include <iomanip> -#include <ostream> -#include <random> using namespace arm_compute::graph_utils; @@ -80,8 +74,10 @@ bool DummyAccessor::access_tensor(ITensor &tensor) return ret; } -PPMAccessor::PPMAccessor(const std::string &ppm_path, bool bgr, float mean_r, float mean_g, float mean_b) - : _ppm_path(ppm_path), _bgr(bgr), _mean_r(mean_r), _mean_g(mean_g), _mean_b(mean_b) +PPMAccessor::PPMAccessor(std::string ppm_path, bool bgr, + float mean_r, float mean_g, float mean_b, + float std_r, float std_g, float std_b) + : _ppm_path(std::move(ppm_path)), _bgr(bgr), _mean_r(mean_r), _mean_g(mean_g), _mean_b(mean_b), _std_r(std_r), _std_g(std_g), _std_b(std_b) { } @@ -94,6 +90,12 @@ bool PPMAccessor::access_tensor(ITensor &tensor) _mean_g, _bgr ? _mean_r : _mean_b }; + const float std[3] = + { + _bgr ? _std_b : _std_r, + _std_g, + _bgr ? _std_r : _std_b + }; // Open PPM file ppm.open(_ppm_path); @@ -111,7 +113,7 @@ bool PPMAccessor::access_tensor(ITensor &tensor) execute_window_loop(window, [&](const Coordinates & id) { const float value = *reinterpret_cast<float *>(tensor.ptr_to_element(id)) - mean[id.z()]; - *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = value; + *reinterpret_cast<float *>(tensor.ptr_to_element(id)) = value / std[id.z()]; }); return true; @@ -330,6 +332,7 @@ bool NumPyBinLoader::access_tensor(ITensor &tensor) // Validate tensor shape ARM_COMPUTE_ERROR_ON_MSG(shape.size() != tensor_shape.num_dimensions(), "Tensor ranks mismatch"); + if(fortran_order) { for(size_t i = 0; i < shape.size(); ++i) diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h index e97bbf1c49..da52c26520 100644 --- a/utils/GraphUtils.h +++ b/utils/GraphUtils.h @@ -90,8 +90,13 @@ public: * @param[in] mean_r (Optional) Red mean value to be subtracted from red channel * @param[in] mean_g (Optional) Green mean value to be subtracted from green channel * @param[in] mean_b (Optional) Blue mean value to be subtracted from blue channel + * @param[in] std_r (Optional) Red standard deviation value to be divided from red channel + * @param[in] std_g (Optional) Green standard deviation value to be divided from green channel + * @param[in] std_b (Optional) Blue standard deviation value to be divided from blue channel */ - PPMAccessor(const std::string &ppm_path, bool bgr = true, float mean_r = 0.0f, float mean_g = 0.0f, float mean_b = 0.0f); + PPMAccessor(std::string ppm_path, bool bgr = true, + float mean_r = 0.0f, float mean_g = 0.0f, float mean_b = 0.0f, + float std_r = 1.f, float std_g = 1.f, float std_b = 1.f); /** Allow instances of this class to be move constructed */ PPMAccessor(PPMAccessor &&) = default; @@ -99,11 +104,14 @@ public: bool access_tensor(ITensor &tensor) override; private: - const std::string &_ppm_path; - const bool _bgr; - const float _mean_r; - const float _mean_g; - const float _mean_b; + const std::string _ppm_path; + const bool _bgr; + const float _mean_r; + const float _mean_g; + const float _mean_b; + const float _std_r; + const float _std_g; + const float _std_b; }; /** Result accessor class */ @@ -180,6 +188,19 @@ private: const std::string _filename; }; +/** Generates appropriate random accessor + * + * @param[in] lower Lower random values bound + * @param[in] upper Upper random values bound + * @param[in] seed Random generator seed + * + * @return A ramdom accessor + */ +inline std::unique_ptr<graph::ITensorAccessor> get_random_accessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed = 0) +{ + return arm_compute::support::cpp14::make_unique<RandomAccessor>(lower, upper, seed); +} + /** Generates appropriate weights accessor according to the specified path * * @note If path is empty will generate a DummyAccessor else will generate a NumPyBinLoader @@ -209,10 +230,17 @@ inline std::unique_ptr<graph::ITensorAccessor> get_weights_accessor(const std::s * @param[in] mean_r Red mean value to be subtracted from red channel * @param[in] mean_g Green mean value to be subtracted from green channel * @param[in] mean_b Blue mean value to be subtracted from blue channel + * @param[in] std_r (Optional) Red standard deviation value to be divided from red channel + * @param[in] std_g (Optional) Green standard deviation value to be divided from green channel + * @param[in] std_b (Optional) Blue standard deviation value to be divided from blue channel + * @param[in] bgr (Optional) Fill the first plane with blue channel (default = true) * * @return An appropriate tensor accessor */ -inline std::unique_ptr<graph::ITensorAccessor> get_input_accessor(const std::string &ppm_path, float mean_r, float mean_g, float mean_b) +inline std::unique_ptr<graph::ITensorAccessor> get_input_accessor(const std::string &ppm_path, + float mean_r = 0.f, float mean_g = 0.f, float mean_b = 0.f, + float std_r = 1.f, float std_g = 1.f, float std_b = 1.f, + bool bgr = true) { if(ppm_path.empty()) { @@ -220,7 +248,9 @@ inline std::unique_ptr<graph::ITensorAccessor> get_input_accessor(const std::str } else { - return arm_compute::support::cpp14::make_unique<PPMAccessor>(ppm_path, true, mean_r, mean_g, mean_b); + return arm_compute::support::cpp14::make_unique<PPMAccessor>(ppm_path, bgr, + mean_r, mean_g, mean_b, + std_r, std_g, std_b); } } |