[IE Samples][OV2.0] final clean up of old API headers (#9494)
* final clean up of old API headers, compile_tool separated from samples * make cpplint happy
This commit is contained in:
parent
113014161d
commit
28fb55dffe
@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
|
||||
// clang-format off
|
||||
#include "openvino/openvino.hpp"
|
||||
#include "openvino/pass/serialize.hpp"
|
||||
|
||||
#include "gna/gna_config.hpp"
|
||||
@ -173,10 +174,8 @@ int main(int argc, char* argv[]) {
|
||||
ov::runtime::Core core;
|
||||
|
||||
if (FLAGS_d.find("CPU") != std::string::npos && !FLAGS_l.empty()) {
|
||||
// CPU (MKLDNN) extensions is loaded as a shared library and passed as a
|
||||
// pointer to base extension
|
||||
const auto extension_ptr = std::make_shared<InferenceEngine::Extension>(FLAGS_l);
|
||||
core.add_extension(extension_ptr);
|
||||
// CPU (MKLDNN) extensions is loaded as a shared library
|
||||
core.add_extension(FLAGS_l);
|
||||
slog::info << "CPU (MKLDNN) extensions is loaded " << FLAGS_l << slog::endl;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "inference_engine.hpp"
|
||||
#include "openvino/openvino.hpp"
|
||||
// clang-format on
|
||||
|
||||
@ -31,17 +30,6 @@ void readInputFilesArguments(std::vector<std::string>& files, const std::string&
|
||||
*/
|
||||
void parseInputFilesArguments(std::vector<std::string>& files);
|
||||
|
||||
void processPrecision(InferenceEngine::CNNNetwork& network,
|
||||
const std::string& ip,
|
||||
const std::string& op,
|
||||
const std::string& iop);
|
||||
|
||||
void processLayout(InferenceEngine::CNNNetwork& network,
|
||||
const std::string& il,
|
||||
const std::string& ol,
|
||||
const std::string& iol);
|
||||
|
||||
void printInputAndOutputsInfo(const InferenceEngine::CNNNetwork& network);
|
||||
void printInputAndOutputsInfo(const ov::Model& network);
|
||||
|
||||
void configurePrePostProcessing(std::shared_ptr<ov::Model>& function,
|
||||
@ -55,7 +43,6 @@ void configurePrePostProcessing(std::shared_ptr<ov::Model>& function,
|
||||
const std::string& oml,
|
||||
const std::string& ioml);
|
||||
|
||||
//--- API 2.0 -------------------------------------------------------------------------
|
||||
void printInputAndOutputsInfo(const ov::Model& network);
|
||||
void printInputAndOutputsInfoShort(const ov::Model& network);
|
||||
void processPrecision(const ov::Model& network, const std::string& ip, const std::string& op, const std::string& iop);
|
||||
|
@ -17,14 +17,12 @@
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <openvino/openvino.hpp>
|
||||
#include <random>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
// clang-format off
|
||||
#include "inference_engine.hpp"
|
||||
#include "openvino/openvino.hpp"
|
||||
#include "slog.hpp"
|
||||
// clang-format on
|
||||
@ -124,16 +122,6 @@ inline std::string fileExt(const std::string& filename) {
|
||||
return filename.substr(pos + 1);
|
||||
}
|
||||
|
||||
inline slog::LogStream& operator<<(slog::LogStream& os, const InferenceEngine::Version& version) {
|
||||
os << version.description << " version ......... ";
|
||||
os << IE_VERSION_MAJOR << "." << IE_VERSION_MINOR << "." << IE_VERSION_PATCH << slog::endl;
|
||||
|
||||
os << "Build ........... ";
|
||||
os << version.buildNumber << slog::endl;
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
inline slog::LogStream& operator<<(slog::LogStream& os, const ov::Version& version) {
|
||||
os << version.description << " version ......... ";
|
||||
os << OPENVINO_VERSION_MAJOR << "." << OPENVINO_VERSION_MINOR << "." << OPENVINO_VERSION_PATCH << slog::endl;
|
||||
@ -144,16 +132,6 @@ inline slog::LogStream& operator<<(slog::LogStream& os, const ov::Version& versi
|
||||
return os;
|
||||
}
|
||||
|
||||
inline slog::LogStream& operator<<(slog::LogStream& os,
|
||||
const std::map<std::string, InferenceEngine::Version>& versions) {
|
||||
for (auto&& version : versions) {
|
||||
os << version.first << slog::endl;
|
||||
os << version.second << slog::endl;
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
inline slog::LogStream& operator<<(slog::LogStream& os, const std::map<std::string, ov::Version>& versions) {
|
||||
for (auto&& version : versions) {
|
||||
os << version.first << slog::endl;
|
||||
@ -621,49 +599,6 @@ static UNUSED void printPerformanceCounts(const std::map<std::string, ov::runtim
|
||||
std::cout.flags(fmt);
|
||||
}
|
||||
|
||||
// static UNUSED void printPerformanceCounts(InferenceEngine::InferRequest request,
|
||||
// std::ostream& stream,
|
||||
// std::string deviceName,
|
||||
// bool bshowHeader = true) {
|
||||
// auto performanceMap = request.GetPerformanceCounts();
|
||||
// printPerformanceCounts(performanceMap, stream, deviceName, bshowHeader);
|
||||
//}
|
||||
|
||||
inline std::map<std::string, std::string> getMapFullDevicesNames(InferenceEngine::Core& ie,
|
||||
std::vector<std::string> devices) {
|
||||
std::map<std::string, std::string> devicesMap;
|
||||
InferenceEngine::Parameter p;
|
||||
for (std::string& deviceName : devices) {
|
||||
if (deviceName != "") {
|
||||
try {
|
||||
p = ie.GetMetric(deviceName, METRIC_KEY(FULL_DEVICE_NAME));
|
||||
devicesMap.insert(std::pair<std::string, std::string>(deviceName, p.as<std::string>()));
|
||||
} catch (InferenceEngine::Exception&) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return devicesMap;
|
||||
}
|
||||
|
||||
inline std::string getFullDeviceName(std::map<std::string, std::string>& devicesMap, std::string device) {
|
||||
std::map<std::string, std::string>::iterator it = devicesMap.find(device);
|
||||
if (it != devicesMap.end()) {
|
||||
return it->second;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string getFullDeviceName(InferenceEngine::Core& ie, std::string device) {
|
||||
InferenceEngine::Parameter p;
|
||||
try {
|
||||
p = ie.GetMetric(device, METRIC_KEY(FULL_DEVICE_NAME));
|
||||
return p.as<std::string>();
|
||||
} catch (InferenceEngine::Exception&) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This class represents an object that is found by an object detection net
|
||||
*/
|
||||
@ -1019,97 +954,6 @@ static UNUSED void addRectangles(unsigned char* data,
|
||||
}
|
||||
}
|
||||
|
||||
inline std::size_t getTensorWidth(const InferenceEngine::TensorDesc& desc) {
|
||||
const auto& layout = desc.getLayout();
|
||||
const auto& dims = desc.getDims();
|
||||
const auto& size = dims.size();
|
||||
if ((size >= 2) && (layout == InferenceEngine::Layout::NCHW || layout == InferenceEngine::Layout::NHWC ||
|
||||
layout == InferenceEngine::Layout::NCDHW || layout == InferenceEngine::Layout::NDHWC ||
|
||||
layout == InferenceEngine::Layout::OIHW || layout == InferenceEngine::Layout::GOIHW ||
|
||||
layout == InferenceEngine::Layout::OIDHW || layout == InferenceEngine::Layout::GOIDHW ||
|
||||
layout == InferenceEngine::Layout::CHW || layout == InferenceEngine::Layout::HW)) {
|
||||
// Regardless of layout, dimensions are stored in fixed order
|
||||
return dims.back();
|
||||
} else {
|
||||
IE_THROW() << "Tensor does not have width dimension";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline std::size_t getTensorHeight(const InferenceEngine::TensorDesc& desc) {
|
||||
const auto& layout = desc.getLayout();
|
||||
const auto& dims = desc.getDims();
|
||||
const auto& size = dims.size();
|
||||
if ((size >= 2) && (layout == InferenceEngine::Layout::NCHW || layout == InferenceEngine::Layout::NHWC ||
|
||||
layout == InferenceEngine::Layout::NCDHW || layout == InferenceEngine::Layout::NDHWC ||
|
||||
layout == InferenceEngine::Layout::OIHW || layout == InferenceEngine::Layout::GOIHW ||
|
||||
layout == InferenceEngine::Layout::OIDHW || layout == InferenceEngine::Layout::GOIDHW ||
|
||||
layout == InferenceEngine::Layout::CHW || layout == InferenceEngine::Layout::HW)) {
|
||||
// Regardless of layout, dimensions are stored in fixed order
|
||||
return dims.at(size - 2);
|
||||
} else {
|
||||
IE_THROW() << "Tensor does not have height dimension";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline std::size_t getTensorChannels(const InferenceEngine::TensorDesc& desc) {
|
||||
const auto& layout = desc.getLayout();
|
||||
if (layout == InferenceEngine::Layout::NCHW || layout == InferenceEngine::Layout::NHWC ||
|
||||
layout == InferenceEngine::Layout::NCDHW || layout == InferenceEngine::Layout::NDHWC ||
|
||||
layout == InferenceEngine::Layout::C || layout == InferenceEngine::Layout::CHW ||
|
||||
layout == InferenceEngine::Layout::NC || layout == InferenceEngine::Layout::CN) {
|
||||
// Regardless of layout, dimensions are stored in fixed order
|
||||
const auto& dims = desc.getDims();
|
||||
switch (desc.getLayoutByDims(dims)) {
|
||||
case InferenceEngine::Layout::C:
|
||||
return dims.at(0);
|
||||
case InferenceEngine::Layout::NC:
|
||||
return dims.at(1);
|
||||
case InferenceEngine::Layout::CHW:
|
||||
return dims.at(0);
|
||||
case InferenceEngine::Layout::NCHW:
|
||||
return dims.at(1);
|
||||
case InferenceEngine::Layout::NCDHW:
|
||||
return dims.at(1);
|
||||
case InferenceEngine::Layout::SCALAR: // [[fallthrough]]
|
||||
case InferenceEngine::Layout::BLOCKED: // [[fallthrough]]
|
||||
default:
|
||||
IE_THROW() << "Tensor does not have channels dimension";
|
||||
}
|
||||
} else {
|
||||
IE_THROW() << "Tensor does not have channels dimension";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline std::size_t getTensorBatch(const InferenceEngine::TensorDesc& desc) {
|
||||
const auto& layout = desc.getLayout();
|
||||
if (layout == InferenceEngine::Layout::NCHW || layout == InferenceEngine::Layout::NHWC ||
|
||||
layout == InferenceEngine::Layout::NCDHW || layout == InferenceEngine::Layout::NDHWC ||
|
||||
layout == InferenceEngine::Layout::NC || layout == InferenceEngine::Layout::CN) {
|
||||
// Regardless of layout, dimensions are stored in fixed order
|
||||
const auto& dims = desc.getDims();
|
||||
switch (desc.getLayoutByDims(dims)) {
|
||||
case InferenceEngine::Layout::NC:
|
||||
return dims.at(0);
|
||||
case InferenceEngine::Layout::NCHW:
|
||||
return dims.at(0);
|
||||
case InferenceEngine::Layout::NCDHW:
|
||||
return dims.at(0);
|
||||
case InferenceEngine::Layout::CHW: // [[fallthrough]]
|
||||
case InferenceEngine::Layout::C: // [[fallthrough]]
|
||||
case InferenceEngine::Layout::SCALAR: // [[fallthrough]]
|
||||
case InferenceEngine::Layout::BLOCKED: // [[fallthrough]]
|
||||
default:
|
||||
IE_THROW() << "Tensor does not have channels dimension";
|
||||
}
|
||||
} else {
|
||||
IE_THROW() << "Tensor does not have channels dimension";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void showAvailableDevices() {
|
||||
ov::runtime::Core core;
|
||||
std::vector<std::string> devices = core.get_available_devices();
|
||||
@ -1132,13 +976,12 @@ inline void showAvailableDevices() {
|
||||
*/
|
||||
std::map<std::string, std::string> parseConfig(const std::string& configName, char comment = '#');
|
||||
|
||||
//--- API 2.0 --------------------------------------------------------------------------------------
|
||||
inline std::string getFullDeviceName(ov::runtime::Core& core, std::string device) {
|
||||
InferenceEngine::Parameter p;
|
||||
ov::Any p;
|
||||
try {
|
||||
p = core.get_metric(device, METRIC_KEY(FULL_DEVICE_NAME));
|
||||
return p.as<std::string>();
|
||||
} catch (InferenceEngine::Exception&) {
|
||||
} catch (ov::Exception&) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
@ -174,29 +174,6 @@ InferenceEngine::Precision getPrecision(const std::string& value) {
|
||||
return getPrecision(value, supported_precisions);
|
||||
}
|
||||
|
||||
void setPrecisions(const InferenceEngine::CNNNetwork& network, const std::string& iop) {
|
||||
const auto user_precisions_map = parseArgMap(iop);
|
||||
|
||||
auto inputs = network.getInputsInfo();
|
||||
auto outputs = network.getOutputsInfo();
|
||||
|
||||
for (auto&& item : user_precisions_map) {
|
||||
const auto& layer_name = item.first;
|
||||
const auto& user_precision = item.second;
|
||||
|
||||
const auto input = inputs.find(layer_name);
|
||||
const auto output = outputs.find(layer_name);
|
||||
|
||||
if (input != inputs.end()) {
|
||||
input->second->setPrecision(getPrecision(user_precision));
|
||||
} else if (output != outputs.end()) {
|
||||
output->second->setPrecision(getPrecision(user_precision));
|
||||
} else {
|
||||
throw std::logic_error(layer_name + " is not an input neither output");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
using supported_type_t = std::unordered_map<std::string, ov::element::Type>;
|
||||
ov::element::Type getType(std::string value, const supported_type_t& supported_precisions) {
|
||||
std::transform(value.begin(), value.end(), value.begin(), ::toupper);
|
||||
@ -225,29 +202,6 @@ ov::element::Type getType(const std::string& value) {
|
||||
|
||||
} // namespace
|
||||
|
||||
void processPrecision(InferenceEngine::CNNNetwork& network,
|
||||
const std::string& ip,
|
||||
const std::string& op,
|
||||
const std::string& iop) {
|
||||
if (!ip.empty()) {
|
||||
const auto user_precision = getPrecision(ip);
|
||||
for (auto&& layer : network.getInputsInfo()) {
|
||||
layer.second->setPrecision(user_precision);
|
||||
}
|
||||
}
|
||||
|
||||
if (!op.empty()) {
|
||||
auto user_precision = getPrecision(op);
|
||||
for (auto&& layer : network.getOutputsInfo()) {
|
||||
layer.second->setPrecision(user_precision);
|
||||
}
|
||||
}
|
||||
|
||||
if (!iop.empty()) {
|
||||
setPrecisions(network, iop);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
using supported_layouts_t = std::unordered_map<std::string, InferenceEngine::Layout>;
|
||||
using matchLayoutToDims_t = std::unordered_map<size_t, size_t>;
|
||||
@ -295,79 +249,8 @@ bool isMatchLayoutToDims(InferenceEngine::Layout layout, size_t dimension) {
|
||||
return dimension == dims->second;
|
||||
}
|
||||
|
||||
void setLayouts(const InferenceEngine::CNNNetwork& network, const std::string iol) {
|
||||
const auto user_layouts_map = parseArgMap(iol);
|
||||
|
||||
auto inputs = network.getInputsInfo();
|
||||
auto outputs = network.getOutputsInfo();
|
||||
|
||||
for (auto&& item : user_layouts_map) {
|
||||
const auto& layer_name = item.first;
|
||||
const auto& user_layout = getLayout(item.second);
|
||||
|
||||
const auto input = inputs.find(layer_name);
|
||||
const auto output = outputs.find(layer_name);
|
||||
|
||||
if (input != inputs.end()) {
|
||||
if (!isMatchLayoutToDims(user_layout, input->second->getTensorDesc().getDims().size())) {
|
||||
throw std::logic_error(item.second + " layout is not applicable to " + layer_name);
|
||||
}
|
||||
|
||||
input->second->setLayout(user_layout);
|
||||
} else if (output != outputs.end()) {
|
||||
if (!isMatchLayoutToDims(user_layout, output->second->getTensorDesc().getDims().size())) {
|
||||
throw std::logic_error(item.second + " layout is not applicable to " + layer_name);
|
||||
}
|
||||
|
||||
output->second->setLayout(user_layout);
|
||||
} else {
|
||||
throw std::logic_error(layer_name + " is not an input neither output");
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void processLayout(InferenceEngine::CNNNetwork& network,
|
||||
const std::string& il,
|
||||
const std::string& ol,
|
||||
const std::string& iol) {
|
||||
if (!il.empty()) {
|
||||
const auto layout = getLayout(il);
|
||||
for (auto&& layer : network.getInputsInfo()) {
|
||||
if (isMatchLayoutToDims(layout, layer.second->getTensorDesc().getDims().size())) {
|
||||
layer.second->setLayout(layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ol.empty()) {
|
||||
const auto layout = getLayout(ol);
|
||||
for (auto&& layer : network.getOutputsInfo()) {
|
||||
if (isMatchLayoutToDims(layout, layer.second->getTensorDesc().getDims().size())) {
|
||||
layer.second->setLayout(layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!iol.empty()) {
|
||||
setLayouts(network, iol);
|
||||
}
|
||||
}
|
||||
|
||||
void printInputAndOutputsInfo(const InferenceEngine::CNNNetwork& network) {
|
||||
std::cout << "Network inputs:" << std::endl;
|
||||
for (auto&& layer : network.getInputsInfo()) {
|
||||
std::cout << " " << layer.first << " : " << layer.second->getPrecision() << " / "
|
||||
<< layer.second->getLayout() << std::endl;
|
||||
}
|
||||
std::cout << "Network outputs:" << std::endl;
|
||||
for (auto&& layer : network.getOutputsInfo()) {
|
||||
std::cout << " " << layer.first << " : " << layer.second->getPrecision() << " / "
|
||||
<< layer.second->getLayout() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//--- API 2.0 -------------------------------------------------------------------------------------
|
||||
void printInputAndOutputsInfoShort(const ov::Model& network) {
|
||||
std::cout << "Network inputs:" << std::endl;
|
||||
for (auto&& param : network.get_parameters()) {
|
||||
|
@ -2,21 +2,18 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#include <format_reader_ptr.h>
|
||||
|
||||
#include <inference_engine.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
// clang-format off
|
||||
#include "ngraph/ngraph.hpp"
|
||||
#include "openvino/openvino.hpp"
|
||||
#include "ngraph/ngraph.hpp"
|
||||
|
||||
#include "format_reader_ptr.h"
|
||||
#include "samples/args_helper.hpp"
|
||||
#include "samples/common.hpp"
|
||||
#include "samples/slog.hpp"
|
||||
#include "format_reader_ptr.h"
|
||||
// clang-format on
|
||||
|
||||
// thickness of a line (in pixels) to be used for bounding boxes
|
||||
|
@ -20,9 +20,6 @@
|
||||
#include <vpu/private_plugin_config.hpp>
|
||||
#include <vpu/utils/string.hpp>
|
||||
|
||||
#include "samples/common.hpp"
|
||||
#include "samples/args_helper.hpp"
|
||||
|
||||
static constexpr char help_message[] =
|
||||
"Optional. Print the usage message.";
|
||||
|
||||
@ -120,6 +117,425 @@ DEFINE_string(VPU_NUMBER_OF_SHAVES, "", number_of_shaves_message);
|
||||
DEFINE_string(VPU_NUMBER_OF_CMX_SLICES, "", number_of_cmx_slices_message);
|
||||
DEFINE_string(VPU_TILING_CMX_LIMIT_KB, "", tiling_cmx_limit_message);
|
||||
|
||||
|
||||
namespace {
|
||||
std::vector<std::string> splitStringList(const std::string& str, char delim) {
|
||||
if (str.empty())
|
||||
return {};
|
||||
|
||||
std::istringstream istr(str);
|
||||
|
||||
std::vector<std::string> result;
|
||||
std::string elem;
|
||||
while (std::getline(istr, elem, delim)) {
|
||||
if (elem.empty()) {
|
||||
continue;
|
||||
}
|
||||
result.emplace_back(std::move(elem));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> parseArgMap(std::string argMap) {
|
||||
argMap.erase(std::remove_if(argMap.begin(), argMap.end(), ::isspace), argMap.end());
|
||||
|
||||
const auto pairs = splitStringList(argMap, ',');
|
||||
|
||||
std::map<std::string, std::string> parsedMap;
|
||||
for (auto&& pair : pairs) {
|
||||
const auto lastDelimPos = pair.find_last_of(':');
|
||||
auto key = pair.substr(0, lastDelimPos);
|
||||
auto value = pair.substr(lastDelimPos + 1);
|
||||
|
||||
if (lastDelimPos == std::string::npos || key.empty() || value.empty()) {
|
||||
throw std::invalid_argument("Invalid key/value pair " + pair + ". Expected <layer_name>:<value>");
|
||||
}
|
||||
|
||||
parsedMap[std::move(key)] = std::move(value);
|
||||
}
|
||||
|
||||
return parsedMap;
|
||||
}
|
||||
|
||||
using supported_precisions_t = std::unordered_map<std::string, InferenceEngine::Precision>;
|
||||
|
||||
InferenceEngine::Precision getPrecision(std::string value, const supported_precisions_t& supported_precisions) {
|
||||
std::transform(value.begin(), value.end(), value.begin(), ::toupper);
|
||||
|
||||
const auto precision = supported_precisions.find(value);
|
||||
if (precision == supported_precisions.end()) {
|
||||
throw std::logic_error("\"" + value + "\"" + " is not a valid precision");
|
||||
}
|
||||
|
||||
return precision->second;
|
||||
}
|
||||
|
||||
InferenceEngine::Precision getPrecision(const std::string& value) {
|
||||
static const supported_precisions_t supported_precisions = {
|
||||
{"FP32", InferenceEngine::Precision::FP32}, {"f32", InferenceEngine::Precision::FP32},
|
||||
{"FP16", InferenceEngine::Precision::FP16}, {"f16", InferenceEngine::Precision::FP16},
|
||||
{"BF16", InferenceEngine::Precision::BF16}, {"bf16", InferenceEngine::Precision::BF16},
|
||||
{"U64", InferenceEngine::Precision::U64}, {"u64", InferenceEngine::Precision::U64},
|
||||
{"I64", InferenceEngine::Precision::I64}, {"i64", InferenceEngine::Precision::I64},
|
||||
{"U32", InferenceEngine::Precision::U32}, {"u32", InferenceEngine::Precision::U32},
|
||||
{"I32", InferenceEngine::Precision::I32}, {"i32", InferenceEngine::Precision::I32},
|
||||
{"U16", InferenceEngine::Precision::U16}, {"u16", InferenceEngine::Precision::U16},
|
||||
{"I16", InferenceEngine::Precision::I16}, {"i16", InferenceEngine::Precision::I16},
|
||||
{"U8", InferenceEngine::Precision::U8}, {"u8", InferenceEngine::Precision::U8},
|
||||
{"I8", InferenceEngine::Precision::I8}, {"i8", InferenceEngine::Precision::I8},
|
||||
{"BOOL", InferenceEngine::Precision::BOOL}, {"boolean", InferenceEngine::Precision::BOOL},
|
||||
};
|
||||
|
||||
return getPrecision(value, supported_precisions);
|
||||
}
|
||||
|
||||
void setPrecisions(const InferenceEngine::CNNNetwork& network, const std::string& iop) {
|
||||
const auto user_precisions_map = parseArgMap(iop);
|
||||
|
||||
auto inputs = network.getInputsInfo();
|
||||
auto outputs = network.getOutputsInfo();
|
||||
|
||||
for (auto&& item : user_precisions_map) {
|
||||
const auto& layer_name = item.first;
|
||||
const auto& user_precision = item.second;
|
||||
|
||||
const auto input = inputs.find(layer_name);
|
||||
const auto output = outputs.find(layer_name);
|
||||
|
||||
if (input != inputs.end()) {
|
||||
input->second->setPrecision(getPrecision(user_precision));
|
||||
} else if (output != outputs.end()) {
|
||||
output->second->setPrecision(getPrecision(user_precision));
|
||||
} else {
|
||||
throw std::logic_error(layer_name + " is not an input neither output");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} //namespace
|
||||
|
||||
|
||||
void processPrecision(InferenceEngine::CNNNetwork& network,
|
||||
const std::string& ip,
|
||||
const std::string& op,
|
||||
const std::string& iop) {
|
||||
if (!ip.empty()) {
|
||||
const auto user_precision = getPrecision(ip);
|
||||
for (auto&& layer : network.getInputsInfo()) {
|
||||
layer.second->setPrecision(user_precision);
|
||||
}
|
||||
}
|
||||
|
||||
if (!op.empty()) {
|
||||
auto user_precision = getPrecision(op);
|
||||
for (auto&& layer : network.getOutputsInfo()) {
|
||||
layer.second->setPrecision(user_precision);
|
||||
}
|
||||
}
|
||||
|
||||
if (!iop.empty()) {
|
||||
setPrecisions(network, iop);
|
||||
}
|
||||
}
|
||||
|
||||
using supported_layouts_t = std::unordered_map<std::string, InferenceEngine::Layout>;
|
||||
using matchLayoutToDims_t = std::unordered_map<size_t, size_t>;
|
||||
|
||||
InferenceEngine::Layout getLayout(std::string value, const supported_layouts_t& supported_layouts) {
|
||||
std::transform(value.begin(), value.end(), value.begin(), ::toupper);
|
||||
|
||||
const auto layout = supported_layouts.find(value);
|
||||
if (layout == supported_layouts.end()) {
|
||||
throw std::logic_error("\"" + value + "\"" + " is not a valid layout");
|
||||
}
|
||||
|
||||
return layout->second;
|
||||
}
|
||||
|
||||
InferenceEngine::Layout getLayout(const std::string& value) {
|
||||
static const supported_layouts_t supported_layouts = {
|
||||
{"NCDHW", InferenceEngine::Layout::NCDHW},
|
||||
{"NDHWC", InferenceEngine::Layout::NDHWC},
|
||||
{"NCHW", InferenceEngine::Layout::NCHW},
|
||||
{"NHWC", InferenceEngine::Layout::NHWC},
|
||||
{"CHW", InferenceEngine::Layout::CHW},
|
||||
{"HWC", InferenceEngine::Layout::HWC},
|
||||
{"NC", InferenceEngine::Layout::NC},
|
||||
{"C", InferenceEngine::Layout::C},
|
||||
};
|
||||
|
||||
return getLayout(value, supported_layouts);
|
||||
}
|
||||
|
||||
bool isMatchLayoutToDims(InferenceEngine::Layout layout, size_t dimension) {
|
||||
static const matchLayoutToDims_t matchLayoutToDims = { {static_cast<size_t>(InferenceEngine::Layout::NCDHW), 5},
|
||||
{static_cast<size_t>(InferenceEngine::Layout::NDHWC), 5},
|
||||
{static_cast<size_t>(InferenceEngine::Layout::NCHW), 4},
|
||||
{static_cast<size_t>(InferenceEngine::Layout::NHWC), 4},
|
||||
{static_cast<size_t>(InferenceEngine::Layout::CHW), 3},
|
||||
{static_cast<size_t>(InferenceEngine::Layout::NC), 2},
|
||||
{static_cast<size_t>(InferenceEngine::Layout::C), 1} };
|
||||
|
||||
const auto dims = matchLayoutToDims.find(static_cast<size_t>(layout));
|
||||
if (dims == matchLayoutToDims.end()) {
|
||||
throw std::logic_error("Layout is not valid.");
|
||||
}
|
||||
|
||||
return dimension == dims->second;
|
||||
}
|
||||
|
||||
void setLayouts(const InferenceEngine::CNNNetwork& network, const std::string iol) {
|
||||
const auto user_layouts_map = parseArgMap(iol);
|
||||
|
||||
auto inputs = network.getInputsInfo();
|
||||
auto outputs = network.getOutputsInfo();
|
||||
|
||||
for (auto&& item : user_layouts_map) {
|
||||
const auto& layer_name = item.first;
|
||||
const auto& user_layout = getLayout(item.second);
|
||||
|
||||
const auto input = inputs.find(layer_name);
|
||||
const auto output = outputs.find(layer_name);
|
||||
|
||||
if (input != inputs.end()) {
|
||||
if (!isMatchLayoutToDims(user_layout, input->second->getTensorDesc().getDims().size())) {
|
||||
throw std::logic_error(item.second + " layout is not applicable to " + layer_name);
|
||||
}
|
||||
|
||||
input->second->setLayout(user_layout);
|
||||
} else if (output != outputs.end()) {
|
||||
if (!isMatchLayoutToDims(user_layout, output->second->getTensorDesc().getDims().size())) {
|
||||
throw std::logic_error(item.second + " layout is not applicable to " + layer_name);
|
||||
}
|
||||
|
||||
output->second->setLayout(user_layout);
|
||||
} else {
|
||||
throw std::logic_error(layer_name + " is not an input neither output");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void processLayout(InferenceEngine::CNNNetwork& network,
|
||||
const std::string& il,
|
||||
const std::string& ol,
|
||||
const std::string& iol) {
|
||||
if (!il.empty()) {
|
||||
const auto layout = getLayout(il);
|
||||
for (auto&& layer : network.getInputsInfo()) {
|
||||
if (isMatchLayoutToDims(layout, layer.second->getTensorDesc().getDims().size())) {
|
||||
layer.second->setLayout(layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!ol.empty()) {
|
||||
const auto layout = getLayout(ol);
|
||||
for (auto&& layer : network.getOutputsInfo()) {
|
||||
if (isMatchLayoutToDims(layout, layer.second->getTensorDesc().getDims().size())) {
|
||||
layer.second->setLayout(layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!iol.empty()) {
|
||||
setLayouts(network, iol);
|
||||
}
|
||||
}
|
||||
|
||||
using supported_type_t = std::unordered_map<std::string, ov::element::Type>;
|
||||
ov::element::Type getType(std::string value, const supported_type_t& supported_precisions) {
|
||||
std::transform(value.begin(), value.end(), value.begin(), ::toupper);
|
||||
|
||||
const auto precision = supported_precisions.find(value);
|
||||
if (precision == supported_precisions.end()) {
|
||||
throw std::logic_error("\"" + value + "\"" + " is not a valid precision");
|
||||
}
|
||||
|
||||
return precision->second;
|
||||
}
|
||||
ov::element::Type getType(const std::string& value) {
|
||||
static const supported_type_t supported_types = {
|
||||
{"FP32", ov::element::f32}, {"f32", ov::element::f32}, {"FP16", ov::element::f16},
|
||||
{"f16", ov::element::f16}, {"BF16", ov::element::bf16}, {"bf16", ov::element::bf16},
|
||||
{"U64", ov::element::u64}, {"u64", ov::element::u64}, {"I64", ov::element::i64},
|
||||
{"i64", ov::element::i64}, {"U32", ov::element::u32}, {"u32", ov::element::u32},
|
||||
{"I32", ov::element::i32}, {"i32", ov::element::i32}, {"U16", ov::element::u16},
|
||||
{"u16", ov::element::u16}, {"I16", ov::element::i16}, {"i16", ov::element::i16},
|
||||
{"U8", ov::element::u8}, {"u8", ov::element::u8}, {"I8", ov::element::i8},
|
||||
{"i8", ov::element::i8}, {"BOOL", ov::element::boolean}, {"boolean", ov::element::boolean},
|
||||
};
|
||||
|
||||
return getType(value, supported_types);
|
||||
}
|
||||
|
||||
void configurePrePostProcessing(std::shared_ptr<ov::Model>& model,
|
||||
const std::string& ip,
|
||||
const std::string& op,
|
||||
const std::string& iop,
|
||||
const std::string& il,
|
||||
const std::string& ol,
|
||||
const std::string& iol,
|
||||
const std::string& iml,
|
||||
const std::string& oml,
|
||||
const std::string& ioml) {
|
||||
auto preprocessor = ov::preprocess::PrePostProcessor(model);
|
||||
const auto inputs = model->inputs();
|
||||
const auto outputs = model->outputs();
|
||||
if (!ip.empty()) {
|
||||
auto type = getType(ip);
|
||||
for (size_t i = 0; i < inputs.size(); i++) {
|
||||
preprocessor.input(i).tensor().set_element_type(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (!op.empty()) {
|
||||
auto type = getType(op);
|
||||
for (size_t i = 0; i < outputs.size(); i++) {
|
||||
preprocessor.output(i).tensor().set_element_type(type);
|
||||
}
|
||||
}
|
||||
|
||||
if (!iop.empty()) {
|
||||
const auto user_precisions_map = parseArgMap(iop);
|
||||
for (auto&& item : user_precisions_map) {
|
||||
const auto& tensor_name = item.first;
|
||||
const auto type = getType(item.second);
|
||||
|
||||
bool tensorFound = false;
|
||||
for (size_t i = 0; i < inputs.size(); i++) {
|
||||
if (inputs[i].get_names().count(tensor_name)) {
|
||||
preprocessor.input(i).tensor().set_element_type(type);
|
||||
tensorFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!tensorFound) {
|
||||
for (size_t i = 0; i < outputs.size(); i++) {
|
||||
if (outputs[i].get_names().count(tensor_name)) {
|
||||
preprocessor.output(i).tensor().set_element_type(type);
|
||||
tensorFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
OPENVINO_ASSERT(!tensorFound, "Model doesn't have input/output with tensor name: ", tensor_name);
|
||||
}
|
||||
}
|
||||
if (!il.empty()) {
|
||||
for (size_t i = 0; i < inputs.size(); i++) {
|
||||
preprocessor.input(i).tensor().set_layout(ov::Layout(il));
|
||||
}
|
||||
}
|
||||
|
||||
if (!ol.empty()) {
|
||||
for (size_t i = 0; i < outputs.size(); i++) {
|
||||
preprocessor.output(i).tensor().set_layout(ov::Layout(ol));
|
||||
}
|
||||
}
|
||||
|
||||
if (!iol.empty()) {
|
||||
const auto user_precisions_map = parseArgMap(iol);
|
||||
for (auto&& item : user_precisions_map) {
|
||||
const auto& tensor_name = item.first;
|
||||
|
||||
bool tensorFound = false;
|
||||
for (size_t i = 0; i < inputs.size(); i++) {
|
||||
if (inputs[i].get_names().count(tensor_name)) {
|
||||
preprocessor.input(i).tensor().set_layout(ov::Layout(item.second));
|
||||
tensorFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!tensorFound) {
|
||||
for (size_t i = 0; i < outputs.size(); i++) {
|
||||
if (outputs[i].get_names().count(tensor_name)) {
|
||||
preprocessor.output(i).tensor().set_layout(ov::Layout(item.second));
|
||||
tensorFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
OPENVINO_ASSERT(!tensorFound, "Model doesn't have input/output with tensor name: ", tensor_name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!iml.empty()) {
|
||||
for (size_t i = 0; i < inputs.size(); i++) {
|
||||
preprocessor.input(i).model().set_layout(ov::Layout(iml));
|
||||
}
|
||||
}
|
||||
|
||||
if (!oml.empty()) {
|
||||
for (size_t i = 0; i < outputs.size(); i++) {
|
||||
preprocessor.output(i).model().set_layout(ov::Layout(oml));
|
||||
}
|
||||
}
|
||||
|
||||
if (!ioml.empty()) {
|
||||
const auto user_precisions_map = parseArgMap(ioml);
|
||||
for (auto&& item : user_precisions_map) {
|
||||
const auto& tensor_name = item.first;
|
||||
|
||||
bool tensorFound = false;
|
||||
for (size_t i = 0; i < inputs.size(); i++) {
|
||||
if (inputs[i].get_names().count(tensor_name)) {
|
||||
preprocessor.input(i).model().set_layout(ov::Layout(item.second));
|
||||
tensorFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!tensorFound) {
|
||||
for (size_t i = 0; i < outputs.size(); i++) {
|
||||
if (outputs[i].get_names().count(tensor_name)) {
|
||||
preprocessor.output(i).model().set_layout(ov::Layout(item.second));
|
||||
tensorFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
OPENVINO_ASSERT(!tensorFound, "Model doesn't have input/output with tensor name: ", tensor_name);
|
||||
}
|
||||
}
|
||||
|
||||
model = preprocessor.build();
|
||||
}
|
||||
|
||||
void printInputAndOutputsInfo(const InferenceEngine::CNNNetwork& network) {
|
||||
std::cout << "Network inputs:" << std::endl;
|
||||
for (auto&& layer : network.getInputsInfo()) {
|
||||
std::cout << " " << layer.first << " : " << layer.second->getPrecision() << " / "
|
||||
<< layer.second->getLayout() << std::endl;
|
||||
}
|
||||
std::cout << "Network outputs:" << std::endl;
|
||||
for (auto&& layer : network.getOutputsInfo()) {
|
||||
std::cout << " " << layer.first << " : " << layer.second->getPrecision() << " / "
|
||||
<< layer.second->getLayout() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void printInputAndOutputsInfoShort(const ov::Model& network) {
|
||||
std::cout << "Network inputs:" << std::endl;
|
||||
for (auto&& param : network.get_parameters()) {
|
||||
auto l = param->get_layout();
|
||||
std::cout << " " << param->get_friendly_name() << " : " << param->get_element_type() << " / "
|
||||
<< param->get_layout().to_string() << std::endl;
|
||||
}
|
||||
std::cout << "Network outputs:" << std::endl;
|
||||
for (auto&& result : network.get_results()) {
|
||||
std::cout << " " << result->get_friendly_name() << " : " << result->get_element_type() << " / "
|
||||
<< result->get_layout().to_string() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string fileNameNoExt(const std::string& filepath) {
|
||||
auto pos = filepath.rfind('.');
|
||||
if (pos == std::string::npos)
|
||||
return filepath;
|
||||
return filepath.substr(0, pos);
|
||||
}
|
||||
|
||||
|
||||
static void showUsage() {
|
||||
std::cout << "compile_tool [OPTIONS]" << std::endl;
|
||||
std::cout << std::endl;
|
||||
@ -337,7 +753,7 @@ int main(int argc, char* argv[]) {
|
||||
auto model = core.read_model(FLAGS_m);
|
||||
|
||||
configurePrePostProcessing(model, FLAGS_ip, FLAGS_op, FLAGS_iop, FLAGS_il, FLAGS_ol, FLAGS_iol, FLAGS_iml, FLAGS_oml, FLAGS_ioml);
|
||||
printInputAndOutputsInfo(*model);
|
||||
printInputAndOutputsInfoShort(*model);
|
||||
auto timeBeforeLoadNetwork = std::chrono::steady_clock::now();
|
||||
auto compiledModel = core.compile_model(model, FLAGS_d, configure());
|
||||
loadNetworkTimeElapsed = std::chrono::duration_cast<TimeDiff>(std::chrono::steady_clock::now() - timeBeforeLoadNetwork);
|
||||
|
Loading…
Reference in New Issue
Block a user