aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorIsabella Gottardi <isabella.gottardi@arm.com>2017-11-03 12:11:55 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:35:24 +0000
commita4c6188262d6d9f75f019e437f8190bdd56e604d (patch)
tree6abdf95cea0e1bdffca342386f899734604cc992 /utils
parentd621bca4e963555a99be4328c8d49d1813789649 (diff)
downloadComputeLibrary-a4c6188262d6d9f75f019e437f8190bdd56e604d.tar.gz
COMPMID-657 - Add PPMAccessor and TopNPredictionsAccessor to GoogleNet
Change-Id: Ib6f2f9e73043d2c59b2698c243fb1a9f51c526e9 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/94363 Tested-by: Kaizen <jeremy.johnson+kaizengerrit@arm.com> Reviewed-by: Gian Marco Iodice <gianmarco.iodice@arm.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/GraphUtils.cpp3
-rw-r--r--utils/GraphUtils.h66
-rw-r--r--utils/Utils.h14
3 files changed, 83 insertions, 0 deletions
diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp
index 15767632c8..9a1ed3d7d9 100644
--- a/utils/GraphUtils.cpp
+++ b/utils/GraphUtils.cpp
@@ -98,6 +98,9 @@ bool PPMAccessor::access_tensor(ITensor &tensor)
// Open PPM file
ppm.open(_ppm_path);
+ ARM_COMPUTE_ERROR_ON_MSG(ppm.width() != tensor.info()->dimension(0) || ppm.height() != tensor.info()->dimension(1),
+ "Failed to load image file: dimensions [%d,%d] not correct, expected [%d,%d].", ppm.width(), ppm.height(), tensor.info()->dimension(0), tensor.info()->dimension(1));
+
// Fill the tensor with the PPM content (BGR)
ppm.fill_planar_tensor(tensor, _bgr);
diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h
index 39b3f115bd..d7d5cd6778 100644
--- a/utils/GraphUtils.h
+++ b/utils/GraphUtils.h
@@ -175,6 +175,72 @@ public:
private:
const std::string _filename;
};
+
+/** Generates appropriate weights accessor according to the specified path
+ *
+ * @note If path is empty will generate a DummyAccessor else will generate a NumPyBinLoader
+ *
+ * @param[in] path Path to the data files
+ * @param[in] data_file Relative path to the data files from path
+ *
+ * @return An appropriate tensor accessor
+ */
+inline std::unique_ptr<graph::ITensorAccessor> get_weights_accessor(const std::string &path, const std::string &data_file)
+{
+ if(path.empty())
+ {
+ return arm_compute::support::cpp14::make_unique<DummyAccessor>();
+ }
+ else
+ {
+ return arm_compute::support::cpp14::make_unique<NumPyBinLoader>(path + data_file);
+ }
+}
+
+/** Generates appropriate input accessor according to the specified ppm_path
+ *
+ * @note If ppm_path is empty will generate a DummyAccessor else will generate a PPMAccessor
+ *
+ * @param[in] ppm_path Path to PPM file
+ * @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
+ *
+ * @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)
+{
+ if(ppm_path.empty())
+ {
+ return arm_compute::support::cpp14::make_unique<DummyAccessor>();
+ }
+ else
+ {
+ return arm_compute::support::cpp14::make_unique<PPMAccessor>(ppm_path, true, mean_r, mean_g, mean_b);
+ }
+}
+
+/** Generates appropriate output accessor according to the specified labels_path
+ *
+ * @note If labels_path is empty will generate a DummyAccessor else will generate a TopNPredictionsAccessor
+ *
+ * @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
+ *
+ * @return An appropriate tensor accessor
+ */
+inline std::unique_ptr<graph::ITensorAccessor> get_output_accessor(const std::string &labels_path, size_t top_n = 5, std::ostream &output_stream = std::cout)
+{
+ if(labels_path.empty())
+ {
+ return arm_compute::support::cpp14::make_unique<DummyAccessor>();
+ }
+ else
+ {
+ return arm_compute::support::cpp14::make_unique<TopNPredictionsAccessor>(labels_path, top_n, output_stream);
+ }
+}
} // namespace graph_utils
} // namespace arm_compute
diff --git a/utils/Utils.h b/utils/Utils.h
index 1f3d971917..28382f47e4 100644
--- a/utils/Utils.h
+++ b/utils/Utils.h
@@ -410,6 +410,20 @@ public:
}
}
+ /** Return the width of the currently open PPM file.
+ */
+ unsigned int width() const
+ {
+ return _width;
+ }
+
+ /** Return the height of the currently open PPM file.
+ */
+ unsigned int height() const
+ {
+ return _height;
+ }
+
private:
std::ifstream _fs;
unsigned int _width, _height;