24.02.1
|
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 RawTensor & | get (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 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 . 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 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. 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 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 . 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... | |
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.
using GeneratorFunctionType = std::function<ResultType(void)> |
Definition at line 411 of file AssetsLibrary.h.
using RangePair = std::pair<float, float> |
Definition at line 62 of file AssetsLibrary.h.
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
.
[in] | path | Path to load assets from. |
[in] | seed | Seed used to initialise the random number generator. |
Definition at line 254 of file AssetsLibrary.cpp.
References AssetsLibrary::seed().
Fills the raw tensor with the content of the specified channel extracted from the given image.
[in,out] | raw | To be filled raw tensor. |
[in] | name | Image file used to fill the tensor. |
[in] | channel | Channel of the image used to fill the tensor. |
Definition at line 277 of file AssetsLibrary.cpp.
References AssetsLibrary::fill(), arm_compute::test::get_format_for_channel(), and name.
Fills the raw tensor with the content of the specified image converted to the given format.
[in,out] | raw | To be filled raw tensor. |
[in] | name | Image file used to fill the tensor. |
[in] | format | Format of the image used to fill the tensor. |
Definition at line 270 of file AssetsLibrary.cpp.
References SimpleTensor< T >::data(), update_supported_ops::format, AssetsLibrary::get(), name, SimpleTensor< T >::size(), and arm_compute::test::validation::src.
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.
[in,out] | raw | To be filled raw tensor. |
[in] | name | Image file used to fill the tensor. |
[in] | format | Format of the image used to fill the tensor. |
[in] | channel | Channel of the image used to fill the tensor. |
Definition at line 282 of file AssetsLibrary.cpp.
References SimpleTensor< T >::data(), update_supported_ops::format, AssetsLibrary::get(), name, SimpleTensor< T >::size(), and arm_compute::test::validation::src.
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
.
[in,out] | raw | To be filled raw. |
[in] | distribution | Distribution used to fill the tensor. |
[in] | seed_offset | The offset will be added to the global seed before initialising the random generator. |
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().
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
.
[in,out] | vec | To be filled vector. |
[in] | distribution | Distribution used to fill the tensor. |
[in] | seed_offset | The offset will be added to the global seed before initialising the random generator. |
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().
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.
[in,out] | tensor | To be filled tensor. |
[in] | name | Image file used to fill the tensor. |
[in] | channel | Channel of the image used to fill the tensor. |
Definition at line 687 of file AssetsLibrary.h.
References AssetsLibrary::fill(), arm_compute::test::get_format_for_channel(), name, and tensor.
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.
[in,out] | tensor | To be filled tensor. |
[in] | name | Image file used to fill the tensor. |
[in] | format | Format of the image used to fill the tensor. |
Definition at line 672 of file AssetsLibrary.h.
References SimpleTensor< T >::data(), SimpleTensor< T >::element_size(), update_supported_ops::format, AssetsLibrary::get(), arm_compute::test::index2coord(), name, offset(), SimpleTensor< T >::shape(), SimpleTensor< T >::size(), and tensor.
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.
[in,out] | tensor | To be filled tensor. |
[in] | name | Image file used to fill the tensor. |
[in] | format | Format of the image used to fill the tensor. |
[in] | channel | Channel of the image used to fill the tensor. |
Definition at line 693 of file AssetsLibrary.h.
References SimpleTensor< T >::data(), SimpleTensor< T >::element_size(), update_supported_ops::format, AssetsLibrary::get(), arm_compute::test::index2coord(), name, offset(), SimpleTensor< T >::shape(), SimpleTensor< T >::size(), and tensor.
void fill | ( | T && | tensor, |
D && | distribution, | ||
std::random_device::result_type | seed_offset | ||
) | const |
Fills the specified tensor
with random values drawn from distribution
.
[in,out] | tensor | To be filled tensor. |
[in] | distribution | Distribution used to fill the tensor. |
[in] | seed_offset | The offset will be added to the global seed before initialising the random generator. |
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 AssetsLibrary::fill(), AssetsLibrary::fill_tensor_uniform(), and AssetsLibrary::fill_tensor_uniform_ranged().
void fill | ( | T && | tensor, |
RawTensor | raw | ||
) | const |
Fills the specified tensor
with the content of the raw tensor.
[in,out] | tensor | To be filled tensor. |
[in] | raw | Raw tensor used to fill 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.
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.
[in,out] | tensor | To be filled tensor. |
[in] | distribution | Distribution used to fill the tensor's surroundings. |
[in] | seed_offset | The 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::execute_window_loop(), BorderSize::left, BorderSize::right, Window::set(), arm_compute::test::validation::shape, tensor, and BorderSize::top.
Referenced by AssetsLibrary::fill(), and AssetsLibrary::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.
void fill_layer_data | ( | T && | tensor, |
std::string | name | ||
) | const |
Fills the specified tensor
with data loaded from .npy (numpy binary) in specified path.
[in,out] | tensor | To be filled tensor. |
[in] | name | Data file. |
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().
void fill_static_values | ( | T && | tensor, |
const std::vector< DataType > & | values | ||
) | const |
Fill a tensor with a given vector with static values.
[in,out] | tensor | To be filled tensor. |
[in] | values | A 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.
void fill_tensor_uniform | ( | T && | tensor, |
std::random_device::result_type | seed_offset | ||
) | const |
Fill a tensor with uniform distribution.
[in,out] | tensor | To be filled tensor. |
[in] | seed_offset | The 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().
void fill_tensor_uniform | ( | T && | tensor, |
std::random_device::result_type | seed_offset, | ||
D | low, | ||
D | high | ||
) | const |
Fill a tensor with uniform distribution.
[in,out] | tensor | To be filled tensor. |
[in] | seed_offset | The offset will be added to the global seed before initialising the random generator. |
[in] | low | lowest value in the range (inclusive) |
[in] | high | highest value in the range (inclusive) |
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.
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.
[in,out] | tensor | To be filled tensor. |
[in] | seed_offset | The offset will be added to the global seed before initialising the random generator. |
[in] | excluded_range_pairs | Ranges 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.
void fill_tensor_value | ( | T && | tensor, |
D | value | ||
) | const |
Fill a tensor with a constant value.
[in,out] | tensor | To be filled tensor. |
[in] | value | Value to be assigned to all elements of the input tensor. |
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.
void fill_with_generator | ( | T && | tensor, |
const GeneratorFunctionType< ResultType > & | generate_value | ||
) | const |
Fill a tensor with a value generator function.
[in,out] | tensor | To be filled tensor. |
[in] | generate_value | A 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().
RawTensor get | ( | const std::string & | name | ) |
Provides a raw tensor for the specified image.
[in] | name | Image file used to look up the raw tensor. |
Definition at line 477 of file AssetsLibrary.cpp.
References name, and arm_compute::RGB888.
const RawTensor & get | ( | const std::string & | name | ) | const |
Provides a constant raw tensor for the specified image.
[in] | name | Image file used to look up the raw tensor. |
Definition at line 471 of file AssetsLibrary.cpp.
References name, and arm_compute::RGB888.
Referenced by AssetsLibrary::fill(), and AssetsLibrary::get().
Provides a raw tensor for the specified channel after it has been extracted form the given image.
[in] | name | Image file used to look up the raw tensor. |
[in] | channel | Channel used to look up the raw tensor. |
Definition at line 505 of file AssetsLibrary.cpp.
References AssetsLibrary::get(), arm_compute::test::get_format_for_channel(), and name.
Provides a contant raw tensor for the specified channel after it has been extracted form the given image.
[in] | name | Image file used to look up the raw tensor. |
[in] | channel | Channel used to look up the raw tensor. |
Definition at line 500 of file AssetsLibrary.cpp.
References AssetsLibrary::get(), arm_compute::test::get_format_for_channel(), and name.
Creates an uninitialised raw tensor with the given data_type
and num_channels
.
The shape is derived from the specified image.
[in] | name | Image file used to initialise the tensor. |
[in] | data_type | Data type used to initialise the tensor. |
[in] | num_channels | Number of channels used to initialise the tensor. |
Definition at line 483 of file AssetsLibrary.cpp.
References arm_compute::test::validation::data_type, AssetsLibrary::get(), name, and SimpleTensor< T >::shape().
Provides a raw tensor for the specified image after it has been converted to format
.
[in] | name | Image file used to look up the raw tensor. |
[in] | format | Format used to look up the raw tensor. |
Definition at line 495 of file AssetsLibrary.cpp.
References update_supported_ops::format, and name.
Provides a contant raw tensor for the specified image after it has been converted to format
.
[in] | name | Image file used to look up the raw tensor. |
[in] | format | Format used to look up the raw tensor. |
Definition at line 490 of file AssetsLibrary.cpp.
References update_supported_ops::format, and name.
Provides a raw tensor for the specified channel after it has been extracted form the given image formatted to format
.
[in] | name | Image file used to look up the raw tensor. |
[in] | format | Format used to look up the raw tensor. |
[in] | channel | Channel used to look up the raw tensor. |
Definition at line 515 of file AssetsLibrary.cpp.
References update_supported_ops::format, and name.
Provides a constant raw tensor for the specified channel after it has been extracted form the given image formatted to format
.
[in] | name | Image file used to look up the raw tensor. |
[in] | format | Format used to look up the raw tensor. |
[in] | channel | Channel used to look up the raw tensor. |
Definition at line 510 of file AssetsLibrary.cpp.
References update_supported_ops::format, and name.
TensorShape get_image_shape | ( | const std::string & | name | ) |
Provides a tensor shape for the specified image.
[in] | name | Image file used to look up the raw tensor. |
Definition at line 466 of file AssetsLibrary.cpp.
References name, and SimpleTensor< T >::shape().
std::string path | ( | ) | const |
Path to assets directory used to initialise library.
Definition at line 260 of file AssetsLibrary.cpp.
Referenced by AssetsLibrary::fill_layer_data().
std::random_device::result_type seed | ( | ) | const |
Seed that is used to fill tensors with random values.
Definition at line 265 of file AssetsLibrary.cpp.
Referenced by AssetsLibrary::AssetsLibrary().