aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAnthony Barbier <anthony.barbier@arm.com>2018-08-21 18:16:53 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:54:54 +0000
commit8a042116e26b702a74514b251b0961c4b661e6ca (patch)
tree1d6b06490401dc491ea8e97bf3daa9eedfcc00a0 /utils
parent80040bce896357fa15b7a6f05a624b9e18ee5821 (diff)
downloadComputeLibrary-8a042116e26b702a74514b251b0961c4b661e6ca.tar.gz
COMPMID-1188: Revert change to DummyAccessor, fixed NPY and Image loaders
Change-Id: If645dc88871cb2bc3fb68bba5b90e656869d8b5a Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/145079 Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com> Tested-by: Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/GraphUtils.cpp64
-rw-r--r--utils/GraphUtils.h2
2 files changed, 38 insertions, 28 deletions
diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp
index a83d3beb5d..bfb8ba34c3 100644
--- a/utils/GraphUtils.cpp
+++ b/utils/GraphUtils.cpp
@@ -128,7 +128,7 @@ DummyAccessor::DummyAccessor(unsigned int maximum)
bool DummyAccessor::access_tensor(ITensor &tensor)
{
ARM_COMPUTE_UNUSED(tensor);
- bool ret = _iterator < _maximum;
+ bool ret = _maximum == 0 || _iterator < _maximum;
if(_iterator == _maximum)
{
_iterator = 0;
@@ -180,39 +180,43 @@ bool NumPyAccessor::access_tensor(ITensor &tensor)
}
ImageAccessor::ImageAccessor(std::string filename, bool bgr, std::unique_ptr<IPreprocessor> preprocessor)
- : _filename(std::move(filename)), _bgr(bgr), _preprocessor(std::move(preprocessor))
+ : _already_loaded(false), _filename(std::move(filename)), _bgr(bgr), _preprocessor(std::move(preprocessor))
{
}
bool ImageAccessor::access_tensor(ITensor &tensor)
{
- auto image_loader = utils::ImageLoaderFactory::create(_filename);
- ARM_COMPUTE_EXIT_ON_MSG(image_loader == nullptr, "Unsupported image type");
+ if(!_already_loaded)
+ {
+ auto image_loader = utils::ImageLoaderFactory::create(_filename);
+ ARM_COMPUTE_EXIT_ON_MSG(image_loader == nullptr, "Unsupported image type");
- // Open image file
- image_loader->open(_filename);
+ // Open image file
+ image_loader->open(_filename);
- // 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_parameters(tensor.info()->tensor_shape(), tensor.info()->data_layout());
- }
- ARM_COMPUTE_EXIT_ON_MSG(image_loader->width() != permuted_shape.x() || image_loader->height() != permuted_shape.y(),
- "Failed to load image file: dimensions [%d,%d] not correct, expected [%d,%d].",
- image_loader->width(), image_loader->height(), permuted_shape.x(), permuted_shape.y());
+ // 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_parameters(tensor.info()->tensor_shape(), tensor.info()->data_layout());
+ }
+ ARM_COMPUTE_EXIT_ON_MSG(image_loader->width() != permuted_shape.x() || image_loader->height() != permuted_shape.y(),
+ "Failed to load image file: dimensions [%d,%d] not correct, expected [%d,%d].",
+ image_loader->width(), image_loader->height(), permuted_shape.x(), permuted_shape.y());
- // Fill the tensor with the PPM content (BGR)
- image_loader->fill_planar_tensor(tensor, _bgr);
+ // Fill the tensor with the PPM content (BGR)
+ image_loader->fill_planar_tensor(tensor, _bgr);
- // Preprocess tensor
- if(_preprocessor)
- {
- _preprocessor->preprocess(tensor);
+ // Preprocess tensor
+ if(_preprocessor)
+ {
+ _preprocessor->preprocess(tensor);
+ }
}
- return true;
+ _already_loaded = !_already_loaded;
+ return _already_loaded;
}
ValidationInputAccessor::ValidationInputAccessor(const std::string &image_list,
@@ -602,15 +606,19 @@ bool RandomAccessor::access_tensor(ITensor &tensor)
}
NumPyBinLoader::NumPyBinLoader(std::string filename, DataLayout file_layout)
- : _filename(std::move(filename)), _file_layout(file_layout)
+ : _already_loaded(false), _filename(std::move(filename)), _file_layout(file_layout)
{
}
bool NumPyBinLoader::access_tensor(ITensor &tensor)
{
- utils::NPYLoader loader;
- loader.open(_filename, _file_layout);
- loader.fill_tensor(tensor);
+ if(!_already_loaded)
+ {
+ utils::NPYLoader loader;
+ loader.open(_filename, _file_layout);
+ loader.fill_tensor(tensor);
+ }
- return true;
+ _already_loaded = !_already_loaded;
+ return _already_loaded;
}
diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h
index bc7699b70c..a6d670d761 100644
--- a/utils/GraphUtils.h
+++ b/utils/GraphUtils.h
@@ -183,6 +183,7 @@ public:
bool access_tensor(ITensor &tensor) override;
private:
+ bool _already_loaded;
const std::string _filename;
const bool _bgr;
std::unique_ptr<IPreprocessor> _preprocessor;
@@ -352,6 +353,7 @@ public:
bool access_tensor(ITensor &tensor) override;
private:
+ bool _already_loaded;
const std::string _filename;
const DataLayout _file_layout;
};