ov2.0 IE samples modification (#8340)

* ov2.0 IE samples modification

apply code style

turn off clang style check for headers order

unify samples a bit

add yuv nv12 reader to format_reader, helloe_nv112 sample

hello_reshape_ssd ov2.0

* sync with PR 8629 preprocessing api changes

* fix for slog << vector<int>

* add operator<< for ov::Version from PR-8687

* Update samples/cpp/hello_nv12_input_classification/main.cpp

Co-authored-by: Mikhail Nosov <mikhail.nosov@intel.com>

* apply code style

* change according to review comments

* add const qualifier

* apply code style

* std::ostream for old inference engine version to make VPU plugin tests happy

* apply code style

* revert changes in print version for old api samples

* keep inference_engine.hpp for not ov2.0 yet samples

* fix merge artifacts

* fix compilation

* apply code style

* Fixed classification sample test

* Revert changes in hello_reshape_ssd sample

* rebase to master, sync with PR-9054

* fix issues found by C++ tests

* rebased and sync with PR-9051

* fix test result parsers for classification tests (except unicode one)

* fix mismatches after merge

* rebase and sync with PR-9144

Co-authored-by: Mikhail Nosov <mikhail.nosov@intel.com>
Co-authored-by: antonrom23 <anton.romanov@intel.com>
This commit is contained in:
Vladimir Dudnik
2021-12-13 11:30:58 +03:00
committed by GitHub
parent 4e8a6d5a4b
commit 5b25dbee22
45 changed files with 1033 additions and 825 deletions

View File

@@ -5,28 +5,18 @@
#include <cstdlib>
#include <iomanip>
#include <memory>
#include <samples/common.hpp>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include "ie_plugin_config.hpp"
// clang-format off
#include "openvino/openvino.hpp"
#include "samples/common.hpp"
#include "samples/slog.hpp"
// clang-format on
namespace {
/**
* @brief Overload output stream operator to print vectors in pretty form
* [value1, value2, ...]
*/
template <typename T>
std::ostream& operator<<(std::ostream& stream, const std::vector<T>& v) {
stream << "[ ";
for (auto&& value : v)
stream << value << " ";
return stream << "]";
}
/**
* @brief Print IE Parameters
* @param reference on IE Parameter
@@ -34,54 +24,54 @@ std::ostream& operator<<(std::ostream& stream, const std::vector<T>& v) {
*/
void printAnyValue(const ov::Any& value) {
if (value.empty()) {
std::cout << "EMPTY VALUE" << std::endl;
slog::info << "EMPTY VALUE" << slog::endl;
} else if (value.is<bool>()) {
std::cout << std::boolalpha << value.as<bool>() << std::noboolalpha << std::endl;
slog::info << std::boolalpha << value.as<bool>() << std::noboolalpha << slog::endl;
} else if (value.is<int>()) {
std::cout << value.as<int>() << std::endl;
slog::info << value.as<int>() << slog::endl;
} else if (value.is<unsigned int>()) {
std::cout << value.as<unsigned int>() << std::endl;
slog::info << value.as<unsigned int>() << slog::endl;
} else if (value.is<uint64_t>()) {
std::cout << value.as<uint64_t>() << std::endl;
slog::info << value.as<uint64_t>() << slog::endl;
} else if (value.is<float>()) {
std::cout << value.as<float>() << std::endl;
slog::info << value.as<float>() << slog::endl;
} else if (value.is<std::string>()) {
std::string stringValue = value.as<std::string>();
std::cout << (stringValue.empty() ? "\"\"" : stringValue) << std::endl;
slog::info << (stringValue.empty() ? "\"\"" : stringValue) << slog::endl;
} else if (value.is<std::vector<std::string>>()) {
std::cout << value.as<std::vector<std::string>>() << std::endl;
slog::info << value.as<std::vector<std::string>>() << slog::endl;
} else if (value.is<std::vector<int>>()) {
std::cout << value.as<std::vector<int>>() << std::endl;
slog::info << value.as<std::vector<int>>() << slog::endl;
} else if (value.is<std::vector<float>>()) {
std::cout << value.as<std::vector<float>>() << std::endl;
slog::info << value.as<std::vector<float>>() << slog::endl;
} else if (value.is<std::vector<unsigned int>>()) {
std::cout << value.as<std::vector<unsigned int>>() << std::endl;
slog::info << value.as<std::vector<unsigned int>>() << slog::endl;
} else if (value.is<std::tuple<unsigned int, unsigned int, unsigned int>>()) {
auto values = value.as<std::tuple<unsigned int, unsigned int, unsigned int>>();
std::cout << "{ ";
std::cout << std::get<0>(values) << ", ";
std::cout << std::get<1>(values) << ", ";
std::cout << std::get<2>(values);
std::cout << " }";
std::cout << std::endl;
slog::info << "{ ";
slog::info << std::get<0>(values) << ", ";
slog::info << std::get<1>(values) << ", ";
slog::info << std::get<2>(values);
slog::info << " }";
slog::info << slog::endl;
} else if (value.is<InferenceEngine::Metrics::DeviceType>()) {
auto v = value.as<InferenceEngine::Metrics::DeviceType>();
std::cout << v << std::endl;
slog::info << v << slog::endl;
} else if (value.is<std::map<InferenceEngine::Precision, float>>()) {
auto values = value.as<std::map<InferenceEngine::Precision, float>>();
std::cout << "{ ";
slog::info << "{ ";
for (auto& kv : values) {
std::cout << kv.first << ": " << kv.second << "; ";
slog::info << kv.first << ": " << kv.second << "; ";
}
std::cout << " }";
std::cout << std::endl;
slog::info << " }";
slog::info << slog::endl;
} else if (value.is<std::tuple<unsigned int, unsigned int>>()) {
auto values = value.as<std::tuple<unsigned int, unsigned int>>();
std::cout << "{ ";
std::cout << std::get<0>(values) << ", ";
std::cout << std::get<1>(values);
std::cout << " }";
std::cout << std::endl;
slog::info << "{ ";
slog::info << std::get<0>(values) << ", ";
slog::info << std::get<1>(values);
slog::info << " }";
slog::info << slog::endl;
} else {
std::stringstream strm;
value.print(strm);
@@ -98,6 +88,9 @@ void printAnyValue(const ov::Any& value) {
int main(int argc, char* argv[]) {
try {
// -------- Get OpenVINO runtime version --------
slog::info << ov::get_openvino_version() << slog::endl;
// -------- Parsing and validation of input arguments --------
if (argc != 1) {
std::cout << "Usage : " << argv[0] << std::endl;
@@ -105,25 +98,22 @@ int main(int argc, char* argv[]) {
}
// -------- Step 1. Initialize OpenVINO Runtime Core --------
std::cout << "Loading OpenVINO Runtime" << std::endl;
ov::runtime::Core core;
// -------- Step 2. Get list of available devices --------
std::vector<std::string> availableDevices = core.get_available_devices();
// -------- Step 3. Query and print supported metrics and config keys --------
std::cout << "Available devices: " << std::endl;
slog::info << "Available devices: " << slog::endl;
for (auto&& device : availableDevices) {
std::cout << device << std::endl;
slog::info << device << slog::endl;
// Query supported metrics and print all of them
std::cout << "\tSUPPORTED_METRICS: " << std::endl;
slog::info << "\tSUPPORTED_METRICS: " << slog::endl;
std::vector<std::string> supportedMetrics = core.get_metric(device, METRIC_KEY(SUPPORTED_METRICS));
for (auto&& metricName : supportedMetrics) {
if (metricName != METRIC_KEY(SUPPORTED_METRICS) && metricName != METRIC_KEY(SUPPORTED_CONFIG_KEYS)) {
std::cout << "\t\t" << metricName << " : " << std::flush;
slog::info << "\t\t" << metricName << " : " << slog::flush;
printAnyValue(core.get_metric(device, metricName));
}
}
@@ -131,16 +121,16 @@ int main(int argc, char* argv[]) {
// Query supported config keys and print all of them
if (std::find(supportedMetrics.begin(), supportedMetrics.end(), METRIC_KEY(SUPPORTED_CONFIG_KEYS)) !=
supportedMetrics.end()) {
std::cout << "\tSUPPORTED_CONFIG_KEYS (default values): " << std::endl;
slog::info << "\tSUPPORTED_CONFIG_KEYS (default values): " << slog::endl;
std::vector<std::string> supportedConfigKeys =
core.get_metric(device, METRIC_KEY(SUPPORTED_CONFIG_KEYS));
for (auto&& configKey : supportedConfigKeys) {
std::cout << "\t\t" << configKey << " : " << std::flush;
slog::info << "\t\t" << configKey << " : " << slog::flush;
printAnyValue(core.get_config(device, configKey));
}
}
std::cout << std::endl;
slog::info << slog::endl;
}
} catch (const std::exception& ex) {
std::cerr << std::endl << "Exception occurred: " << ex.what() << std::endl << std::flush;