Compute Library
 22.05
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 578 of file GraphUtils.h.

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

582 {
583  ARM_COMPUTE_UNUSED(is_validation);
584  if(!graph_parameters.validation_file.empty())
585  {
586  return std::make_unique<ValidationOutputAccessor>(graph_parameters.validation_file,
587  output_stream,
588  graph_parameters.validation_range_start,
589  graph_parameters.validation_range_end);
590  }
591  else if(graph_parameters.labels.empty())
592  {
593  return std::make_unique<DummyAccessor>(0);
594  }
595  else
596  {
597  return std::make_unique<DetectionOutputAccessor>(graph_parameters.labels, tensor_shapes, output_stream);
598  }
599 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ 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 498 of file GraphUtils.h.

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().

501 {
502  if(!graph_parameters.validation_file.empty())
503  {
504  return std::make_unique<ValidationInputAccessor>(graph_parameters.validation_file,
505  graph_parameters.validation_path,
506  std::move(preprocessor),
507  bgr,
508  graph_parameters.validation_range_start,
509  graph_parameters.validation_range_end);
510  }
511  else
512  {
513  const std::string &image_file = graph_parameters.image;
514  const std::string &image_file_lower = lower_string(image_file);
515  if(arm_compute::utility::endswith(image_file_lower, ".npy"))
516  {
517  return std::make_unique<NumPyBinLoader>(image_file, graph_parameters.data_layout);
518  }
519  else if(arm_compute::utility::endswith(image_file_lower, ".jpeg")
520  || arm_compute::utility::endswith(image_file_lower, ".jpg")
521  || arm_compute::utility::endswith(image_file_lower, ".ppm"))
522  {
523  return std::make_unique<ImageAccessor>(image_file, bgr, std::move(preprocessor));
524  }
525  else
526  {
527  return std::make_unique<DummyAccessor>();
528  }
529  }
530 }
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:351
bool endswith(const std::string &str, const std::string &suffix)
Checks if a string contains a given suffix.
Definition: Utility.h:178

◆ 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 612 of file GraphUtils.h.

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

Referenced by GraphEdsr::setup().

614 {
615  if(npy_path.empty())
616  {
617  return std::make_unique<DummyAccessor>(0);
618  }
619  else
620  {
621  return std::make_unique<NumPyAccessor>(npy_path, shape, data_type, data_layout, output_stream);
622  }
623 }

◆ 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 544 of file GraphUtils.h.

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

548 {
549  ARM_COMPUTE_UNUSED(is_validation);
550  if(!graph_parameters.validation_file.empty())
551  {
552  return std::make_unique<ValidationOutputAccessor>(graph_parameters.validation_file,
553  output_stream,
554  graph_parameters.validation_range_start,
555  graph_parameters.validation_range_end);
556  }
557  else if(graph_parameters.labels.empty())
558  {
559  return std::make_unique<DummyAccessor>(0);
560  }
561  else
562  {
563  return std::make_unique<TopNPredictionsAccessor>(graph_parameters.labels, top_n, output_stream);
564  }
565 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ 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 652 of file GraphUtils.h.

653 {
654  return std::make_unique<PrintAccessor>(output_stream);
655 }

◆ 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 461 of file GraphUtils.h.

462 {
463  return std::make_unique<RandomAccessor>(lower, upper, seed);
464 }

◆ 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 634 of file GraphUtils.h.

635 {
636  if(npy_name.empty())
637  {
638  return std::make_unique<DummyAccessor>(0);
639  }
640  else
641  {
642  return std::make_unique<SaveNumPyAccessor>(npy_name, is_fortran);
643  }
644 }

◆ 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 476 of file GraphUtils.h.

Referenced by GraphEdsr::setup().

479 {
480  if(path.empty())
481  {
482  return std::make_unique<DummyAccessor>();
483  }
484  else
485  {
486  return std::make_unique<NumPyBinLoader>(path + data_file, file_layout);
487  }
488 }

◆ 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 665 of file GraphUtils.h.

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().

666 {
667  if(in_data_layout != out_data_layout)
668  {
669  arm_compute::PermutationVector perm_vec = (in_data_layout == DataLayout::NCHW) ? arm_compute::PermutationVector(2U, 0U, 1U) : arm_compute::PermutationVector(1U, 2U, 0U);
670  arm_compute::permute(tensor_shape, perm_vec);
671  }
672  return tensor_shape;
673 }
Strides PermutationVector
Permutation vector.
Definition: Types.h:51
void permute(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes given Dimensions according to a permutation vector.
Definition: Helpers.h:125
Strides of an item in bytes.
Definition: Strides.h:37

◆ 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 681 of file GraphUtils.h.

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

682 {
683  ARM_COMPUTE_ERROR_ON_MSG(target > 2, "Invalid target. Target must be 0 (NEON), 1 (OpenCL), 2 (OpenCL + Tuner)");
684  if((target == 1 || target == 2))
685  {
686  return graph::Target::CL;
687  }
688  else
689  {
690  return graph::Target::NEON;
691  }
692 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456