diff options
author | Isabella Gottardi <isabella.gottardi@arm.com> | 2018-04-06 12:24:55 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:52:35 +0000 |
commit | 88d5b22eb5574d8b564474df2c758d222b3b5547 (patch) | |
tree | 92edf8ecc38a9349faf1ef958998abddcf5b9a8c /utils/GraphUtils.h | |
parent | bcedf513938fca9e33331bdef975f0488288bad4 (diff) | |
download | ComputeLibrary-88d5b22eb5574d8b564474df2c758d222b3b5547.tar.gz |
COMPMID-1035 - Add ResneXt50 as a graph example
Change-Id: I42f0e7dab38e45b5eecfe6858eaecee8939c8585
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/129291
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'utils/GraphUtils.h')
-rw-r--r-- | utils/GraphUtils.h | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h index a8507b1ac7..597708369d 100644 --- a/utils/GraphUtils.h +++ b/utils/GraphUtils.h @@ -25,9 +25,11 @@ #define __ARM_COMPUTE_GRAPH_UTILS_H__ #include "arm_compute/core/PixelValue.h" +#include "arm_compute/core/utils/misc/Utility.h" #include "arm_compute/graph/Graph.h" #include "arm_compute/graph/ITensorAccessor.h" #include "arm_compute/graph/Types.h" +#include "arm_compute/runtime/Tensor.h" #include <array> #include <random> @@ -117,6 +119,37 @@ private: unsigned int _maximum; }; +/** NumPy accessor class */ +class NumPyAccessor final : public graph::ITensorAccessor +{ +public: + /** Constructor + * + * @param[in] npy_path Path to npy file. + * @param[in] shape Shape of the numpy tensor data. + * @param[in] data_type DataType of the numpy tensor data. + * @param[out] output_stream (Optional) Output stream + */ + NumPyAccessor(std::string npy_path, TensorShape shape, DataType data_type, std::ostream &output_stream = std::cout); + /** Allow instances of this class to be move constructed */ + NumPyAccessor(NumPyAccessor &&) = default; + /** Prevent instances of this class from being copied (As this class contains pointers) */ + NumPyAccessor(const NumPyAccessor &) = delete; + /** Prevent instances of this class from being copied (As this class contains pointers) */ + NumPyAccessor &operator=(const NumPyAccessor &) = delete; + + // Inherited methods overriden: + bool access_tensor(ITensor &tensor) override; + +private: + template <typename T> + void access_numpy_tensor(ITensor &tensor); + + Tensor _npy_tensor; + const std::string _filename; + std::ostream &_output_stream; +}; + /** PPM accessor class */ class PPMAccessor final : public graph::ITensorAccessor { @@ -273,7 +306,14 @@ inline std::unique_ptr<graph::ITensorAccessor> get_input_accessor(const std::str } else { - return arm_compute::support::cpp14::make_unique<PPMAccessor>(ppm_path, bgr, std::move(preprocessor)); + if(arm_compute::utility::endswith(ppm_path, ".npy")) + { + return arm_compute::support::cpp14::make_unique<NumPyBinLoader>(ppm_path); + } + else + { + return arm_compute::support::cpp14::make_unique<PPMAccessor>(ppm_path, bgr, std::move(preprocessor)); + } } } @@ -298,6 +338,28 @@ inline std::unique_ptr<graph::ITensorAccessor> get_output_accessor(const std::st return arm_compute::support::cpp14::make_unique<TopNPredictionsAccessor>(labels_path, top_n, output_stream); } } +/** Generates appropriate npy output accessor according to the specified npy_path + * + * @note If npy_path is empty will generate a DummyAccessor else will generate a NpyAccessor + * + * @param[in] npy_path Path to npy file. + * @param[in] shape Shape of the numpy tensor data. + * @param[in] data_type DataType of the numpy tensor data. + * @param[out] output_stream (Optional) Output stream + * + * @return An appropriate tensor accessor + */ +inline std::unique_ptr<graph::ITensorAccessor> get_npy_output_accessor(const std::string &npy_path, TensorShape shape, DataType data_type, std::ostream &output_stream = std::cout) +{ + if(npy_path.empty()) + { + return arm_compute::support::cpp14::make_unique<DummyAccessor>(0); + } + else + { + return arm_compute::support::cpp14::make_unique<NumPyAccessor>(npy_path, shape, data_type, output_stream); + } +} /** Utility function to return the TargetHint * |