mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge pull request #15184 from l-bat:IE_R2
Support new IE API (#15184) * Add support OpenVINO R2 for layers * Add Core API * Fix tests * Fix expectNoFallbacksFromIE for ONNX nets * Remove deprecated API * Remove td * Remove TargetDevice * Fix Async * Add test * Fix detectMyriadX * Fix test * Fix warning
This commit is contained in:
committed by
Alexander Alekhin
parent
cf93a05d2d
commit
0e1ef8f8e1
@@ -136,13 +136,10 @@ static const std::vector<std::string> getOpenVINOTestModelsList()
|
||||
|
||||
static inline void genData(const std::vector<size_t>& dims, Mat& m, Blob::Ptr& dataPtr)
|
||||
{
|
||||
std::vector<int> reversedDims(dims.begin(), dims.end());
|
||||
std::reverse(reversedDims.begin(), reversedDims.end());
|
||||
|
||||
m.create(reversedDims, CV_32F);
|
||||
m.create(std::vector<int>(dims.begin(), dims.end()), CV_32F);
|
||||
randu(m, -1, 1);
|
||||
|
||||
dataPtr = make_shared_blob<float>(Precision::FP32, dims, (float*)m.data);
|
||||
dataPtr = make_shared_blob<float>({Precision::FP32, dims, Layout::ANY}, (float*)m.data);
|
||||
}
|
||||
|
||||
void runIE(Target target, const std::string& xmlPath, const std::string& binPath,
|
||||
@@ -154,32 +151,42 @@ void runIE(Target target, const std::string& xmlPath, const std::string& binPath
|
||||
|
||||
CNNNetwork net = reader.getNetwork();
|
||||
|
||||
std::string device_name;
|
||||
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GT(2019010000)
|
||||
Core ie;
|
||||
#else
|
||||
InferenceEnginePluginPtr enginePtr;
|
||||
InferencePlugin plugin;
|
||||
#endif
|
||||
ExecutableNetwork netExec;
|
||||
InferRequest infRequest;
|
||||
|
||||
try
|
||||
{
|
||||
auto dispatcher = InferenceEngine::PluginDispatcher({""});
|
||||
switch (target)
|
||||
{
|
||||
case DNN_TARGET_CPU:
|
||||
enginePtr = dispatcher.getSuitablePlugin(TargetDevice::eCPU);
|
||||
device_name = "CPU";
|
||||
break;
|
||||
case DNN_TARGET_OPENCL:
|
||||
case DNN_TARGET_OPENCL_FP16:
|
||||
enginePtr = dispatcher.getSuitablePlugin(TargetDevice::eGPU);
|
||||
device_name = "GPU";
|
||||
break;
|
||||
case DNN_TARGET_MYRIAD:
|
||||
enginePtr = dispatcher.getSuitablePlugin(TargetDevice::eMYRIAD);
|
||||
device_name = "MYRIAD";
|
||||
break;
|
||||
case DNN_TARGET_FPGA:
|
||||
enginePtr = dispatcher.getPluginByDevice("HETERO:FPGA,CPU");
|
||||
device_name = "FPGA";
|
||||
break;
|
||||
default:
|
||||
CV_Error(Error::StsNotImplemented, "Unknown target");
|
||||
};
|
||||
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_LE(2019010000)
|
||||
auto dispatcher = InferenceEngine::PluginDispatcher({""});
|
||||
enginePtr = dispatcher.getPluginByDevice(device_name);
|
||||
#endif
|
||||
if (target == DNN_TARGET_CPU || target == DNN_TARGET_FPGA)
|
||||
{
|
||||
std::string suffixes[] = {"_avx2", "_sse4", ""};
|
||||
@@ -202,16 +209,23 @@ void runIE(Target target, const std::string& xmlPath, const std::string& binPath
|
||||
try
|
||||
{
|
||||
IExtensionPtr extension = make_so_pointer<IExtension>(libName);
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GT(2019010000)
|
||||
ie.AddExtension(extension, device_name);
|
||||
#else
|
||||
enginePtr->AddExtension(extension, 0);
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
catch(...) {}
|
||||
}
|
||||
// Some of networks can work without a library of extra layers.
|
||||
}
|
||||
#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GT(2019010000)
|
||||
netExec = ie.LoadNetwork(net, device_name);
|
||||
#else
|
||||
plugin = InferencePlugin(enginePtr);
|
||||
|
||||
netExec = plugin.LoadNetwork(net, {});
|
||||
#endif
|
||||
infRequest = netExec.CreateInferRequest();
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
@@ -224,7 +238,7 @@ void runIE(Target target, const std::string& xmlPath, const std::string& binPath
|
||||
BlobMap inputBlobs;
|
||||
for (auto& it : net.getInputsInfo())
|
||||
{
|
||||
genData(it.second->getDims(), inputsMap[it.first], inputBlobs[it.first]);
|
||||
genData(it.second->getTensorDesc().getDims(), inputsMap[it.first], inputBlobs[it.first]);
|
||||
}
|
||||
infRequest.SetInput(inputBlobs);
|
||||
|
||||
@@ -233,7 +247,7 @@ void runIE(Target target, const std::string& xmlPath, const std::string& binPath
|
||||
BlobMap outputBlobs;
|
||||
for (auto& it : net.getOutputsInfo())
|
||||
{
|
||||
genData(it.second->dims, outputsMap[it.first], outputBlobs[it.first]);
|
||||
genData(it.second->getTensorDesc().getDims(), outputsMap[it.first], outputBlobs[it.first]);
|
||||
}
|
||||
infRequest.SetOutput(outputBlobs);
|
||||
|
||||
|
||||
@@ -467,6 +467,42 @@ INSTANTIATE_TEST_CASE_P(/**/, Async, Combine(
|
||||
Values(CV_32F, CV_8U),
|
||||
testing::ValuesIn(getAvailableTargets(DNN_BACKEND_INFERENCE_ENGINE))
|
||||
));
|
||||
|
||||
typedef testing::TestWithParam<Target> Test_Model_Optimizer;
|
||||
TEST_P(Test_Model_Optimizer, forward_two_nets)
|
||||
{
|
||||
const int target = GetParam();
|
||||
|
||||
const std::string suffix = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? "_fp16" : "";
|
||||
const std::string& model = findDataFile("dnn/layers/layer_convolution" + suffix + ".bin");
|
||||
const std::string& proto = findDataFile("dnn/layers/layer_convolution" + suffix + ".xml");
|
||||
|
||||
Net net0 = readNet(model, proto);
|
||||
net0.setPreferableTarget(target);
|
||||
|
||||
Net net1 = readNet(model, proto);
|
||||
net1.setPreferableTarget(target);
|
||||
|
||||
// Generate inputs.
|
||||
int blobSize[] = {2, 6, 75, 113};
|
||||
Mat input(4, &blobSize[0], CV_32F);
|
||||
randu(input, 0, 255);
|
||||
|
||||
net0.setInput(input);
|
||||
Mat ref0 = net0.forward().clone();
|
||||
|
||||
net1.setInput(input);
|
||||
Mat ref1 = net1.forward();
|
||||
|
||||
net0.setInput(input);
|
||||
Mat ref2 = net0.forward();
|
||||
|
||||
normAssert(ref0, ref2, 0, 0);
|
||||
}
|
||||
INSTANTIATE_TEST_CASE_P(/**/, Test_Model_Optimizer,
|
||||
testing::ValuesIn(getAvailableTargets(DNN_BACKEND_INFERENCE_ENGINE))
|
||||
);
|
||||
|
||||
#endif // HAVE_INF_ENGINE
|
||||
|
||||
}} // namespace
|
||||
|
||||
Reference in New Issue
Block a user