24 #ifndef __ARM_COMPUTE_UTILS_GRAPH_UTILS_H__ 25 #define __ARM_COMPUTE_UTILS_GRAPH_UTILS_H__ 69 CaffePreproccessor(std::array<float, 3> mean = std::array<float, 3> { { 0, 0, 0 } },
bool bgr =
true,
float scale = 1.f);
74 void preprocess_typed(
ITensor &tensor);
76 std::array<float, 3> _mean;
97 void preprocess_typed(
ITensor &tensor);
117 bool access_tensor(
ITensor &tensor)
override;
120 const std::string _name;
121 unsigned int _iterator;
122 unsigned int _maximum;
138 bool access_tensor(
ITensor &tensor)
override;
141 unsigned int _iterator;
142 unsigned int _maximum;
166 bool access_tensor(
ITensor &tensor)
override;
169 template <
typename T>
170 void access_numpy_tensor(
ITensor &tensor, T tolerance);
173 const std::string _filename;
174 std::ostream &_output_stream;
195 bool access_tensor(
ITensor &tensor)
override;
198 const std::string _npy_name;
199 const bool _is_fortran;
222 bool access_tensor(
ITensor &tensor)
override;
225 std::ostream &_output_stream;
239 ImageAccessor(std::string filename,
bool bgr =
true, std::unique_ptr<IPreprocessor> preprocessor =
nullptr);
244 bool access_tensor(
ITensor &tensor)
override;
247 bool _already_loaded;
248 const std::string _filename;
250 std::unique_ptr<IPreprocessor> _preprocessor;
270 std::string images_path,
271 std::unique_ptr<IPreprocessor> preprocessor =
nullptr,
273 unsigned int start = 0,
274 unsigned int end = 0,
275 std::ostream &output_stream = std::cout);
278 bool access_tensor(
ITensor &tensor)
override;
282 std::vector<std::string> _images;
283 std::unique_ptr<IPreprocessor> _preprocessor;
286 std::ostream &_output_stream;
303 std::ostream &output_stream = std::cout,
304 unsigned int start = 0,
305 unsigned int end = 0);
310 bool access_tensor(
ITensor &tensor)
override;
319 template <
typename T>
320 std::vector<size_t> access_predictions_tensor(
ITensor &tensor);
328 void aggregate_sample(
const std::vector<size_t> &res,
size_t &positive_samples,
size_t top_n,
size_t correct_label);
335 void report_top_n(
size_t top_n,
size_t total_samples,
size_t positive_samples);
338 std::vector<int> _results;
339 std::ostream &_output_stream;
341 size_t _positive_samples_top1;
342 size_t _positive_samples_top5;
355 DetectionOutputAccessor(
const std::string &labels_path, std::vector<TensorShape> &imgs_tensor_shapes, std::ostream &output_stream = std::cout);
364 bool access_tensor(
ITensor &tensor)
override;
367 template <
typename T>
368 void access_predictions_tensor(
ITensor &tensor);
370 std::vector<std::string> _labels;
371 std::vector<TensorShape> _tensor_shapes;
372 std::ostream &_output_stream;
385 TopNPredictionsAccessor(
const std::string &labels_path,
size_t top_n = 5, std::ostream &output_stream = std::cout);
394 bool access_tensor(
ITensor &tensor)
override;
397 template <
typename T>
398 void access_predictions_tensor(
ITensor &tensor);
400 std::vector<std::string> _labels;
401 std::ostream &_output_stream;
420 bool access_tensor(
ITensor &tensor)
override;
423 template <
typename T,
typename D>
427 std::random_device::result_type _seed;
444 bool access_tensor(
ITensor &tensor)
override;
447 bool _already_loaded;
448 const std::string _filename;
462 return std::make_unique<RandomAccessor>(lower, upper, seed);
476 const std::string &data_file,
481 return std::make_unique<DummyAccessor>();
485 return std::make_unique<NumPyBinLoader>(path + data_file, file_layout);
498 std::unique_ptr<IPreprocessor> preprocessor =
nullptr,
503 return std::make_unique<ValidationInputAccessor>(graph_parameters.
validation_file,
505 std::move(preprocessor),
512 const std::string &image_file = graph_parameters.
image;
513 const std::string &image_file_lower =
lower_string(image_file);
516 return std::make_unique<NumPyBinLoader>(image_file, graph_parameters.
data_layout);
522 return std::make_unique<ImageAccessor>(image_file, bgr, std::move(preprocessor));
526 return std::make_unique<DummyAccessor>();
545 bool is_validation =
false,
546 std::ostream &output_stream = std::cout)
551 return std::make_unique<ValidationOutputAccessor>(graph_parameters.
validation_file,
556 else if(graph_parameters.
labels.empty())
558 return std::make_unique<DummyAccessor>(0);
562 return std::make_unique<TopNPredictionsAccessor>(graph_parameters.
labels, top_n, output_stream);
578 std::vector<TensorShape> tensor_shapes,
579 bool is_validation =
false,
580 std::ostream &output_stream = std::cout)
585 return std::make_unique<ValidationOutputAccessor>(graph_parameters.
validation_file,
590 else if(graph_parameters.
labels.empty())
592 return std::make_unique<DummyAccessor>(0);
596 return std::make_unique<DetectionOutputAccessor>(graph_parameters.
labels, tensor_shapes, output_stream);
612 std::ostream &output_stream = std::cout)
616 return std::make_unique<DummyAccessor>(0);
637 return std::make_unique<DummyAccessor>(0);
641 return std::make_unique<SaveNumPyAccessor>(npy_name, is_fortran);
653 return std::make_unique<PrintAccessor>(output_stream);
666 if(in_data_layout != out_data_layout)
683 if((target == 1 || target == 2))
SaveNumPy accessor class.
graph::Target set_target_hint(int target)
Utility function to return the TargetHint.
Arm® Neon™ capable target device.
Class describing the value of a pixel for any image format.
std::unique_ptr< graph::ITensorAccessor > get_save_npy_output_accessor(const std::string &npy_name, const bool is_fortran=false)
Generates appropriate npy output accessor according to the specified npy_path.
std::string validation_path
std::unique_ptr< graph::ITensorAccessor > get_input_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, std::unique_ptr< IPreprocessor > preprocessor=nullptr, bool bgr=true)
Generates appropriate input accessor according to the specified graph parameters. ...
unsigned int validation_range_start
std::unique_ptr< graph::ITensorAccessor > get_detection_output_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, std::vector< TensorShape > tensor_shapes, bool is_validation=false, std::ostream &output_stream=std::cout)
Generates appropriate output accessor according to the specified graph parameters.
Strides PermutationVector
Permutation vector.
const DataLayout data_layout
std::unique_ptr< graph::ITensorAccessor > get_print_output_accessor(std::ostream &output_stream=std::cout)
Generates print tensor accessor.
std::unique_ptr< graph::ITensorAccessor > get_npy_output_accessor(const std::string &npy_path, TensorShape shape, DataType data_type, DataLayout data_layout=DataLayout::NCHW, std::ostream &output_stream=std::cout)
Generates appropriate npy output accessor according to the specified npy_path.
std::string lower_string(const std::string &val)
Lower a given string.
arm_compute::DataLayout data_layout
Interface for CPU tensor.
unsigned int validation_range_end
Copyright (c) 2017-2021 Arm Limited.
std::unique_ptr< graph::ITensorAccessor > get_random_accessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed=0)
Generates appropriate random accessor.
void permute(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes given Dimensions according to a permutation vector.
bool endswith(const std::string &str, const std::string &suffix)
Checks if a string contains a given suffix.
virtual void preprocess(ITensor &tensor)=0
Preprocess the given tensor.
Numpy Binary loader class.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
library fill(src, distribution, 0)
std::string validation_file
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Basic implementation of the tensor interface.
void end(TokenStream &in, bool &valid)
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
Num samples, channels, height, width.
Tensor accessor interface.
TensorShape permute_shape(TensorShape tensor_shape, DataLayout in_data_layout, DataLayout out_data_layout)
Permutes a given tensor shape given the input and output data layout.
virtual ~IPreprocessor()=default
Default destructor.
Strides of an item in bytes.
Structure holding all the common graph parameters.
std::unique_ptr< graph::ITensorAccessor > get_output_accessor(const arm_compute::utils::CommonGraphParams &graph_parameters, size_t top_n=5, bool is_validation=false, std::ostream &output_stream=std::cout)
Generates appropriate output accessor according to the specified graph parameters.
std::unique_ptr< graph::ITensorAccessor > get_weights_accessor(const std::string &path, const std::string &data_file, DataLayout file_layout=DataLayout::NCHW)
Generates appropriate weights accessor according to the specified path.
Detection output accessor class.
DataType
Available data types.
OpenCL capable target device.
DataLayout
[DataLayout enum definition]
Output Accessor used for network validation.