Compute Library
 22.11
AssetsLibrary Class Referencefinal

Factory class to create and fill tensors. More...

#include <AssetsLibrary.h>

Public Types

using RangePair = std::pair< float, float >
 
template<typename ResultType >
using GeneratorFunctionType = std::function< ResultType(void)>
 

Public Member Functions

 AssetsLibrary (std::string path, std::random_device::result_type seed)
 Initialises the library with a path to the assets directory. More...
 
std::string path () const
 Path to assets directory used to initialise library. More...
 
std::random_device::result_type seed () const
 Seed that is used to fill tensors with random values. More...
 
TensorShape get_image_shape (const std::string &name)
 Provides a tensor shape for the specified image. More...
 
const RawTensorget (const std::string &name) const
 Provides a constant raw tensor for the specified image. More...
 
RawTensor get (const std::string &name)
 Provides a raw tensor for the specified image. More...
 
RawTensor get (const std::string &name, DataType data_type, int num_channels=1) const
 Creates an uninitialised raw tensor with the given data_type and num_channels. More...
 
const RawTensorget (const std::string &name, Format format) const
 Provides a contant raw tensor for the specified image after it has been converted to format. More...
 
RawTensor get (const std::string &name, Format format)
 Provides a raw tensor for the specified image after it has been converted to format. More...
 
const RawTensorget (const std::string &name, Channel channel) const
 Provides a contant raw tensor for the specified channel after it has been extracted form the given image. More...
 
RawTensor get (const std::string &name, Channel channel)
 Provides a raw tensor for the specified channel after it has been extracted form the given image. More...
 
const RawTensorget (const std::string &name, Format format, Channel channel) const
 Provides a constant raw tensor for the specified channel after it has been extracted form the given image formatted to format. More...
 
RawTensor get (const std::string &name, Format format, Channel channel)
 Provides a raw tensor for the specified channel after it has been extracted form the given image formatted to format. More...
 
template<typename T , typename D >
void fill_borders_with_garbage (T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
 Puts garbage values all around the tensor for testing purposes. More...
 
template<typename T , typename D >
void fill (T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
 Fills the specified tensor with random values drawn from distribution. More...
 
template<typename T , typename D >
void fill_boxes (T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
 
template<typename T , typename D >
void fill (std::vector< T > &vec, D &&distribution, std::random_device::result_type seed_offset) const
 Fills the specified raw tensor with random values drawn from distribution. More...
 
template<typename D >
void fill (RawTensor &raw, D &&distribution, std::random_device::result_type seed_offset) const
 Fills the specified raw tensor with random values drawn from distribution. More...
 
template<typename T >
void fill (T &&tensor, const std::string &name, Format format) const
 Fills the specified tensor with the content of the specified image converted to the given format. More...
 
void fill (RawTensor &raw, const std::string &name, Format format) const
 Fills the raw tensor with the content of the specified image converted to the given format. More...
 
template<typename T >
void fill (T &&tensor, const std::string &name, Channel channel) const
 Fills the specified tensor with the content of the specified channel extracted from the given image. More...
 
void fill (RawTensor &raw, const std::string &name, Channel channel) const
 Fills the raw tensor with the content of the specified channel extracted from the given image. More...
 
template<typename T >
void fill (T &&tensor, const std::string &name, Format format, Channel channel) const
 Fills the specified tensor with the content of the specified channel extracted from the given image after it has been converted to the given format. More...
 
void fill (RawTensor &raw, const std::string &name, Format format, Channel channel) const
 Fills the raw tensor with the content of the specified channel extracted from the given image after it has been converted to the given format. More...
 
template<typename T >
void fill (T &&tensor, RawTensor raw) const
 Fills the specified tensor with the content of the raw tensor. More...
 
template<typename T >
void fill_tensor_uniform (T &&tensor, std::random_device::result_type seed_offset) const
 Fill a tensor with uniform distribution. More...
 
template<typename T , typename D >
void fill_tensor_uniform (T &&tensor, std::random_device::result_type seed_offset, D low, D high) const
 Fill a tensor with uniform distribution. More...
 
template<typename T >
void fill_tensor_uniform_ranged (T &&tensor, std::random_device::result_type seed_offset, const std::vector< AssetsLibrary::RangePair > &excluded_range_pairs) const
 Fill a tensor with uniform distribution across the specified range. More...
 
template<typename T >
void fill_layer_data (T &&tensor, std::string name) const
 Fills the specified tensor with data loaded from .npy (numpy binary) in specified path. More...
 
template<typename T , typename D >
void fill_tensor_value (T &&tensor, D value) const
 Fill a tensor with a constant value. More...
 
template<typename T , typename DataType >
void fill_static_values (T &&tensor, const std::vector< DataType > &values) const
 Fill a tensor with a given vector with static values. More...
 
template<typename T , typename ResultType >
void fill_with_generator (T &&tensor, const GeneratorFunctionType< ResultType > &generate_value) const
 Fill a tensor with a value generator function. More...
 

Detailed Description

Factory class to create and fill tensors.

Allows to initialise tensors from loaded images or by specifying the shape explicitly. Furthermore, provides methods to fill tensors with the content of loaded images or with random values.

Definition at line 59 of file AssetsLibrary.h.

Member Typedef Documentation

◆ GeneratorFunctionType

using GeneratorFunctionType = std::function<ResultType(void)>

Definition at line 411 of file AssetsLibrary.h.

◆ RangePair

using RangePair = std::pair<float, float>

Definition at line 62 of file AssetsLibrary.h.

Constructor & Destructor Documentation

◆ AssetsLibrary()

AssetsLibrary ( std::string  path,
std::random_device::result_type  seed 
)

Initialises the library with a path to the assets directory.

Furthermore, sets the seed for the random generator to seed.

Parameters
[in]pathPath to load assets from.
[in]seedSeed used to initialise the random number generator.

Definition at line 254 of file AssetsLibrary.cpp.

255  : _library_path(std::move(path)),
256  _seed{ seed }
257 {
258 }
std::string path() const
Path to assets directory used to initialise library.
std::random_device::result_type seed() const
Seed that is used to fill tensors with random values.

Member Function Documentation

◆ fill() [1/10]

void fill ( T &&  tensor,
D &&  distribution,
std::random_device::result_type  seed_offset 
) const

Fills the specified tensor with random values drawn from distribution.

Parameters
[in,out]tensorTo be filled tensor.
[in]distributionDistribution used to fill the tensor.
[in]seed_offsetThe offset will be added to the global seed before initialising the random generator.
Note
The distribution has to provide operator(Generator &) which will be used to draw samples.

Definition at line 622 of file AssetsLibrary.h.

References arm_compute::test::validation::distribution(), AssetsLibrary::fill_borders_with_garbage(), AssetsLibrary::fill_with_generator(), and tensor.

Referenced by arm_compute::test::validation::utils::fill(), AssetsLibrary::fill(), AssetsLibrary::fill_tensor_uniform(), and AssetsLibrary::fill_tensor_uniform_ranged().

623 {
624  using ResultType = typename std::remove_reference<D>::type::result_type;
625  std::mt19937 gen(_seed + seed_offset);
626 
627  GeneratorFunctionType<ResultType> number_generator = [&]()
628  {
629  const ResultType value = distribution(gen);
630  return value;
631  };
632 
633  fill_with_generator(tensor, number_generator);
635 }
void fill_with_generator(T &&tensor, const GeneratorFunctionType< ResultType > &generate_value) const
Fill a tensor with a value generator function.
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
CLTensor * tensor
Pointer to the auxiliary tensor.
void fill_borders_with_garbage(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
Puts garbage values all around the tensor for testing purposes.

◆ fill() [2/10]

void fill ( std::vector< T > &  vec,
D &&  distribution,
std::random_device::result_type  seed_offset 
) const

Fills the specified raw tensor with random values drawn from distribution.

Parameters
[in,out]vecTo be filled vector.
[in]distributionDistribution used to fill the tensor.
[in]seed_offsetThe offset will be added to the global seed before initialising the random generator.
Note
The distribution has to provide operator(Generator &) which will be used to draw samples.

Definition at line 571 of file AssetsLibrary.h.

References ARM_COMPUTE_ERROR_ON_MSG, and arm_compute::test::validation::distribution().

572 {
573  ARM_COMPUTE_ERROR_ON_MSG(vec.empty(), "Vector must not be empty");
574 
575  using ResultType = typename std::remove_reference<D>::type::result_type;
576 
577  std::mt19937 gen(_seed + seed_offset);
578  for(size_t i = 0; i < vec.size(); ++i)
579  {
580  const ResultType value = distribution(gen);
581 
582  vec[i] = value;
583  }
584 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
std::uniform_real_distribution< float > distribution(-5.f, 5.f)

◆ fill() [3/10]

void fill ( RawTensor raw,
D &&  distribution,
std::random_device::result_type  seed_offset 
) const

Fills the specified raw tensor with random values drawn from distribution.

Parameters
[in,out]rawTo be filled raw.
[in]distributionDistribution used to fill the tensor.
[in]seed_offsetThe offset will be added to the global seed before initialising the random generator.
Note
The distribution has to provide operator(Generator &) which will be used to draw samples.

Definition at line 658 of file AssetsLibrary.h.

References SimpleTensor< T >::data(), SimpleTensor< T >::data_type(), arm_compute::test::validation::distribution(), SimpleTensor< T >::element_size(), offset(), SimpleTensor< T >::size(), and arm_compute::test::store_value_with_data_type().

659 {
660  std::mt19937 gen(_seed + seed_offset);
661 
662  for(size_t offset = 0; offset < raw.size(); offset += raw.element_size())
663  {
664  using ResultType = typename std::remove_reference<D>::type::result_type;
665  const ResultType value = distribution(gen);
666 
667  store_value_with_data_type(raw.data() + offset, value, raw.data_type());
668  }
669 }
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1084
void store_value_with_data_type(void *ptr, T value, DataType data_type)
Write the value after casting the pointer according to data_type.
Definition: Utils.h:252
std::uniform_real_distribution< float > distribution(-5.f, 5.f)

◆ fill() [4/10]

void fill ( T &&  tensor,
const std::string &  name,
Format  format 
) const

Fills the specified tensor with the content of the specified image converted to the given format.

Parameters
[in,out]tensorTo be filled tensor.
[in]nameImage file used to fill the tensor.
[in]formatFormat of the image used to fill the tensor.
Warning
No check is performed that the specified format actually matches the format of the tensor.

Definition at line 672 of file AssetsLibrary.h.

References SimpleTensor< T >::data(), SimpleTensor< T >::element_size(), arm_compute::test::index2coord(), name, offset(), SimpleTensor< T >::shape(), SimpleTensor< T >::size(), and tensor.

673 {
674  const RawTensor &raw = get(name, format);
675 
676  for(size_t offset = 0; offset < raw.size(); offset += raw.element_size())
677  {
678  const Coordinates id = index2coord(raw.shape(), offset / raw.element_size());
679 
680  const RawTensor::value_type *const raw_ptr = raw.data() + offset;
681  const auto out_ptr = static_cast<RawTensor::value_type *>(tensor(id));
682  std::copy_n(raw_ptr, raw.element_size(), out_ptr);
683  }
684 }
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1084
uint8_t value_type
Tensor value type.
Definition: SimpleTensor.h:103
const char * name
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Definition: Utils.h:359
CLTensor * tensor
Pointer to the auxiliary tensor.

◆ fill() [5/10]

void fill ( RawTensor raw,
const std::string &  name,
Format  format 
) const

Fills the raw tensor with the content of the specified image converted to the given format.

Parameters
[in,out]rawTo be filled raw tensor.
[in]nameImage file used to fill the tensor.
[in]formatFormat of the image used to fill the tensor.
Warning
No check is performed that the specified format actually matches the format of the tensor.

Definition at line 270 of file AssetsLibrary.cpp.

References SimpleTensor< T >::data(), name, and SimpleTensor< T >::size().

271 {
272  //FIXME: Should be done by swapping cached buffers
273  const RawTensor &src = get(name, format);
274  std::copy_n(src.data(), raw.size(), raw.data());
275 }
SimpleTensor< float > src
Definition: DFT.cpp:155
const char * name

◆ fill() [6/10]

void fill ( T &&  tensor,
const std::string &  name,
Channel  channel 
) const

Fills the specified tensor with the content of the specified channel extracted from the given image.

Parameters
[in,out]tensorTo be filled tensor.
[in]nameImage file used to fill the tensor.
[in]channelChannel of the image used to fill the tensor.
Note
The channel has to be unambiguous so that the format can be inferred automatically.
Warning
No check is performed that the specified format actually matches the format of the tensor.

Definition at line 687 of file AssetsLibrary.h.

References AssetsLibrary::fill(), arm_compute::test::get_format_for_channel(), and tensor.

688 {
689  fill(std::forward<T>(tensor), name, get_format_for_channel(channel), channel);
690 }
Format get_format_for_channel(Channel channel)
Look up the format corresponding to a channel.
Definition: Utils.h:145
void fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
Fills the specified tensor with random values drawn from distribution.
const char * name
CLTensor * tensor
Pointer to the auxiliary tensor.

◆ fill() [7/10]

void fill ( RawTensor raw,
const std::string &  name,
Channel  channel 
) const

Fills the raw tensor with the content of the specified channel extracted from the given image.

Parameters
[in,out]rawTo be filled raw tensor.
[in]nameImage file used to fill the tensor.
[in]channelChannel of the image used to fill the tensor.
Note
The channel has to be unambiguous so that the format can be inferred automatically.
Warning
No check is performed that the specified format actually matches the format of the tensor.

Definition at line 277 of file AssetsLibrary.cpp.

References AssetsLibrary::fill(), and arm_compute::test::get_format_for_channel().

278 {
279  fill(raw, name, get_format_for_channel(channel), channel);
280 }
Format get_format_for_channel(Channel channel)
Look up the format corresponding to a channel.
Definition: Utils.h:145
void fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
Fills the specified tensor with random values drawn from distribution.
const char * name

◆ fill() [8/10]

void fill ( T &&  tensor,
const std::string &  name,
Format  format,
Channel  channel 
) const

Fills the specified tensor with the content of the specified channel extracted from the given image after it has been converted to the given format.

Parameters
[in,out]tensorTo be filled tensor.
[in]nameImage file used to fill the tensor.
[in]formatFormat of the image used to fill the tensor.
[in]channelChannel of the image used to fill the tensor.
Warning
No check is performed that the specified format actually matches the format of the tensor.

Definition at line 693 of file AssetsLibrary.h.

References SimpleTensor< T >::data(), SimpleTensor< T >::element_size(), arm_compute::test::index2coord(), name, offset(), SimpleTensor< T >::shape(), SimpleTensor< T >::size(), and tensor.

694 {
695  const RawTensor &raw = get(name, format, channel);
696 
697  for(size_t offset = 0; offset < raw.size(); offset += raw.element_size())
698  {
699  const Coordinates id = index2coord(raw.shape(), offset / raw.element_size());
700 
701  const RawTensor::value_type *const raw_ptr = raw.data() + offset;
702  const auto out_ptr = static_cast<RawTensor::value_type *>(tensor(id));
703  std::copy_n(raw_ptr, raw.element_size(), out_ptr);
704  }
705 }
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1084
uint8_t value_type
Tensor value type.
Definition: SimpleTensor.h:103
const char * name
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Definition: Utils.h:359
CLTensor * tensor
Pointer to the auxiliary tensor.

◆ fill() [9/10]

void fill ( RawTensor raw,
const std::string &  name,
Format  format,
Channel  channel 
) const

Fills the raw tensor with the content of the specified channel extracted from the given image after it has been converted to the given format.

Parameters
[in,out]rawTo be filled raw tensor.
[in]nameImage file used to fill the tensor.
[in]formatFormat of the image used to fill the tensor.
[in]channelChannel of the image used to fill the tensor.
Warning
No check is performed that the specified format actually matches the format of the tensor.

Definition at line 282 of file AssetsLibrary.cpp.

References TensorCache::add(), arm_compute::B, SimpleTensor< T >::data(), arm_compute::test::validation::dst, TensorCache::find(), SimpleTensor< T >::format(), arm_compute::G, arm_compute::test::get_channel_format(), name, arm_compute::R, arm_compute::RGB888, arm_compute::S16, SimpleTensor< T >::shape(), SimpleTensor< T >::size(), arm_compute::U16, arm_compute::U32, and arm_compute::U8.

283 {
284  const RawTensor &src = get(name, format, channel);
285  std::copy_n(src.data(), raw.size(), raw.data());
286 }
SimpleTensor< float > src
Definition: DFT.cpp:155
const char * name

◆ fill() [10/10]

void fill ( T &&  tensor,
RawTensor  raw 
) const

Fills the specified tensor with the content of the raw tensor.

Parameters
[in,out]tensorTo be filled tensor.
[in]rawRaw tensor used to fill the tensor.
Warning
No check is performed that the specified format actually matches the format of the tensor.

Definition at line 708 of file AssetsLibrary.h.

References SimpleTensor< T >::data(), SimpleTensor< T >::element_size(), arm_compute::test::index2coord(), offset(), SimpleTensor< T >::shape(), SimpleTensor< T >::size(), and tensor.

709 {
710  for(size_t offset = 0; offset < raw.size(); offset += raw.element_size())
711  {
712  const Coordinates id = index2coord(raw.shape(), offset / raw.element_size());
713 
714  const RawTensor::value_type *const raw_ptr = raw.data() + offset;
715  const auto out_ptr = static_cast<RawTensor::value_type *>(tensor(id));
716  std::copy_n(raw_ptr, raw.element_size(), out_ptr);
717  }
718 }
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1084
uint8_t value_type
Tensor value type.
Definition: SimpleTensor.h:103
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Definition: Utils.h:359
CLTensor * tensor
Pointer to the auxiliary tensor.

◆ fill_borders_with_garbage()

void fill_borders_with_garbage ( T &&  tensor,
D &&  distribution,
std::random_device::result_type  seed_offset 
) const

Puts garbage values all around the tensor for testing purposes.

Parameters
[in,out]tensorTo be filled tensor.
[in]distributionDistribution used to fill the tensor's surroundings.
[in]seed_offsetThe offset will be added to the global seed before initialising the random generator.

Definition at line 506 of file AssetsLibrary.h.

References BorderSize::bottom, arm_compute::test::validation::distribution(), arm_compute::execute_window_loop(), BorderSize::left, BorderSize::right, Window::set(), arm_compute::test::validation::shape, arm_compute::test::store_value_with_data_type(), tensor, BorderSize::top, Dimensions< T >::x(), and Dimensions< T >::y().

Referenced by arm_compute::test::validation::utils::fill(), AssetsLibrary::fill(), and AssetsLibrary::fill_boxes().

507 {
508  const PaddingSize padding_size = tensor.padding();
509 
510  Window window;
511  window.set(0, Window::Dimension(-padding_size.left, tensor.shape()[0] + padding_size.right, 1));
512  if(tensor.shape().num_dimensions() > 1)
513  {
514  window.set(1, Window::Dimension(-padding_size.top, tensor.shape()[1] + padding_size.bottom, 1));
515  }
516 
517  std::mt19937 gen(_seed + seed_offset);
518 
519  execute_window_loop(window, [&](const Coordinates & id)
520  {
521  TensorShape shape = tensor.shape();
522 
523  // If outside of valid region
524  if(id.x() < 0 || id.x() >= static_cast<int>(shape.x()) || id.y() < 0 || id.y() >= static_cast<int>(shape.y()))
525  {
526  using ResultType = typename std::remove_reference<D>::type::result_type;
527  const ResultType value = distribution(gen);
528  void *const out_ptr = tensor(id);
529  store_value_with_data_type(out_ptr, value, tensor.data_type());
530  }
531  });
532 }
void store_value_with_data_type(void *ptr, T value, DataType data_type)
Write the value after casting the pointer according to data_type.
Definition: Utils.h:252
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
BorderSize PaddingSize
Container for 2D padding size.
Definition: Types.h:397
CLTensor * tensor
Pointer to the auxiliary tensor.
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Definition: Helpers.inl:77

◆ fill_boxes()

void fill_boxes ( T &&  tensor,
D &&  distribution,
std::random_device::result_type  seed_offset 
) const

Definition at line 535 of file AssetsLibrary.h.

References arm_compute::test::validation::distribution(), arm_compute::quantization::epsilon, AssetsLibrary::fill_borders_with_garbage(), arm_compute::test::index2coord(), arm_compute::test::validation::shape, arm_compute::test::store_value_with_data_type(), tensor, and type.

536 {
537  using DistributionType = typename std::remove_reference<D>::type;
538  using ResultType = typename DistributionType::result_type;
539 
540  std::mt19937 gen(_seed + seed_offset);
541  TensorShape shape(tensor.shape());
542  const uint32_t num_boxes = tensor.num_elements() / 4;
543  // Iterate over all elements
544  DistributionType size_dist{ ResultType(0.f), ResultType(1.f) };
545  for(uint32_t element_idx = 0; element_idx < num_boxes * 4; element_idx += 4)
546  {
547  const ResultType delta = size_dist(gen);
548  const ResultType epsilon = size_dist(gen);
549  const ResultType left = distribution(gen);
550  const ResultType top = distribution(gen);
551  const ResultType right = left + delta;
552  const ResultType bottom = top + epsilon;
553  const std::tuple<ResultType, ResultType, ResultType, ResultType> box(left, top, right, bottom);
554  Coordinates x1 = index2coord(shape, element_idx);
555  Coordinates y1 = index2coord(shape, element_idx + 1);
556  Coordinates x2 = index2coord(shape, element_idx + 2);
557  Coordinates y2 = index2coord(shape, element_idx + 3);
558  ResultType &target_value_x1 = reinterpret_cast<ResultType *>(tensor(x1))[0];
559  ResultType &target_value_y1 = reinterpret_cast<ResultType *>(tensor(y1))[0];
560  ResultType &target_value_x2 = reinterpret_cast<ResultType *>(tensor(x2))[0];
561  ResultType &target_value_y2 = reinterpret_cast<ResultType *>(tensor(y2))[0];
562  store_value_with_data_type(&target_value_x1, std::get<0>(box), tensor.data_type());
563  store_value_with_data_type(&target_value_y1, std::get<1>(box), tensor.data_type());
564  store_value_with_data_type(&target_value_x2, std::get<2>(box), tensor.data_type());
565  store_value_with_data_type(&target_value_y2, std::get<3>(box), tensor.data_type());
566  }
568 }
decltype(strategy::transforms) typedef type
void store_value_with_data_type(void *ptr, T value, DataType data_type)
Write the value after casting the pointer according to data_type.
Definition: Utils.h:252
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Definition: Utils.h:359
CLTensor * tensor
Pointer to the auxiliary tensor.
void fill_borders_with_garbage(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
Puts garbage values all around the tensor for testing purposes.

◆ fill_layer_data()

void fill_layer_data ( T &&  tensor,
std::string  name 
) const

Fills the specified tensor with data loaded from .npy (numpy binary) in specified path.

Parameters
[in,out]tensorTo be filled tensor.
[in]nameData file.
Note
The numpy array stored in the binary .npy file must be row-major in the sense that it must store elements within a row consecutively in the memory, then rows within a 2D slice, then 2D slices within a 3D slice and so on. Note that it imposes no restrictions on what indexing convention is used in the numpy array. That is, the numpy array can be either fortran style or C style as long as it adheres to the rule above.

More concretely, the orders of dimensions for each style are as follows: C-style (numpy default): array[HigherDims..., Z, Y, X] Fortran style: array[X, Y, Z, HigherDims...]

Definition at line 1016 of file AssetsLibrary.h.

References arm_compute::execute_window_loop(), name, AssetsLibrary::path(), tensor, Window::use_tensor_dimensions(), and arm_compute::test::detail::validate_npy_header().

1017 {
1018 #ifdef _WIN32
1019  const std::string path_separator("\\");
1020 #else /* _WIN32 */
1021  const std::string path_separator("/");
1022 #endif /* _WIN32 */
1023  const std::string path = _library_path + path_separator + name;
1024 
1025  // Open file
1026  std::ifstream stream(path, std::ios::in | std::ios::binary);
1027  if(!stream.good())
1028  {
1029  throw framework::FileNotFound("Could not load npy file: " + path);
1030  }
1031 
1032  validate_npy_header(stream, tensor.data_type(), tensor.shape());
1033 
1034  // Read data
1035  if(tensor.padding().empty())
1036  {
1037  // If tensor has no padding read directly from stream.
1038  stream.read(reinterpret_cast<char *>(tensor.data()), tensor.size());
1039  }
1040  else
1041  {
1042  // If tensor has padding accessing tensor elements through execution window.
1043  Window window;
1044  window.use_tensor_dimensions(tensor.shape());
1045 
1046  execute_window_loop(window, [&](const Coordinates & id)
1047  {
1048  stream.read(reinterpret_cast<char *>(tensor(id)), tensor.element_size());
1049  });
1050  }
1051 }
std::string path() const
Path to assets directory used to initialise library.
void validate_npy_header(std::ifstream &stream, const std::string &expect_typestr, const TensorShape &expect_shape)
const char * name
CLTensor * tensor
Pointer to the auxiliary tensor.
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Definition: Helpers.inl:77

◆ fill_static_values()

void fill_static_values ( T &&  tensor,
const std::vector< DataType > &  values 
) const

Fill a tensor with a given vector with static values.

Parameters
[in,out]tensorTo be filled tensor.
[in]valuesA vector containing values

To cope with various size tensors, the vector size doens't have to be the same as tensor's size. If the size of the tensor is larger than the vector, the iterator the vector will keep iterating and wrap around. If the vector is larger, values located after the required size won't be used.

Definition at line 638 of file AssetsLibrary.h.

References AssetsLibrary::fill_with_generator(), and tensor.

639 {
640  auto it = values.begin();
641  GeneratorFunctionType<DataType> get_next_value = [&]()
642  {
643  const DataType value = *it;
644  ++it;
645 
646  if(it == values.end())
647  {
648  it = values.begin();
649  }
650 
651  return value;
652  };
653 
654  fill_with_generator(tensor, get_next_value);
655 }
void fill_with_generator(T &&tensor, const GeneratorFunctionType< ResultType > &generate_value) const
Fill a tensor with a value generator function.
CLTensor * tensor
Pointer to the auxiliary tensor.
DataType
Available data types.
Definition: Types.h:79

◆ fill_tensor_uniform() [1/2]

void fill_tensor_uniform ( T &&  tensor,
std::random_device::result_type  seed_offset 
) const

Fill a tensor with uniform distribution.

Parameters
[in,out]tensorTo be filled tensor.
[in]seed_offsetThe offset will be added to the global seed before initialising the random generator.

Definition at line 721 of file AssetsLibrary.h.

References ARM_COMPUTE_ERROR, arm_compute::BFLOAT16, arm_compute::F16, arm_compute::F32, arm_compute::F64, AssetsLibrary::fill(), arm_compute::support::cpp11::lowest(), arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, arm_compute::QSYMM16, arm_compute::QSYMM8, arm_compute::QSYMM8_PER_CHANNEL, arm_compute::S16, arm_compute::S32, arm_compute::S64, arm_compute::S8, arm_compute::SIZET, tensor, arm_compute::U16, arm_compute::U32, arm_compute::U64, and arm_compute::U8.

Referenced by AssetsLibrary::fill_tensor_value().

722 {
723  switch(tensor.data_type())
724  {
725  case DataType::U8:
726  case DataType::QASYMM8:
727  {
728  std::uniform_int_distribution<unsigned int> distribution_u8(std::numeric_limits<uint8_t>::lowest(), std::numeric_limits<uint8_t>::max());
729  fill(tensor, distribution_u8, seed_offset);
730  break;
731  }
732  case DataType::S8:
733  case DataType::QSYMM8:
736  {
737  std::uniform_int_distribution<int> distribution_s8(std::numeric_limits<int8_t>::lowest(), std::numeric_limits<int8_t>::max());
738  fill(tensor, distribution_s8, seed_offset);
739  break;
740  }
741  case DataType::U16:
742  {
743  std::uniform_int_distribution<uint16_t> distribution_u16(std::numeric_limits<uint16_t>::lowest(), std::numeric_limits<uint16_t>::max());
744  fill(tensor, distribution_u16, seed_offset);
745  break;
746  }
747  case DataType::S16:
748  case DataType::QSYMM16:
749  {
750  std::uniform_int_distribution<int16_t> distribution_s16(std::numeric_limits<int16_t>::lowest(), std::numeric_limits<int16_t>::max());
751  fill(tensor, distribution_s16, seed_offset);
752  break;
753  }
754  case DataType::U32:
755  {
756  std::uniform_int_distribution<uint32_t> distribution_u32(std::numeric_limits<uint32_t>::lowest(), std::numeric_limits<uint32_t>::max());
757  fill(tensor, distribution_u32, seed_offset);
758  break;
759  }
760  case DataType::S32:
761  {
762  std::uniform_int_distribution<int32_t> distribution_s32(std::numeric_limits<int32_t>::lowest(), std::numeric_limits<int32_t>::max());
763  fill(tensor, distribution_s32, seed_offset);
764  break;
765  }
766  case DataType::U64:
767  {
768  std::uniform_int_distribution<uint64_t> distribution_u64(std::numeric_limits<uint64_t>::lowest(), std::numeric_limits<uint64_t>::max());
769  fill(tensor, distribution_u64, seed_offset);
770  break;
771  }
772  case DataType::S64:
773  {
774  std::uniform_int_distribution<int64_t> distribution_s64(std::numeric_limits<int64_t>::lowest(), std::numeric_limits<int64_t>::max());
775  fill(tensor, distribution_s64, seed_offset);
776  break;
777  }
778  case DataType::BFLOAT16:
779  {
780  // It doesn't make sense to check [-inf, inf], so hard code it to a big number
781  arm_compute::utils::uniform_real_distribution_16bit<bfloat16> distribution_bf16{ -1000.f, 1000.f };
782  fill(tensor, distribution_bf16, seed_offset);
783  break;
784  }
785  case DataType::F16:
786  {
787  // It doesn't make sense to check [-inf, inf], so hard code it to a big number
788  arm_compute::utils::uniform_real_distribution_16bit<half> distribution_f16{ -100.f, 100.f };
789  fill(tensor, distribution_f16, seed_offset);
790  break;
791  }
792  case DataType::F32:
793  {
794  // It doesn't make sense to check [-inf, inf], so hard code it to a big number
795  std::uniform_real_distribution<float> distribution_f32(-1000.f, 1000.f);
796  fill(tensor, distribution_f32, seed_offset);
797  break;
798  }
799  case DataType::F64:
800  {
801  // It doesn't make sense to check [-inf, inf], so hard code it to a big number
802  std::uniform_real_distribution<double> distribution_f64(-1000.f, 1000.f);
803  fill(tensor, distribution_f64, seed_offset);
804  break;
805  }
806  case DataType::SIZET:
807  {
808  std::uniform_int_distribution<size_t> distribution_sizet(std::numeric_limits<size_t>::lowest(), std::numeric_limits<size_t>::max());
809  fill(tensor, distribution_sizet, seed_offset);
810  break;
811  }
812  default:
813  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
814  }
815 }
quantized, symmetric fixed-point 16-bit number
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
1 channel, 1 F32 per channel
1 channel, 1 U16 per channel
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
16-bit brain floating-point number
signed 64-bit number
Specialized class to generate random non-zero FP16 values.
Definition: Utils.h:254
1 channel, 1 U32 per channel
quantized, asymmetric fixed-point 8-bit number unsigned
void fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
Fills the specified tensor with random values drawn from distribution.
1 channel, 1 S16 per channel
quantized, symmetric fixed-point 8-bit number
quantized, symmetric per channel fixed-point 8-bit number
CLTensor * tensor
Pointer to the auxiliary tensor.
quantized, asymmetric fixed-point 8-bit number signed
64-bit floating-point number
unsigned 64-bit number
signed 8-bit number

◆ fill_tensor_uniform() [2/2]

void fill_tensor_uniform ( T &&  tensor,
std::random_device::result_type  seed_offset,
low,
high 
) const

Fill a tensor with uniform distribution.

Parameters
[in,out]tensorTo be filled tensor.
[in]seed_offsetThe offset will be added to the global seed before initialising the random generator.
[in]lowlowest value in the range (inclusive)
[in]highhighest value in the range (inclusive)
Note
low and high must be of the same type as the data type of tensor

Definition at line 913 of file AssetsLibrary.h.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, arm_compute::BFLOAT16, arm_compute::F16, arm_compute::F32, arm_compute::F64, AssetsLibrary::fill(), arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, arm_compute::QSYMM16, arm_compute::QSYMM8, arm_compute::S16, arm_compute::S32, arm_compute::S64, arm_compute::S8, arm_compute::SIZET, tensor, arm_compute::U16, arm_compute::U32, arm_compute::U64, and arm_compute::U8.

914 {
915  switch(tensor.data_type())
916  {
917  case DataType::U8:
918  case DataType::QASYMM8:
919  {
920  ARM_COMPUTE_ERROR_ON(!(std::is_same<uint8_t, D>::value));
921  std::uniform_int_distribution<uint32_t> distribution_u8(low, high);
922  fill(tensor, distribution_u8, seed_offset);
923  break;
924  }
925  case DataType::S8:
926  case DataType::QSYMM8:
928  {
929  ARM_COMPUTE_ERROR_ON(!(std::is_same<int8_t, D>::value));
930  std::uniform_int_distribution<int32_t> distribution_s8(low, high);
931  fill(tensor, distribution_s8, seed_offset);
932  break;
933  }
934  case DataType::U16:
935  {
936  ARM_COMPUTE_ERROR_ON(!(std::is_same<uint16_t, D>::value));
937  std::uniform_int_distribution<uint16_t> distribution_u16(low, high);
938  fill(tensor, distribution_u16, seed_offset);
939  break;
940  }
941  case DataType::S16:
942  case DataType::QSYMM16:
943  {
944  ARM_COMPUTE_ERROR_ON(!(std::is_same<int16_t, D>::value));
945  std::uniform_int_distribution<int16_t> distribution_s16(low, high);
946  fill(tensor, distribution_s16, seed_offset);
947  break;
948  }
949  case DataType::U32:
950  {
951  ARM_COMPUTE_ERROR_ON(!(std::is_same<uint32_t, D>::value));
952  std::uniform_int_distribution<uint32_t> distribution_u32(low, high);
953  fill(tensor, distribution_u32, seed_offset);
954  break;
955  }
956  case DataType::S32:
957  {
958  ARM_COMPUTE_ERROR_ON(!(std::is_same<int32_t, D>::value));
959  std::uniform_int_distribution<int32_t> distribution_s32(low, high);
960  fill(tensor, distribution_s32, seed_offset);
961  break;
962  }
963  case DataType::U64:
964  {
965  ARM_COMPUTE_ERROR_ON(!(std::is_same<uint64_t, D>::value));
966  std::uniform_int_distribution<uint64_t> distribution_u64(low, high);
967  fill(tensor, distribution_u64, seed_offset);
968  break;
969  }
970  case DataType::S64:
971  {
972  ARM_COMPUTE_ERROR_ON(!(std::is_same<int64_t, D>::value));
973  std::uniform_int_distribution<int64_t> distribution_s64(low, high);
974  fill(tensor, distribution_s64, seed_offset);
975  break;
976  }
977  case DataType::BFLOAT16:
978  {
979  arm_compute::utils::uniform_real_distribution_16bit<bfloat16> distribution_bf16{ float(low), float(high) };
980  fill(tensor, distribution_bf16, seed_offset);
981  break;
982  }
983  case DataType::F16:
984  {
985  arm_compute::utils::uniform_real_distribution_16bit<half> distribution_f16{ float(low), float(high) };
986  fill(tensor, distribution_f16, seed_offset);
987  break;
988  }
989  case DataType::F32:
990  {
991  ARM_COMPUTE_ERROR_ON(!(std::is_same<float, D>::value));
992  std::uniform_real_distribution<float> distribution_f32(low, high);
993  fill(tensor, distribution_f32, seed_offset);
994  break;
995  }
996  case DataType::F64:
997  {
998  ARM_COMPUTE_ERROR_ON(!(std::is_same<double, D>::value));
999  std::uniform_real_distribution<double> distribution_f64(low, high);
1000  fill(tensor, distribution_f64, seed_offset);
1001  break;
1002  }
1003  case DataType::SIZET:
1004  {
1005  ARM_COMPUTE_ERROR_ON(!(std::is_same<size_t, D>::value));
1006  std::uniform_int_distribution<size_t> distribution_sizet(low, high);
1007  fill(tensor, distribution_sizet, seed_offset);
1008  break;
1009  }
1010  default:
1011  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
1012  }
1013 }
quantized, symmetric fixed-point 16-bit number
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
1 channel, 1 U16 per channel
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
16-bit brain floating-point number
signed 64-bit number
Specialized class to generate random non-zero FP16 values.
Definition: Utils.h:254
1 channel, 1 U32 per channel
quantized, asymmetric fixed-point 8-bit number unsigned
void fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
Fills the specified tensor with random values drawn from distribution.
1 channel, 1 S16 per channel
quantized, symmetric fixed-point 8-bit number
CLTensor * tensor
Pointer to the auxiliary tensor.
quantized, asymmetric fixed-point 8-bit number signed
64-bit floating-point number
unsigned 64-bit number
signed 8-bit number

◆ fill_tensor_uniform_ranged()

void fill_tensor_uniform_ranged ( T &&  tensor,
std::random_device::result_type  seed_offset,
const std::vector< AssetsLibrary::RangePair > &  excluded_range_pairs 
) const

Fill a tensor with uniform distribution across the specified range.

Parameters
[in,out]tensorTo be filled tensor.
[in]seed_offsetThe offset will be added to the global seed before initialising the random generator.
[in]excluded_range_pairsRanges to exclude from the generator

Definition at line 818 of file AssetsLibrary.h.

References ARM_COMPUTE_ERROR, arm_compute::BFLOAT16, arm_compute::F16, arm_compute::F32, AssetsLibrary::fill(), arm_compute::support::cpp11::lowest(), arm_compute::QASYMM8, arm_compute::QSYMM16, arm_compute::QSYMM8, arm_compute::S16, arm_compute::S32, arm_compute::S8, tensor, arm_compute::U16, arm_compute::U32, and arm_compute::U8.

821 {
822  using namespace arm_compute::utils::random;
823 
824  switch(tensor.data_type())
825  {
826  case DataType::U8:
827  case DataType::QASYMM8:
828  {
829  const auto converted_pairs = detail::convert_range_pair<uint32_t>(excluded_range_pairs);
831  std::numeric_limits<uint8_t>::max(),
832  converted_pairs);
833  fill(tensor, distribution_u8, seed_offset);
834  break;
835  }
836  case DataType::S8:
837  case DataType::QSYMM8:
838  {
839  const auto converted_pairs = detail::convert_range_pair<int32_t>(excluded_range_pairs);
841  std::numeric_limits<int8_t>::max(),
842  converted_pairs);
843  fill(tensor, distribution_s8, seed_offset);
844  break;
845  }
846  case DataType::U16:
847  {
848  const auto converted_pairs = detail::convert_range_pair<uint16_t>(excluded_range_pairs);
850  std::numeric_limits<uint16_t>::max(),
851  converted_pairs);
852  fill(tensor, distribution_u16, seed_offset);
853  break;
854  }
855  case DataType::S16:
856  case DataType::QSYMM16:
857  {
858  const auto converted_pairs = detail::convert_range_pair<int16_t>(excluded_range_pairs);
860  std::numeric_limits<int16_t>::max(),
861  converted_pairs);
862  fill(tensor, distribution_s16, seed_offset);
863  break;
864  }
865  case DataType::U32:
866  {
867  const auto converted_pairs = detail::convert_range_pair<uint32_t>(excluded_range_pairs);
869  std::numeric_limits<uint32_t>::max(),
870  converted_pairs);
871  fill(tensor, distribution_u32, seed_offset);
872  break;
873  }
874  case DataType::S32:
875  {
876  const auto converted_pairs = detail::convert_range_pair<int32_t>(excluded_range_pairs);
878  std::numeric_limits<int32_t>::max(),
879  converted_pairs);
880  fill(tensor, distribution_s32, seed_offset);
881  break;
882  }
883  case DataType::BFLOAT16:
884  {
885  // It doesn't make sense to check [-inf, inf], so hard code it to a big number
886  const auto converted_pairs = detail::convert_range_pair<bfloat16>(excluded_range_pairs);
887  RangedUniformDistribution<bfloat16> distribution_bf16(bfloat16(-1000.f), bfloat16(1000.f), converted_pairs);
888  fill(tensor, distribution_bf16, seed_offset);
889  break;
890  }
891  case DataType::F16:
892  {
893  // It doesn't make sense to check [-inf, inf], so hard code it to a big number
894  const auto converted_pairs = detail::convert_range_pair<half>(excluded_range_pairs);
895  RangedUniformDistribution<half> distribution_f16(half(-100.f), half(100.f), converted_pairs);
896  fill(tensor, distribution_f16, seed_offset);
897  break;
898  }
899  case DataType::F32:
900  {
901  // It doesn't make sense to check [-inf, inf], so hard code it to a big number
902  const auto converted_pairs = detail::convert_range_pair<float>(excluded_range_pairs);
903  RangedUniformDistribution<float> distribution_f32(-1000.f, 1000.f, converted_pairs);
904  fill(tensor, distribution_f32, seed_offset);
905  break;
906  }
907  default:
908  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
909  }
910 }
Uniform distribution within a given number of sub-ranges.
Definition: Random.h:44
quantized, symmetric fixed-point 16-bit number
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
half_float::half half
16-bit floating point type
Definition: Types.h:48
1 channel, 1 F32 per channel
1 channel, 1 U16 per channel
1 channel, 1 F16 per channel
arm_compute::bfloat16 bfloat16
Definition: bfloat.hpp:30
1 channel, 1 S32 per channel
16-bit brain floating-point number
1 channel, 1 U32 per channel
quantized, asymmetric fixed-point 8-bit number unsigned
void fill(T &&tensor, D &&distribution, std::random_device::result_type seed_offset) const
Fills the specified tensor with random values drawn from distribution.
1 channel, 1 S16 per channel
quantized, symmetric fixed-point 8-bit number
CLTensor * tensor
Pointer to the auxiliary tensor.
signed 8-bit number

◆ fill_tensor_value()

void fill_tensor_value ( T &&  tensor,
value 
) const

Fill a tensor with a constant value.

Parameters
[in,out]tensorTo be filled tensor.
[in]valueValue to be assigned to all elements of the input tensor.
Note
value must be of the same type as the data type of tensor

Definition at line 1054 of file AssetsLibrary.h.

References AssetsLibrary::fill_tensor_uniform(), and tensor.

1055 {
1056  fill_tensor_uniform(tensor, 0, value, value);
1057 }
void fill_tensor_uniform(T &&tensor, std::random_device::result_type seed_offset) const
Fill a tensor with uniform distribution.
CLTensor * tensor
Pointer to the auxiliary tensor.

◆ fill_with_generator()

void fill_with_generator ( T &&  tensor,
const GeneratorFunctionType< ResultType > &  generate_value 
) const

Fill a tensor with a value generator function.

Parameters
[in,out]tensorTo be filled tensor.
[in]generate_valueA function that generates values.

Definition at line 587 of file AssetsLibrary.h.

References arm_compute::test::index2coord(), arm_compute::NHWC, arm_compute::permute(), arm_compute::test::validation::shape, arm_compute::test::store_value_with_data_type(), tensor, and arm_compute::utils::cast::U.

Referenced by AssetsLibrary::fill(), and AssetsLibrary::fill_static_values().

588 {
589  const bool is_nhwc = tensor.data_layout() == DataLayout::NHWC;
590  TensorShape shape(tensor.shape());
591 
592  if(is_nhwc)
593  {
594  // Ensure that the equivalent tensors will be filled for both data layouts
595  permute(shape, PermutationVector(1U, 2U, 0U));
596  }
597 
598  // Iterate over all elements
599  const uint32_t num_elements = tensor.num_elements();
600  for(uint32_t element_idx = 0; element_idx < num_elements; ++element_idx)
601  {
602  Coordinates id = index2coord(shape, element_idx);
603 
604  if(is_nhwc)
605  {
606  // Write in the correct id for permuted shapes
607  permute(id, PermutationVector(2U, 0U, 1U));
608  }
609 
610  // Iterate over all channels
611  for(int channel = 0; channel < tensor.num_channels(); ++channel)
612  {
613  const ResultType value = generate_value();
614  ResultType &target_value = reinterpret_cast<ResultType *>(tensor(id))[channel];
615 
616  store_value_with_data_type(&target_value, value, tensor.data_type());
617  }
618  }
619 }
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
void store_value_with_data_type(void *ptr, T value, DataType data_type)
Write the value after casting the pointer according to data_type.
Definition: Utils.h:252
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Definition: Utils.h:359
Num samples, height, width, channels.
CLTensor * tensor
Pointer to the auxiliary tensor.

◆ get() [1/9]

const RawTensor & get ( const std::string &  name) const

Provides a constant raw tensor for the specified image.

Parameters
[in]nameImage file used to look up the raw tensor.
Returns
a raw tensor for the specified image.

Definition at line 471 of file AssetsLibrary.cpp.

References arm_compute::RGB888.

472 {
473  //FIXME: Format should be derived from the image name. Not be fixed to RGB.
474  return find_or_create_raw_tensor(name, Format::RGB888);
475 }
3 channels, 1 U8 per channel
const char * name

◆ get() [2/9]

RawTensor get ( const std::string &  name)

Provides a raw tensor for the specified image.

Parameters
[in]nameImage file used to look up the raw tensor.
Returns
a raw tensor for the specified image.

Definition at line 477 of file AssetsLibrary.cpp.

References arm_compute::RGB888.

478 {
479  //FIXME: Format should be derived from the image name. Not be fixed to RGB.
480  return RawTensor(find_or_create_raw_tensor(name, Format::RGB888));
481 }
3 channels, 1 U8 per channel
const char * name

◆ get() [3/9]

RawTensor get ( const std::string &  name,
DataType  data_type,
int  num_channels = 1 
) const

Creates an uninitialised raw tensor with the given data_type and num_channels.

The shape is derived from the specified image.

Parameters
[in]nameImage file used to initialise the tensor.
[in]data_typeData type used to initialise the tensor.
[in]num_channelsNumber of channels used to initialise the tensor.
Returns
a raw tensor for the specified image.

Definition at line 483 of file AssetsLibrary.cpp.

References arm_compute::test::validation::data_type, name, and SimpleTensor< T >::shape().

484 {
485  const RawTensor &raw = get(name);
486 
487  return RawTensor(raw.shape(), data_type, num_channels);
488 }
const char * name

◆ get() [4/9]

const RawTensor & get ( const std::string &  name,
Format  format 
) const

Provides a contant raw tensor for the specified image after it has been converted to format.

Parameters
[in]nameImage file used to look up the raw tensor.
[in]formatFormat used to look up the raw tensor.
Returns
a raw tensor for the specified image.

Definition at line 490 of file AssetsLibrary.cpp.

491 {
492  return find_or_create_raw_tensor(name, format);
493 }
const char * name

◆ get() [5/9]

RawTensor get ( const std::string &  name,
Format  format 
)

Provides a raw tensor for the specified image after it has been converted to format.

Parameters
[in]nameImage file used to look up the raw tensor.
[in]formatFormat used to look up the raw tensor.
Returns
a raw tensor for the specified image.

Definition at line 495 of file AssetsLibrary.cpp.

496 {
497  return RawTensor(find_or_create_raw_tensor(name, format));
498 }
const char * name

◆ get() [6/9]

const RawTensor & get ( const std::string &  name,
Channel  channel 
) const

Provides a contant raw tensor for the specified channel after it has been extracted form the given image.

Parameters
[in]nameImage file used to look up the raw tensor.
[in]channelChannel used to look up the raw tensor.
Note
The channel has to be unambiguous so that the format can be inferred automatically.
Returns
a raw tensor for the specified image channel.

Definition at line 500 of file AssetsLibrary.cpp.

References arm_compute::test::get_format_for_channel(), and name.

501 {
502  return get(name, get_format_for_channel(channel), channel);
503 }
Format get_format_for_channel(Channel channel)
Look up the format corresponding to a channel.
Definition: Utils.h:145
const char * name

◆ get() [7/9]

RawTensor get ( const std::string &  name,
Channel  channel 
)

Provides a raw tensor for the specified channel after it has been extracted form the given image.

Parameters
[in]nameImage file used to look up the raw tensor.
[in]channelChannel used to look up the raw tensor.
Note
The channel has to be unambiguous so that the format can be inferred automatically.
Returns
a raw tensor for the specified image channel.

Definition at line 505 of file AssetsLibrary.cpp.

References arm_compute::test::get_format_for_channel().

506 {
507  return RawTensor(get(name, get_format_for_channel(channel), channel));
508 }
Format get_format_for_channel(Channel channel)
Look up the format corresponding to a channel.
Definition: Utils.h:145
const char * name

◆ get() [8/9]

const RawTensor & get ( const std::string &  name,
Format  format,
Channel  channel 
) const

Provides a constant raw tensor for the specified channel after it has been extracted form the given image formatted to format.

Parameters
[in]nameImage file used to look up the raw tensor.
[in]formatFormat used to look up the raw tensor.
[in]channelChannel used to look up the raw tensor.
Returns
a raw tensor for the specified image channel.

Definition at line 510 of file AssetsLibrary.cpp.

511 {
512  return find_or_create_raw_tensor(name, format, channel);
513 }
const char * name

◆ get() [9/9]

RawTensor get ( const std::string &  name,
Format  format,
Channel  channel 
)

Provides a raw tensor for the specified channel after it has been extracted form the given image formatted to format.

Parameters
[in]nameImage file used to look up the raw tensor.
[in]formatFormat used to look up the raw tensor.
[in]channelChannel used to look up the raw tensor.
Returns
a raw tensor for the specified image channel.

Definition at line 515 of file AssetsLibrary.cpp.

516 {
517  return RawTensor(find_or_create_raw_tensor(name, format, channel));
518 }
const char * name

◆ get_image_shape()

TensorShape get_image_shape ( const std::string &  name)

Provides a tensor shape for the specified image.

Parameters
[in]nameImage file used to look up the raw tensor.
Returns
the tensor shape for the specified image.

Definition at line 466 of file AssetsLibrary.cpp.

References SimpleTensor< T >::shape().

467 {
468  return load_image(name).shape();
469 }
TensorShape shape() const override
Shape of the tensor.
Definition: SimpleTensor.h:320
const char * name

◆ path()

std::string path ( ) const

Path to assets directory used to initialise library.

Returns
the path to the assets directory.

Definition at line 260 of file AssetsLibrary.cpp.

Referenced by AssetsLibrary::fill_layer_data().

261 {
262  return _library_path;
263 }

◆ seed()

std::random_device::result_type seed ( ) const

Seed that is used to fill tensors with random values.

Returns
the initial random seed.

Definition at line 265 of file AssetsLibrary.cpp.

266 {
267  return _seed;
268 }

The documentation for this class was generated from the following files: