Compute Library
 23.11
arm_compute::graph_utils Namespace Reference

Data Structures

class  CaffePreproccessor
 Caffe preproccessor. More...
 
class  DetectionOutputAccessor
 Detection output accessor class. More...
 
class  DummyAccessor
 Dummy accessor class. More...
 
class  ImageAccessor
 Image accessor class. More...
 
class  IPreprocessor
 Preprocessor interface. More...
 
class  NumPyAccessor
 NumPy accessor class. More...
 
class  NumPyBinLoader
 Numpy Binary loader class. More...
 
class  PPMWriter
 PPM writer class. More...
 
class  PrintAccessor
 Print accessor class. More...
 
class  RandomAccessor
 Random accessor class. More...
 
class  SaveNumPyAccessor
 SaveNumPy accessor class. More...
 
class  TFPreproccessor
 TF preproccessor. More...
 
class  TopNPredictionsAccessor
 Result accessor class. More...
 
class  ValidationInputAccessor
 Input Accessor used for network validation. More...
 
class  ValidationOutputAccessor
 Output Accessor used for network validation. More...
 

Functions

std::unique_ptr< graph::ITensorAccessorget_random_accessor (PixelValue lower, PixelValue upper, const std::random_device::result_type seed=0)
 Generates appropriate random accessor. More...
 
std::unique_ptr< graph::ITensorAccessorget_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. More...
 
std::unique_ptr< graph::ITensorAccessorget_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. More...
 
std::unique_ptr< graph::ITensorAccessorget_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. More...
 
std::unique_ptr< graph::ITensorAccessorget_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. More...
 
std::unique_ptr< graph::ITensorAccessorget_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. More...
 
std::unique_ptr< graph::ITensorAccessorget_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. More...
 
std::unique_ptr< graph::ITensorAccessorget_print_output_accessor (std::ostream &output_stream=std::cout)
 Generates print tensor accessor. More...
 
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. More...
 
graph::Target set_target_hint (int target)
 Utility function to return the TargetHint. More...
 

Function Documentation

◆ get_detection_output_accessor()

std::unique_ptr<graph::ITensorAccessor> arm_compute::graph_utils::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 
)
inline

Generates appropriate output accessor according to the specified graph parameters.

Note
If the output accessor is requested to validate the graph then ValidationOutputAccessor is generated else if output_accessor_file is empty will generate a DummyAccessor else will generate a TopNPredictionsAccessor
Parameters
[in]graph_parametersGraph parameters
[in]tensor_shapesNetwork input images tensor shapes.
[in]is_validation(Optional) Validation flag (default = false)
[out]output_stream(Optional) Output stream (default = std::cout)
Returns
An appropriate tensor accessor

Definition at line 583 of file GraphUtils.h.

587 {
588  ARM_COMPUTE_UNUSED(is_validation);
589  if (!graph_parameters.validation_file.empty())
590  {
591  return std::make_unique<ValidationOutputAccessor>(graph_parameters.validation_file, output_stream,
592  graph_parameters.validation_range_start,
593  graph_parameters.validation_range_end);
594  }
595  else if (graph_parameters.labels.empty())
596  {
597  return std::make_unique<DummyAccessor>(0);
598  }
599  else
600  {
601  return std::make_unique<DetectionOutputAccessor>(graph_parameters.labels, tensor_shapes, output_stream);
602  }
603 }

References ARM_COMPUTE_UNUSED, CommonGraphParams::labels, CommonGraphParams::validation_file, CommonGraphParams::validation_range_end, and CommonGraphParams::validation_range_start.

◆ get_input_accessor()

std::unique_ptr<graph::ITensorAccessor> arm_compute::graph_utils::get_input_accessor ( const arm_compute::utils::CommonGraphParams graph_parameters,
std::unique_ptr< IPreprocessor preprocessor = nullptr,
bool  bgr = true 
)
inline

Generates appropriate input accessor according to the specified graph parameters.

Parameters
[in]graph_parametersGraph parameters
[in]preprocessor(Optional) Preproccessor object
[in]bgr(Optional) Fill the first plane with blue channel (default = true)
Returns
An appropriate tensor accessor

Definition at line 505 of file GraphUtils.h.

508 {
509  if (!graph_parameters.validation_file.empty())
510  {
511  return std::make_unique<ValidationInputAccessor>(
512  graph_parameters.validation_file, graph_parameters.validation_path, std::move(preprocessor), bgr,
513  graph_parameters.validation_range_start, graph_parameters.validation_range_end);
514  }
515  else
516  {
517  const std::string &image_file = graph_parameters.image;
518  const std::string &image_file_lower = lower_string(image_file);
519  if (arm_compute::utility::endswith(image_file_lower, ".npy"))
520  {
521  return std::make_unique<NumPyBinLoader>(image_file, graph_parameters.data_layout);
522  }
523  else if (arm_compute::utility::endswith(image_file_lower, ".jpeg") ||
524  arm_compute::utility::endswith(image_file_lower, ".jpg") ||
525  arm_compute::utility::endswith(image_file_lower, ".ppm"))
526  {
527  return std::make_unique<ImageAccessor>(image_file, bgr, std::move(preprocessor));
528  }
529  else
530  {
531  return std::make_unique<DummyAccessor>();
532  }
533  }
534 }

References CommonGraphParams::data_layout, arm_compute::utility::endswith(), CommonGraphParams::image, arm_compute::lower_string(), CommonGraphParams::validation_file, CommonGraphParams::validation_path, CommonGraphParams::validation_range_end, and CommonGraphParams::validation_range_start.

Referenced by GraphEdsr::setup().

◆ get_npy_output_accessor()

std::unique_ptr<graph::ITensorAccessor> arm_compute::graph_utils::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 
)
inline

Generates appropriate npy output accessor according to the specified npy_path.

Note
If npy_path is empty will generate a DummyAccessor else will generate a NpyAccessor
Parameters
[in]npy_pathPath to npy file.
[in]shapeShape of the numpy tensor data.
[in]data_typeDataType of the numpy tensor data.
[in]data_layoutDataLayout of the numpy tensor data.
[out]output_stream(Optional) Output stream
Returns
An appropriate tensor accessor

Definition at line 616 of file GraphUtils.h.

621 {
622  if (npy_path.empty())
623  {
624  return std::make_unique<DummyAccessor>(0);
625  }
626  else
627  {
628  return std::make_unique<NumPyAccessor>(npy_path, shape, data_type, data_layout, output_stream);
629  }
630 }

References arm_compute::cpu::data_layout, arm_compute::test::validation::data_type, and arm_compute::test::validation::shape.

Referenced by GraphEdsr::setup().

◆ get_output_accessor()

std::unique_ptr<graph::ITensorAccessor> arm_compute::graph_utils::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 
)
inline

Generates appropriate output accessor according to the specified graph parameters.

Note
If the output accessor is requested to validate the graph then ValidationOutputAccessor is generated else if output_accessor_file is empty will generate a DummyAccessor else will generate a TopNPredictionsAccessor
Parameters
[in]graph_parametersGraph parameters
[in]top_n(Optional) Number of output classes to print (default = 5)
[in]is_validation(Optional) Validation flag (default = false)
[out]output_stream(Optional) Output stream (default = std::cout)
Returns
An appropriate tensor accessor

Definition at line 549 of file GraphUtils.h.

553 {
554  ARM_COMPUTE_UNUSED(is_validation);
555  if (!graph_parameters.validation_file.empty())
556  {
557  return std::make_unique<ValidationOutputAccessor>(graph_parameters.validation_file, output_stream,
558  graph_parameters.validation_range_start,
559  graph_parameters.validation_range_end);
560  }
561  else if (graph_parameters.labels.empty())
562  {
563  return std::make_unique<DummyAccessor>(0);
564  }
565  else
566  {
567  return std::make_unique<TopNPredictionsAccessor>(graph_parameters.labels, top_n, output_stream);
568  }
569 }

References ARM_COMPUTE_UNUSED, CommonGraphParams::labels, CommonGraphParams::validation_file, CommonGraphParams::validation_range_end, and CommonGraphParams::validation_range_start.

◆ get_print_output_accessor()

std::unique_ptr<graph::ITensorAccessor> arm_compute::graph_utils::get_print_output_accessor ( std::ostream &  output_stream = std::cout)
inline

Generates print tensor accessor.

Parameters
[out]output_stream(Optional) Output stream
Returns
A print tensor accessor

Definition at line 660 of file GraphUtils.h.

661 {
662  return std::make_unique<PrintAccessor>(output_stream);
663 }

◆ get_random_accessor()

std::unique_ptr<graph::ITensorAccessor> arm_compute::graph_utils::get_random_accessor ( PixelValue  lower,
PixelValue  upper,
const std::random_device::result_type  seed = 0 
)
inline

Generates appropriate random accessor.

Parameters
[in]lowerLower random values bound
[in]upperUpper random values bound
[in]seedRandom generator seed
Returns
A ramdom accessor

Definition at line 468 of file GraphUtils.h.

469 {
470  return std::make_unique<RandomAccessor>(lower, upper, seed);
471 }

◆ get_save_npy_output_accessor()

std::unique_ptr<graph::ITensorAccessor> arm_compute::graph_utils::get_save_npy_output_accessor ( const std::string &  npy_name,
const bool  is_fortran = false 
)
inline

Generates appropriate npy output accessor according to the specified npy_path.

Note
If npy_path is empty will generate a DummyAccessor else will generate a SaveNpyAccessor
Parameters
[in]npy_nameNpy filename.
[in]is_fortran(Optional) If true, save tensor in fortran order.
Returns
An appropriate tensor accessor

Definition at line 641 of file GraphUtils.h.

643 {
644  if (npy_name.empty())
645  {
646  return std::make_unique<DummyAccessor>(0);
647  }
648  else
649  {
650  return std::make_unique<SaveNumPyAccessor>(npy_name, is_fortran);
651  }
652 }

◆ get_weights_accessor()

std::unique_ptr<graph::ITensorAccessor> arm_compute::graph_utils::get_weights_accessor ( const std::string &  path,
const std::string &  data_file,
DataLayout  file_layout = DataLayout::NCHW 
)
inline

Generates appropriate weights accessor according to the specified path.

Note
If path is empty will generate a DummyAccessor else will generate a NumPyBinLoader
Parameters
[in]pathPath to the data files
[in]data_fileRelative path to the data files from path
[in]file_layout(Optional) Layout of file. Defaults to NCHW
Returns
An appropriate tensor accessor

Definition at line 484 of file GraphUtils.h.

485 {
486  if (path.empty())
487  {
488  return std::make_unique<DummyAccessor>();
489  }
490  else
491  {
492  return std::make_unique<NumPyBinLoader>(path + data_file, file_layout);
493  }
494 }

References add_copyright::path.

Referenced by GraphEdsr::setup().

◆ permute_shape()

TensorShape arm_compute::graph_utils::permute_shape ( TensorShape  tensor_shape,
DataLayout  in_data_layout,
DataLayout  out_data_layout 
)
inline

Permutes a given tensor shape given the input and output data layout.

Parameters
[in]tensor_shapeTensor shape to permute
[in]in_data_layoutInput tensor shape data layout
[in]out_data_layoutOutput tensor shape data layout
Returns
Permuted tensor shape

Definition at line 673 of file GraphUtils.h.

674 {
675  if (in_data_layout != out_data_layout)
676  {
677  arm_compute::PermutationVector perm_vec = (in_data_layout == DataLayout::NCHW)
680  arm_compute::permute(tensor_shape, perm_vec);
681  }
682  return tensor_shape;
683 }

References arm_compute::NCHW, arm_compute::permute(), and arm_compute::utils::cast::U.

Referenced by GraphValidateExample< DepthwiseConvolutionLayer, DepthConvolutionOptions, DepthConvolutionVerifyAccessor >::do_setup(), and VerifyAccessor< D >::output_shape().

◆ set_target_hint()

graph::Target arm_compute::graph_utils::set_target_hint ( int  target)
inline

Utility function to return the TargetHint.

Parameters
[in]targetInteger value which expresses the selected target. Must be 0 for Arm® Neon™ or 1 for OpenCL or 2 (OpenCL with Tuner)
Returns
the TargetHint

Definition at line 691 of file GraphUtils.h.

692 {
693  ARM_COMPUTE_ERROR_ON_MSG(target > 2, "Invalid target. Target must be 0 (NEON), 1 (OpenCL), 2 (OpenCL + Tuner)");
694  if ((target == 1 || target == 2))
695  {
696  return graph::Target::CL;
697  }
698  else
699  {
700  return graph::Target::NEON;
701  }
702 }

References ARM_COMPUTE_ERROR_ON_MSG, arm_compute::graph::CL, and arm_compute::graph::NEON.

arm_compute::lower_string
std::string lower_string(const std::string &val)
Lower a given string.
Definition: StringUtils.cpp:38
arm_compute::utils::CommonGraphParams::validation_range_end
unsigned int validation_range_end
Definition: CommonGraphOptions.h:113
arm_compute::permute
void permute(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes given Dimensions according to a permutation vector.
Definition: Helpers.h:144
arm_compute::utils::CommonGraphParams::validation_range_start
unsigned int validation_range_start
Definition: CommonGraphOptions.h:112
arm_compute::cpu::data_layout
constexpr auto data_layout
Definition: impl.h:36
arm_compute::Strides
Strides of an item in bytes.
Definition: Strides.h:38
arm_compute::utils::CommonGraphParams::data_layout
arm_compute::DataLayout data_layout
Definition: CommonGraphOptions.h:100
arm_compute::utils::cast::U
U
Definition: SaturateCast.h:65
arm_compute::PermutationVector
Strides PermutationVector
Permutation vector.
Definition: CoreTypes.h:38
arm_compute::test::validation::shape
shape
Definition: DFT.cpp:115
arm_compute::utility::endswith
bool endswith(const std::string &str, const std::string &suffix)
Checks if a string contains a given suffix.
Definition: Utility.h:177
ARM_COMPUTE_ERROR_ON_MSG
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
ARM_COMPUTE_UNUSED
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:151
arm_compute::utils::CommonGraphParams::validation_file
std::string validation_file
Definition: CommonGraphOptions.h:108
arm_compute::test::validation::data_type
data_type
Definition: Cast.cpp:222
arm_compute::utils::CommonGraphParams::image
std::string image
Definition: CommonGraphOptions.h:106
arm_compute::utils::CommonGraphParams::labels
std::string labels
Definition: CommonGraphOptions.h:107
arm_compute::utils::CommonGraphParams::validation_path
std::string validation_path
Definition: CommonGraphOptions.h:109