Compute Library
 21.08
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 577 of file GraphUtils.h.

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

581 {
582  ARM_COMPUTE_UNUSED(is_validation);
583  if(!graph_parameters.validation_file.empty())
584  {
585  return std::make_unique<ValidationOutputAccessor>(graph_parameters.validation_file,
586  output_stream,
587  graph_parameters.validation_range_start,
588  graph_parameters.validation_range_end);
589  }
590  else if(graph_parameters.labels.empty())
591  {
592  return std::make_unique<DummyAccessor>(0);
593  }
594  else
595  {
596  return std::make_unique<DetectionOutputAccessor>(graph_parameters.labels, tensor_shapes, output_stream);
597  }
598 }
#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 497 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().

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

613 {
614  if(npy_path.empty())
615  {
616  return std::make_unique<DummyAccessor>(0);
617  }
618  else
619  {
620  return std::make_unique<NumPyAccessor>(npy_path, shape, data_type, data_layout, output_stream);
621  }
622 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
const DataType data_type
Definition: Im2Col.cpp:150

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

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

547 {
548  ARM_COMPUTE_UNUSED(is_validation);
549  if(!graph_parameters.validation_file.empty())
550  {
551  return std::make_unique<ValidationOutputAccessor>(graph_parameters.validation_file,
552  output_stream,
553  graph_parameters.validation_range_start,
554  graph_parameters.validation_range_end);
555  }
556  else if(graph_parameters.labels.empty())
557  {
558  return std::make_unique<DummyAccessor>(0);
559  }
560  else
561  {
562  return std::make_unique<TopNPredictionsAccessor>(graph_parameters.labels, top_n, output_stream);
563  }
564 }
#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 651 of file GraphUtils.h.

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

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

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

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

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

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

Referenced by GraphEdsr::setup().

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

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

665 {
666  if(in_data_layout != out_data_layout)
667  {
668  arm_compute::PermutationVector perm_vec = (in_data_layout == DataLayout::NCHW) ? arm_compute::PermutationVector(2U, 0U, 1U) : arm_compute::PermutationVector(1U, 2U, 0U);
669  arm_compute::permute(tensor_shape, perm_vec);
670  }
671  return tensor_shape;
672 }
Strides PermutationVector
Permutation vector.
Definition: Types.h:49
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 680 of file GraphUtils.h.

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

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