23.08
|
Go to the documentation of this file.
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);
76 std::array<float, 3> _mean;
120 const std::string _name;
121 unsigned int _iterator;
122 unsigned int _maximum;
142 unsigned int _iterator;
143 unsigned int _maximum;
170 template <
typename T>
174 const std::string _filename;
175 std::ostream &_output_stream;
199 const std::string _npy_name;
200 const bool _is_fortran;
226 std::ostream &_output_stream;
240 ImageAccessor(std::string filename,
bool bgr =
true, std::unique_ptr<IPreprocessor> preprocessor =
nullptr);
248 bool _already_loaded;
249 const std::string _filename;
251 std::unique_ptr<IPreprocessor> _preprocessor;
271 std::string images_path,
272 std::unique_ptr<IPreprocessor> preprocessor =
nullptr,
274 unsigned int start = 0,
275 unsigned int end = 0,
276 std::ostream &output_stream = std::cout);
283 std::vector<std::string> _images;
284 std::unique_ptr<IPreprocessor> _preprocessor;
287 std::ostream &_output_stream;
304 std::ostream &output_stream = std::cout,
305 unsigned int start = 0,
306 unsigned int end = 0);
320 template <
typename T>
321 std::vector<size_t> access_predictions_tensor(
ITensor &
tensor);
329 void aggregate_sample(
const std::vector<size_t> &res,
size_t &positive_samples,
size_t top_n,
size_t correct_label);
336 void report_top_n(
size_t top_n,
size_t total_samples,
size_t positive_samples);
339 std::vector<int> _results;
340 std::ostream &_output_stream;
342 size_t _positive_samples_top1;
343 size_t _positive_samples_top5;
356 DetectionOutputAccessor(
const std::string &labels_path, std::vector<TensorShape> &imgs_tensor_shapes, std::ostream &output_stream = std::cout);
368 template <
typename T>
371 std::vector<std::string> _labels;
372 std::vector<TensorShape> _tensor_shapes;
373 std::ostream &_output_stream;
386 TopNPredictionsAccessor(
const std::string &labels_path,
size_t top_n = 5, std::ostream &output_stream = std::cout);
398 template <
typename T>
401 std::vector<std::string> _labels;
402 std::ostream &_output_stream;
424 template <
typename T,
typename D>
428 std::random_device::result_type _seed;
448 bool _already_loaded;
449 const std::string _filename;
463 return std::make_unique<RandomAccessor>(lower, upper, seed);
477 const std::string &data_file,
482 return std::make_unique<DummyAccessor>();
486 return std::make_unique<NumPyBinLoader>(
path + data_file, file_layout);
499 std::unique_ptr<IPreprocessor> preprocessor =
nullptr,
504 return std::make_unique<ValidationInputAccessor>(graph_parameters.
validation_file,
506 std::move(preprocessor),
513 const std::string &image_file = graph_parameters.
image;
514 const std::string &image_file_lower =
lower_string(image_file);
517 return std::make_unique<NumPyBinLoader>(image_file, graph_parameters.
data_layout);
523 return std::make_unique<ImageAccessor>(image_file, bgr, std::move(preprocessor));
527 return std::make_unique<DummyAccessor>();
546 bool is_validation =
false,
547 std::ostream &output_stream = std::cout)
552 return std::make_unique<ValidationOutputAccessor>(graph_parameters.
validation_file,
557 else if(graph_parameters.
labels.empty())
559 return std::make_unique<DummyAccessor>(0);
563 return std::make_unique<TopNPredictionsAccessor>(graph_parameters.
labels, top_n, output_stream);
579 std::vector<TensorShape> tensor_shapes,
580 bool is_validation =
false,
581 std::ostream &output_stream = std::cout)
586 return std::make_unique<ValidationOutputAccessor>(graph_parameters.
validation_file,
591 else if(graph_parameters.
labels.empty())
593 return std::make_unique<DummyAccessor>(0);
597 return std::make_unique<DetectionOutputAccessor>(graph_parameters.
labels, tensor_shapes, output_stream);
613 std::ostream &output_stream = std::cout)
617 return std::make_unique<DummyAccessor>(0);
638 return std::make_unique<DummyAccessor>(0);
642 return std::make_unique<SaveNumPyAccessor>(npy_name, is_fortran);
654 return std::make_unique<PrintAccessor>(output_stream);
667 if(in_data_layout != out_data_layout)
684 if((target == 1 || target == 2))
@ NCHW
Num samples, channels, height, width.
SaveNumPy accessor class.
PrintAccessor(std::ostream &output_stream=std::cout, IOFormatInfo io_fmt=IOFormatInfo())
Constructor.
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.
NumPyAccessor & operator=(const NumPyAccessor &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
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.
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.
@ CL
OpenCL capable target device.
Class describing the value of a pixel for any image format.
DataLayout
[DataLayout enum definition]
void reset()
Reset accessor state.
std::unique_ptr< graph::ITensorAccessor > get_print_output_accessor(std::ostream &output_stream=std::cout)
Generates print tensor accessor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
std::string lower_string(const std::string &val)
Lower a given string.
SaveNumPyAccessor(const std::string npy_name, const bool is_fortran=false)
Constructor.
@ NEON
Arm® Neon™ capable target device.
TFPreproccessor(float min_range=-1.f, float max_range=1.f)
Constructor.
ValidationOutputAccessor(const std::string &image_list, std::ostream &output_stream=std::cout, unsigned int start=0, unsigned int end=0)
Default Constructor.
Numpy Binary loader class.
unsigned int validation_range_end
SaveNumPyAccessor & operator=(const SaveNumPyAccessor &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
void preprocess(ITensor &tensor) override
Preprocess the given tensor.
NumPyBinLoader(std::string filename, DataLayout file_layout=DataLayout::NCHW)
Default Constructor.
void permute(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes given Dimensions according to a permutation vector.
unsigned int validation_range_start
Interface for CPU tensor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
Strides of an item in bytes.
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.
arm_compute::DataLayout data_layout
DetectionOutputAccessor(const std::string &labels_path, std::vector< TensorShape > &imgs_tensor_shapes, std::ostream &output_stream=std::cout)
Constructor.
Strides PermutationVector
Permutation vector.
bool endswith(const std::string &str, const std::string &suffix)
Checks if a string contains a given suffix.
TopNPredictionsAccessor(const std::string &labels_path, size_t top_n=5, std::ostream &output_stream=std::cout)
Constructor.
DetectionOutputAccessor & operator=(const DetectionOutputAccessor &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
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.
PPMWriter(std::string name, unsigned int maximum=1)
Constructor.
bool access_tensor_data() override
Returns true if the tensor data is being accessed.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
std::string validation_file
CLTensor * tensor
Pointer to the auxiliary tensor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
Tensor accessor interface.
virtual void preprocess(ITensor &tensor)=0
Preprocess the given tensor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
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.
NumPyAccessor(std::string npy_path, TensorShape shape, DataType data_type, DataLayout data_layout=DataLayout::NCHW, std::ostream &output_stream=std::cout)
Constructor.
void preprocess(ITensor &tensor) override
Preprocess the given tensor.
Copyright (c) 2017-2023 Arm Limited.
RandomAccessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed=0)
Constructor.
Output Accessor used for network validation.
graph::Target set_target_hint(int target)
Utility function to return the TargetHint.
std::unique_ptr< graph::ITensorAccessor > get_random_accessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed=0)
Generates appropriate random accessor.
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
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.
void end(TokenStream &in, bool &valid)
PrintAccessor & operator=(const PrintAccessor &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
Basic implementation of the tensor interface.
Detection output accessor class.
TopNPredictionsAccessor & operator=(const TopNPredictionsAccessor &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
CaffePreproccessor(std::array< float, 3 > mean=std::array< float, 3 > { { 0, 0, 0 } }, bool bgr=true, float scale=1.f)
Default Constructor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
Structure holding all the common graph parameters.
DummyAccessor(unsigned int maximum=1)
Constructor.
bool access_tensor(ITensor &tensor) override
Interface to be implemented to access a given tensor.
DataType
Available data types.
ImageAccessor(std::string filename, bool bgr=true, std::unique_ptr< IPreprocessor > preprocessor=nullptr)
Constructor.
std::string validation_path