From 44ec2e7c1edd57eb2fb2674a28452aac02bd8c0a Mon Sep 17 00:00:00 2001 From: Gian Marco Date: Thu, 19 Oct 2017 14:13:38 +0100 Subject: COMPMID-639 - Add PPMAccessor and TopNPredictionsAccessor in graph_utils Change-Id: I40c3e2dfcde10c65ed9c86f9283a53f9e679d4fa Reviewed-on: http://mpd-gerrit.cambridge.arm.com/92437 Reviewed-by: Anthony Barbier Tested-by: Kaizen --- utils/GraphUtils.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'utils/GraphUtils.h') diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h index 5c370e5eba..39b3f115bd 100644 --- a/utils/GraphUtils.h +++ b/utils/GraphUtils.h @@ -29,6 +29,8 @@ #include "arm_compute/graph/Types.h" #include +#include +#include namespace arm_compute { @@ -76,6 +78,60 @@ private: unsigned int _maximum; }; +/** PPM accessor class */ +class PPMAccessor final : public graph::ITensorAccessor +{ +public: + /** Constructor + * + * @param[in] ppm_path Path to PPM file + * @param[in] bgr (Optional) Fill the first plane with blue channel (default = false) + * @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 + */ + PPMAccessor(const std::string &ppm_path, bool bgr = true, float mean_r = 0.0f, float mean_g = 0.0f, float mean_b = 0.0f); + /** Allow instances of this class to be move constructed */ + PPMAccessor(PPMAccessor &&) = default; + + // Inherited methods overriden: + 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; +}; + +/** Result accessor class */ +class TopNPredictionsAccessor final : public graph::ITensorAccessor +{ +public: + /** Constructor + * + * @param[in] labels_path Path to labels text file. + * @param[in] top_n (Optional) Number of output classes to print + * @param[out] output_stream (Optional) Output stream + */ + TopNPredictionsAccessor(const std::string &labels_path, size_t top_n = 5, std::ostream &output_stream = std::cout); + /** Allow instances of this class to be move constructed */ + TopNPredictionsAccessor(TopNPredictionsAccessor &&) = default; + /** Prevent instances of this class from being copied (As this class contains pointers) */ + TopNPredictionsAccessor(const TopNPredictionsAccessor &) = delete; + /** Prevent instances of this class from being copied (As this class contains pointers) */ + TopNPredictionsAccessor &operator=(const TopNPredictionsAccessor &) = delete; + + // Inherited methods overriden: + bool access_tensor(ITensor &tensor) override; + +private: + std::vector _labels; + std::ostream &_output_stream; + size_t _top_n; +}; + /** Random accessor class */ class RandomAccessor final : public graph::ITensorAccessor { -- cgit v1.2.1