24.02.1
|
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;
162 std::ostream &output_stream = std::cout);
174 template <
typename T>
178 const std::string _filename;
179 std::ostream &_output_stream;
203 const std::string _npy_name;
204 const bool _is_fortran;
230 std::ostream &_output_stream;
244 ImageAccessor(std::string filename,
bool bgr =
true, std::unique_ptr<IPreprocessor> preprocessor =
nullptr);
252 bool _already_loaded;
253 const std::string _filename;
255 std::unique_ptr<IPreprocessor> _preprocessor;
275 std::string images_path,
276 std::unique_ptr<IPreprocessor> preprocessor =
nullptr,
278 unsigned int start = 0,
279 unsigned int end = 0,
280 std::ostream &output_stream = std::cout);
287 std::vector<std::string> _images;
288 std::unique_ptr<IPreprocessor> _preprocessor;
291 std::ostream &_output_stream;
308 std::ostream &output_stream = std::cout,
309 unsigned int start = 0,
310 unsigned int end = 0);
324 template <
typename T>
325 std::vector<size_t> access_predictions_tensor(
ITensor &
tensor);
333 void aggregate_sample(
const std::vector<size_t> &res,
size_t &positive_samples,
size_t top_n,
size_t correct_label);
340 void report_top_n(
size_t top_n,
size_t total_samples,
size_t positive_samples);
343 std::vector<int> _results;
344 std::ostream &_output_stream;
346 size_t _positive_samples_top1;
347 size_t _positive_samples_top5;
361 std::vector<TensorShape> &imgs_tensor_shapes,
362 std::ostream &output_stream = std::cout);
374 template <
typename T>
377 std::vector<std::string> _labels;
378 std::vector<TensorShape> _tensor_shapes;
379 std::ostream &_output_stream;
392 TopNPredictionsAccessor(
const std::string &labels_path,
size_t top_n = 5, std::ostream &output_stream = std::cout);
404 template <
typename T>
407 std::vector<std::string> _labels;
408 std::ostream &_output_stream;
430 template <
typename T,
typename D>
434 std::random_device::result_type _seed;
454 bool _already_loaded;
455 const std::string _filename;
467 inline std::unique_ptr<graph::ITensorAccessor>
470 return std::make_unique<RandomAccessor>(lower, upper, seed);
483 inline std::unique_ptr<graph::ITensorAccessor>
488 return std::make_unique<DummyAccessor>();
492 return std::make_unique<NumPyBinLoader>(
path + data_file, file_layout);
504 inline std::unique_ptr<graph::ITensorAccessor>
506 std::unique_ptr<IPreprocessor> preprocessor =
nullptr,
511 return std::make_unique<ValidationInputAccessor>(
517 const std::string &image_file = graph_parameters.
image;
518 const std::string &image_file_lower =
lower_string(image_file);
521 return std::make_unique<NumPyBinLoader>(image_file, graph_parameters.
data_layout);
527 return std::make_unique<ImageAccessor>(image_file, bgr, std::move(preprocessor));
531 return std::make_unique<DummyAccessor>();
548 inline std::unique_ptr<graph::ITensorAccessor>
551 bool is_validation =
false,
552 std::ostream &output_stream = std::cout)
557 return std::make_unique<ValidationOutputAccessor>(graph_parameters.
validation_file, output_stream,
561 else if (graph_parameters.
labels.empty())
563 return std::make_unique<DummyAccessor>(0);
567 return std::make_unique<TopNPredictionsAccessor>(graph_parameters.
labels, top_n, output_stream);
582 inline std::unique_ptr<graph::ITensorAccessor>
584 std::vector<TensorShape> tensor_shapes,
585 bool is_validation =
false,
586 std::ostream &output_stream = std::cout)
591 return std::make_unique<ValidationOutputAccessor>(graph_parameters.
validation_file, output_stream,
595 else if (graph_parameters.
labels.empty())
597 return std::make_unique<DummyAccessor>(0);
601 return std::make_unique<DetectionOutputAccessor>(graph_parameters.
labels, tensor_shapes, output_stream);
620 std::ostream &output_stream = std::cout)
622 if (npy_path.empty())
624 return std::make_unique<DummyAccessor>(0);
642 const bool is_fortran =
false)
644 if (npy_name.empty())
646 return std::make_unique<DummyAccessor>(0);
650 return std::make_unique<SaveNumPyAccessor>(npy_name, is_fortran);
662 return std::make_unique<PrintAccessor>(output_stream);
675 if (in_data_layout != out_data_layout)
694 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
CaffePreproccessor(std::array< float, 3 > mean=std::array< float, 3 >{{0, 0, 0}}, bool bgr=true, float scale=1.f)
Default Constructor.
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.
constexpr auto data_layout
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-2024 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)
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