17 #include <openvino/openvino.hpp>
18 #include "utils/slog.hpp"
25 #define UNUSED __attribute__((unused))
29 template <
typename T, std::
size_t N>
30 constexpr std::size_t arraySize(
const T(&)[N]) noexcept {
34 static inline void catcher() noexcept {
35 if (std::current_exception()) {
37 std::rethrow_exception(std::current_exception());
38 }
catch (
const std::exception& error) {
39 slog::err << error.what() << slog::endl;
41 slog::err <<
"Non-exception object thrown" << slog::endl;
49 T clamp(T value, T low, T high) {
50 return value < low ? low : (value > high ? high : value);
54 return os <<
"OpenVINO" << slog::endl
55 <<
"\tversion: " << OPENVINO_VERSION_MAJOR <<
"." << OPENVINO_VERSION_MINOR <<
"." << OPENVINO_VERSION_PATCH << slog::endl
56 <<
"\tbuild: " << version.buildNumber;
78 unsigned char b) : _r(r), _g(g), _b(b) {}
80 inline unsigned char red()
const {
84 inline unsigned char blue()
const {
88 inline unsigned char green()
const {
94 static UNUSED
const Color CITYSCAPES_COLORS[] = {
118 inline void showAvailableDevices() {
120 std::vector<std::string> devices = core.get_available_devices();
122 std::cout <<
"Available devices:";
123 for (
const auto& device : devices) {
124 std::cout <<
' ' << device;
126 std::cout << std::endl;
129 inline std::string fileNameNoExt(
const std::string& filepath) {
130 auto pos = filepath.rfind(
'.');
131 if (pos == std::string::npos)
return filepath;
132 return filepath.substr(0, pos);
135 inline void logCompiledModelInfo(
136 const ov::CompiledModel& compiledModel,
137 const std::string& modelName,
138 const std::string& deviceName,
139 const std::string& modelType =
"") {
140 slog::info <<
"The " << modelType << (modelType.empty() ?
"" :
" ") <<
"model " << modelName <<
" is loaded to " << deviceName << slog::endl;
141 std::set<std::string> devices;
142 for (
const std::string& device : parseDevices(deviceName)) {
143 devices.insert(device);
146 if (devices.find(
"AUTO") == devices.end()) {
147 for (
const auto& device : devices) {
149 slog::info <<
"\tDevice: " << device << slog::endl;
150 int32_t nstreams = compiledModel.get_property(ov::streams::num);
151 slog::info <<
"\t\tNumber of streams: " << nstreams << slog::endl;
152 if (device ==
"CPU") {
153 int32_t nthreads = compiledModel.get_property(ov::inference_num_threads);
154 slog::info <<
"\t\tNumber of threads: " << (nthreads == 0 ?
"AUTO" : std::to_string(nthreads)) << slog::endl;
157 catch (
const ov::Exception&) {}
162 inline void logBasicModelInfo(
const std::shared_ptr<ov::Model>& model) {
163 slog::info <<
"Model name: " << model->get_friendly_name() << slog::endl;
166 ov::OutputVector inputs = model->inputs();
167 ov::OutputVector outputs = model->outputs();
169 slog::info <<
"\tInputs: " << slog::endl;
170 for (
const ov::Output<ov::Node>& input : inputs) {
171 const std::string name = input.get_any_name();
172 const ov::element::Type type = input.get_element_type();
173 const ov::PartialShape shape = input.get_partial_shape();
174 const ov::Layout layout = ov::layout::get_layout(input);
176 slog::info <<
"\t\t" << name <<
", " << type <<
", " << shape <<
", " << layout.to_string() << slog::endl;
179 slog::info <<
"\tOutputs: " << slog::endl;
180 for (
const ov::Output<ov::Node>& output : outputs) {
181 const std::string name = output.get_any_name();
182 const ov::element::Type type = output.get_element_type();
183 const ov::PartialShape shape = output.get_partial_shape();
184 const ov::Layout layout = ov::layout::get_layout(output);
186 slog::info <<
"\t\t" << name <<
", " << type <<
", " << shape <<
", " << layout.to_string() << slog::endl;
192 std::vector<unsigned> loadClassIndices(
const std::string &groundtruth_filepath,
193 const std::vector<std::string> &imageNames);
A Color class stores channels of a given color.
Definition: common.hpp:63
Color(unsigned char r, unsigned char g, unsigned char b)
Definition: common.hpp:76
The LogStream class implements a stream for sample logging.
Definition: slog.hpp:39
a header file with common samples functionality