36 #pragma GCC diagnostic push 37 #pragma GCC diagnostic ignored "-Wswitch-default" 38 #pragma GCC diagnostic ignored "-Wunused-parameter" 39 #pragma GCC diagnostic ignored "-Wstrict-overflow" 40 #if (defined(__GNUC__) && (__GNUC__ >= 7)) 41 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" 42 #endif // (defined(__GNUC__) && (__GNUC__ >= 7)) 43 #if defined(__clang__) 44 #pragma GCC diagnostic ignored "-Wparentheses-equality" 45 #endif // defined(__clang__) 46 #define STB_IMAGE_IMPLEMENTATION 47 #include "stb/stb_image.h" 48 #pragma GCC diagnostic pop 60 void discard_comments(std::ifstream &fs)
62 while(fs.peek() ==
'#')
64 fs.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
72 void discard_comments_and_spaces(std::ifstream &fs)
78 if(isspace(fs.peek()) == 0)
88 #ifndef BENCHMARK_EXAMPLES 89 int run_example(
int argc,
char **argv, std::unique_ptr<Example> example)
96 bool status = example->do_setup(argc, argv);
102 example->do_teardown();
104 std::cout <<
"\nTest passed\n";
107 #ifdef ARM_COMPUTE_CL 108 catch(cl::Error &err)
110 std::cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
111 std::cerr << std::endl
112 <<
"ERROR " << err.what() <<
"(" << err.err() <<
")" << std::endl;
113 std::cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
116 catch(std::runtime_error &err)
118 std::cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
119 std::cerr << std::endl
120 <<
"ERROR " << err.what() <<
" " << (errno ? strerror(errno) :
"") << std::endl;
121 std::cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
124 std::cout <<
"\nTest FAILED\n";
140 for(
size_t x = 0; x < rect.
width; ++x)
153 for(
size_t y = 0; y < rect.
height; ++y)
175 fs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
176 fs.open(filename, std::ios::in | std::ios::binary);
179 std::array<unsigned char, 2> magic_number{ { 0 } };
180 fs >> magic_number[0] >> magic_number[1];
183 if(static_cast<char>(magic_number[0]) ==
'P' && static_cast<char>(magic_number[1]) ==
'6')
187 else if(magic_number[0] == 0xFF && magic_number[1] == 0xD8)
194 catch(std::runtime_error &e)
205 std::array<char, 2> magic_number{ { 0 } };
206 fs >> magic_number[0] >> magic_number[1];
210 discard_comments_and_spaces(fs);
212 unsigned int width = 0;
215 discard_comments_and_spaces(fs);
217 unsigned int height = 0;
220 discard_comments_and_spaces(fs);
225 discard_comments(fs);
230 return std::make_tuple(width, height, max_val);
233 std::tuple<std::vector<unsigned long>, bool, std::string>
parse_npy_header(std::ifstream &fs)
235 std::vector<unsigned long>
shape;
238 std::string
header = npy::read_header(fs);
241 bool fortran_order =
false;
243 npy::parse_header(
header, typestr, fortran_order,
shape);
247 return std::make_tuple(
shape, fortran_order, typestr);
256 std::string line_attribute;
257 std::ifstream file_meminfo(
"/proc/meminfo");
259 if(file_meminfo.is_open())
261 while(!(file_meminfo >> line_attribute).fail())
264 if(line_attribute ==
"MemFree:")
266 uint64_t mem_available;
267 if(!(file_meminfo >> mem_available).fail())
269 return mem_available;
277 file_meminfo.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
SimpleTensor< T > reverse(const SimpleTensor< T > &src, const SimpleTensor< uint32_t > &axis)
int run_example(int argc, char **argv, std::unique_ptr< Example > example)
Run an example and handle the potential exceptions it throws.
uint64_t get_mem_free_from_meminfo()
This function returns the amount of memory free reading from /proc/meminfo.
uint16_t x
Top-left x coordinate.
virtual int32_t offset_element_in_bytes(const Coordinates &pos) const =0
The offset in bytes from the beginning of the memory allocation to access the element at position (x,...
#define ARM_COMPUTE_ERROR_VAR(msg,...)
Print the given message then throw an std::runtime_error.
#define ARM_COMPUTE_ERROR_ON_FORMAT_NOT_IN(t,...)
decltype(strategy::transforms) typedef type
Interface for CPU tensor.
Copyright (c) 2017-2021 Arm Limited.
3 channels, 1 U8 per channel
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
uint16_t width
Width of the detection window.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory.
std::tuple< std::vector< unsigned long >, bool, std::string > parse_npy_header(std::ifstream &fs)
Parse the npy header from an input file stream.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
uint16_t height
Height of the detection window.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
Detection window used for the object detection.
void draw_detection_rectangle(ITensor *tensor, const DetectionWindow &rect, uint8_t r, uint8_t g, uint8_t b)
Draw a RGB rectangular window for the detected object.
ImageType
Supported image types.
uint16_t y
Top-left y coordinate.
std::tuple< unsigned int, unsigned int, int > parse_ppm_header(std::ifstream &fs)
Parse the ppm header from an input file stream.
ImageType get_image_type_from_file(const std::string &filename)
Gets image type given a file.
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
void header(TokenStream &in, bool &valid)