diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2018-06-21 19:01:25 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:53:57 +0000 |
commit | 7c3b92403958e8970e901fd15b2fc904e7996eee (patch) | |
tree | 09250c8269ad2f78f2a8587f454d83728e97e9dc /utils/GraphUtils.cpp | |
parent | f3139dde4b93b4ea54e4f3bcd27e639c22a7b6ca (diff) | |
download | ComputeLibrary-7c3b92403958e8970e901fd15b2fc904e7996eee.tar.gz |
COMPMID-1308: Add and validate JPEG accessors
Change-Id: I93d7345a795b26153600287346d672209dbb2622
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/137479
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'utils/GraphUtils.cpp')
-rw-r--r-- | utils/GraphUtils.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp index b51e122d61..4db053cf9f 100644 --- a/utils/GraphUtils.cpp +++ b/utils/GraphUtils.cpp @@ -27,6 +27,7 @@ #include "arm_compute/core/Helpers.h" #include "arm_compute/core/Types.h" #include "arm_compute/runtime/SubTensor.h" +#include "utils/ImageLoader.h" #include "utils/Utils.h" #include <iomanip> @@ -202,6 +203,71 @@ bool PPMAccessor::access_tensor(ITensor &tensor) return true; } +ValidationInputAccessor::ValidationInputAccessor(const std::string &image_list, + std::string images_path, + bool bgr, + unsigned int start, + unsigned int end) + : _path(std::move(images_path)), _images(), _bgr(bgr), _offset(0) +{ + ARM_COMPUTE_ERROR_ON_MSG(start > end, "Invalid validation range!"); + + std::ifstream ifs; + try + { + ifs.exceptions(std::ifstream::badbit); + ifs.open(image_list, std::ios::in | std::ios::binary); + + // Parse image names + unsigned int counter = 0; + for(std::string line; !std::getline(ifs, line).fail() && counter <= end; ++counter) + { + // Add image to process if withing range + if(counter >= start) + { + std::stringstream linestream(line); + std::string image_name; + + linestream >> image_name; + _images.emplace_back(std::move(image_name)); + } + } + } + catch(const std::ifstream::failure &e) + { + ARM_COMPUTE_ERROR("Accessing %s: %s", image_list.c_str(), e.what()); + } +} + +bool ValidationInputAccessor::access_tensor(arm_compute::ITensor &tensor) +{ + bool ret = _offset < _images.size(); + if(ret) + { + utils::JPEGLoader jpeg; + + // Open JPEG file + jpeg.open(_path + _images[_offset++]); + + // Get permutated shape and permutation parameters + TensorShape permuted_shape = tensor.info()->tensor_shape(); + arm_compute::PermutationVector perm; + if(tensor.info()->data_layout() != DataLayout::NCHW) + { + std::tie(permuted_shape, perm) = compute_permutation_paramaters(tensor.info()->tensor_shape(), + tensor.info()->data_layout()); + } + ARM_COMPUTE_ERROR_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()); + + // Fill the tensor with the PPM content (BGR) + jpeg.fill_planar_tensor(tensor, _bgr); + } + + return ret; +} + TopNPredictionsAccessor::TopNPredictionsAccessor(const std::string &labels_path, size_t top_n, std::ostream &output_stream) : _labels(), _output_stream(output_stream), _top_n(top_n) { |