mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge pull request #22957 from dkurt:new_openvino_api
Switch to new OpenVINO API after 2022.1 release * Pass Layer_Test_Convolution_DLDT.Accuracy/0 test * Pass test Test_Caffe_layers.Softmax * Failed 136 tests * Fix Concat. Failed 120 tests * Custom nGraph ops. 19 failed tests * Set and get properties from Core * Read model from buffer * Change MaxPooling layer output names. Restore reshape * Cosmetic changes * Cosmetic changes * Override getOutputsInfo * Fixes for OpenVINO < 2022.1 * Async inference for 2021.4 and less * Compile model with config * Fix serialize for 2022.1 * Asynchronous inference with 2022.1 * Handle 1d outputs * Work with model with dynamic output shape * Fixes with 1d output for old API * Control outputs by nGraph function for all OpenVINO versions * Refer inputs in PrePostProcessor by indices * Fix cycled dependency between InfEngineNgraphNode and InfEngineNgraphNet. Add InferRequest callback only for async inference. Do not capture InferRequest object. * Fix tests thresholds * Fix HETERO:GPU,CPU plugin issues with unsupported layer
This commit is contained in:
@@ -39,6 +39,86 @@ cv::String setInferenceEngineBackendType(const cv::String& newBackendType)
|
||||
|
||||
CV__DNN_INLINE_NS_END
|
||||
|
||||
#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2022_1)
|
||||
namespace InferenceEngine {
|
||||
|
||||
CNNNetwork::CNNNetwork() {}
|
||||
|
||||
CNNNetwork::CNNNetwork(std::shared_ptr<ov::Model> model) : model(model) {}
|
||||
|
||||
std::shared_ptr<ov::Model> CNNNetwork::getFunction() const {
|
||||
return model;
|
||||
}
|
||||
|
||||
void CNNNetwork::serialize(const std::string& xmlPath, const std::string& binPath) {
|
||||
ov::pass::Serialize(xmlPath, binPath).run_on_model(model);
|
||||
}
|
||||
|
||||
void CNNNetwork::reshape(const std::map<std::string, std::vector<size_t> >& shapes) {
|
||||
std::map<std::string, ov::PartialShape> partialShapes;
|
||||
for (const auto& it : shapes) {
|
||||
ov::PartialShape shape;
|
||||
shape.insert(shape.begin(), it.second.begin(), it.second.end());
|
||||
partialShapes.insert({it.first, shape});
|
||||
}
|
||||
model->reshape(partialShapes);
|
||||
}
|
||||
|
||||
std::vector<std::string> Core::GetAvailableDevices() {
|
||||
return get_available_devices();
|
||||
}
|
||||
|
||||
void Core::UnregisterPlugin(const std::string& id) {
|
||||
unload_plugin(id);
|
||||
}
|
||||
|
||||
CNNNetwork Core::ReadNetwork(const std::string& xmlPath, const std::string& binPath) {
|
||||
return read_model(xmlPath, binPath);
|
||||
}
|
||||
|
||||
ExecutableNetwork Core::LoadNetwork(CNNNetwork net, const std::string& device,
|
||||
const std::map<std::string, std::string>& config) {
|
||||
ov::AnyMap props;
|
||||
for (const auto& it : config) {
|
||||
props.insert(it);
|
||||
}
|
||||
return compile_model(net.getFunction(), device, props);
|
||||
}
|
||||
|
||||
ExecutableNetwork::ExecutableNetwork() {}
|
||||
|
||||
ExecutableNetwork::ExecutableNetwork(const ov::CompiledModel& copy) : CompiledModel(copy) {}
|
||||
|
||||
ov::InferRequest ExecutableNetwork::CreateInferRequest() { return create_infer_request(); }
|
||||
|
||||
} // namespace InferenceEngine
|
||||
|
||||
Mat infEngineBlobToMat(const ov::Tensor& blob)
|
||||
{
|
||||
std::vector<size_t> dims = blob.get_shape();
|
||||
std::vector<int> size(dims.begin(), dims.end());
|
||||
auto precision = blob.get_element_type();
|
||||
|
||||
int type = -1;
|
||||
switch (precision)
|
||||
{
|
||||
case ov::element::f32: type = CV_32F; break;
|
||||
case ov::element::u8: type = CV_8U; break;
|
||||
default:
|
||||
CV_Error(Error::StsNotImplemented, "Unsupported blob precision");
|
||||
}
|
||||
return Mat(size, type, blob.data());
|
||||
}
|
||||
|
||||
void infEngineBlobsToMats(const ov::TensorVector& blobs,
|
||||
std::vector<Mat>& mats)
|
||||
{
|
||||
mats.resize(blobs.size());
|
||||
for (int i = 0; i < blobs.size(); ++i)
|
||||
mats[i] = infEngineBlobToMat(blobs[i]);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Mat infEngineBlobToMat(const InferenceEngine::Blob::Ptr& blob)
|
||||
{
|
||||
@@ -65,7 +145,7 @@ void infEngineBlobsToMats(const std::vector<InferenceEngine::Blob::Ptr>& blobs,
|
||||
for (int i = 0; i < blobs.size(); ++i)
|
||||
mats[i] = infEngineBlobToMat(blobs[i]);
|
||||
}
|
||||
|
||||
#endif // OpenVINO >= 2022.1
|
||||
|
||||
static bool init_IE_plugins()
|
||||
{
|
||||
@@ -130,7 +210,11 @@ static bool detectArmPlugin_()
|
||||
{
|
||||
if (i->find("CPU") != std::string::npos)
|
||||
{
|
||||
#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2022_1)
|
||||
const std::string name = ie.get_property(*i, ov::device::full_name);
|
||||
#else
|
||||
const std::string name = ie.GetMetric(*i, METRIC_KEY(FULL_DEVICE_NAME)).as<std::string>();
|
||||
#endif
|
||||
CV_LOG_INFO(NULL, "CPU plugin: " << name);
|
||||
return name.find("arm_compute::NEON") != std::string::npos;
|
||||
}
|
||||
@@ -150,7 +234,11 @@ static bool detectMyriadX_(const std::string& device)
|
||||
{
|
||||
if (i->find(device) != std::string::npos)
|
||||
{
|
||||
#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2022_1)
|
||||
const std::string name = ie.get_property(*i, ov::device::full_name);
|
||||
#else
|
||||
const std::string name = ie.GetMetric(*i, METRIC_KEY(FULL_DEVICE_NAME)).as<std::string>();
|
||||
#endif
|
||||
CV_LOG_INFO(NULL, "Myriad device: " << name);
|
||||
return name.find("MyriadX") != std::string::npos || name.find("Myriad X") != std::string::npos || name.find("HDDL") != std::string::npos;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user