mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge pull request #12913 from dkurt:dnn_fix_ie_hyperparams
This commit is contained in:
@@ -107,14 +107,21 @@ public:
|
||||
inputs[i].copyTo(outputs[i]);
|
||||
}
|
||||
|
||||
virtual Ptr<BackendNode> initInfEngine(const std::vector<Ptr<BackendWrapper> >&) CV_OVERRIDE
|
||||
virtual Ptr<BackendNode> initInfEngine(const std::vector<Ptr<BackendWrapper> >& inputs) CV_OVERRIDE
|
||||
{
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
InferenceEngine::DataPtr input = infEngineDataNode(inputs[0]);
|
||||
CV_Assert(!input->dims.empty());
|
||||
|
||||
InferenceEngine::LayerParams lp;
|
||||
lp.name = name;
|
||||
lp.type = "Split";
|
||||
lp.precision = InferenceEngine::Precision::FP32;
|
||||
std::shared_ptr<InferenceEngine::SplitLayer> ieLayer(new InferenceEngine::SplitLayer(lp));
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R3)
|
||||
ieLayer->params["axis"] = format("%d", input->dims.size() - 1);
|
||||
ieLayer->params["out_sizes"] = format("%d", input->dims[0]);
|
||||
#endif
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(ieLayer));
|
||||
#endif // HAVE_INF_ENGINE
|
||||
return Ptr<BackendNode>();
|
||||
|
||||
@@ -460,6 +460,12 @@ public:
|
||||
ieLayer->_pads_end.insert(InferenceEngine::Y_AXIS, pad.height);
|
||||
ieLayer->_dilation.insert(InferenceEngine::X_AXIS, dilation.width);
|
||||
ieLayer->_dilation.insert(InferenceEngine::Y_AXIS, dilation.height);
|
||||
ieLayer->params["output"] = format("%d", outCn);
|
||||
ieLayer->params["kernel"] = format("%d,%d,%d,%d", outCn, inpGroupCn, kernel.height, kernel.width);
|
||||
ieLayer->params["pads_begin"] = format("%d,%d", pad.height, pad.width);
|
||||
ieLayer->params["pads_end"] = format("%d,%d", pad.height, pad.width);
|
||||
ieLayer->params["strides"] = format("%d,%d", stride.height, stride.width);
|
||||
ieLayer->params["dilations"] = format("%d,%d", dilation.height, dilation.width);
|
||||
#else
|
||||
ieLayer->_kernel_x = kernel.width;
|
||||
ieLayer->_kernel_y = kernel.height;
|
||||
|
||||
@@ -156,6 +156,14 @@ public:
|
||||
|
||||
CV_Assert(crop_ranges.size() == 4);
|
||||
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R3)
|
||||
for (int i = 0; i < 4; ++i)
|
||||
{
|
||||
ieLayer->axis.push_back(i);
|
||||
ieLayer->offset.push_back(crop_ranges[i].start);
|
||||
ieLayer->dim.push_back(crop_ranges[i].end - crop_ranges[i].start);
|
||||
}
|
||||
#else
|
||||
ieLayer->axis.push_back(0); // batch
|
||||
ieLayer->offset.push_back(crop_ranges[0].start);
|
||||
ieLayer->dim.push_back(crop_ranges[0].end - crop_ranges[0].start);
|
||||
@@ -171,7 +179,7 @@ public:
|
||||
ieLayer->axis.push_back(2); // width
|
||||
ieLayer->offset.push_back(crop_ranges[3].start);
|
||||
ieLayer->dim.push_back(crop_ranges[3].end - crop_ranges[3].start);
|
||||
|
||||
#endif
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(ieLayer));
|
||||
#endif // HAVE_INF_ENGINE
|
||||
return Ptr<BackendNode>();
|
||||
|
||||
@@ -449,6 +449,9 @@ public:
|
||||
std::shared_ptr<InferenceEngine::FullyConnectedLayer> ieLayer(new InferenceEngine::FullyConnectedLayer(lp));
|
||||
|
||||
ieLayer->_out_num = blobs[0].size[0];
|
||||
#if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2018R3)
|
||||
ieLayer->params["out-size"] = format("%d", blobs[0].size[0]);
|
||||
#endif
|
||||
ieLayer->_weights = wrapToInfEngineBlob(blobs[0], {(size_t)blobs[0].size[0], (size_t)blobs[0].size[1], 1, 1}, InferenceEngine::Layout::OIHW);
|
||||
if (blobs.size() > 1)
|
||||
ieLayer->_biases = wrapToInfEngineBlob(blobs[1], {(size_t)ieLayer->_out_num}, InferenceEngine::Layout::C);
|
||||
|
||||
@@ -275,6 +275,10 @@ public:
|
||||
poolLayer->_padding.insert(InferenceEngine::Y_AXIS, pad_t);
|
||||
poolLayer->_pads_end.insert(InferenceEngine::X_AXIS, pad_r);
|
||||
poolLayer->_pads_end.insert(InferenceEngine::Y_AXIS, pad_b);
|
||||
poolLayer->params["kernel"] = format("%d,%d", kernel.height, kernel.width);
|
||||
poolLayer->params["pads_begin"] = format("%d,%d", pad_t, pad_l);
|
||||
poolLayer->params["pads_end"] = format("%d,%d", pad_b, pad_r);
|
||||
poolLayer->params["strides"] = format("%d,%d", stride.height, stride.width);
|
||||
#else
|
||||
poolLayer->_kernel_x = kernel.width;
|
||||
poolLayer->_kernel_y = kernel.height;
|
||||
|
||||
@@ -51,9 +51,14 @@ public:
|
||||
|
||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||
{
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE)
|
||||
return interpolation == "nearest" && preferableTarget != DNN_TARGET_MYRIAD;
|
||||
{
|
||||
return (interpolation == "nearest" && preferableTarget != DNN_TARGET_MYRIAD) ||
|
||||
(interpolation == "bilinear" && INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2018R4));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
return backendId == DNN_BACKEND_OPENCV;
|
||||
}
|
||||
|
||||
@@ -160,15 +165,27 @@ public:
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
InferenceEngine::LayerParams lp;
|
||||
lp.name = name;
|
||||
lp.type = "Resample";
|
||||
lp.precision = InferenceEngine::Precision::FP32;
|
||||
|
||||
std::shared_ptr<InferenceEngine::CNNLayer> ieLayer(new InferenceEngine::CNNLayer(lp));
|
||||
ieLayer->params["type"] = "caffe.ResampleParameter.NEAREST";
|
||||
ieLayer->params["antialias"] = "0";
|
||||
std::shared_ptr<InferenceEngine::CNNLayer> ieLayer;
|
||||
if (interpolation == "nearest")
|
||||
{
|
||||
lp.type = "Resample";
|
||||
ieLayer = std::shared_ptr<InferenceEngine::CNNLayer>(new InferenceEngine::CNNLayer(lp));
|
||||
ieLayer->params["type"] = "caffe.ResampleParameter.NEAREST";
|
||||
ieLayer->params["antialias"] = "0";
|
||||
}
|
||||
else if (interpolation == "bilinear")
|
||||
{
|
||||
lp.type = "Interp";
|
||||
ieLayer = std::shared_ptr<InferenceEngine::CNNLayer>(new InferenceEngine::CNNLayer(lp));
|
||||
ieLayer->params["pad_beg"] = "0";
|
||||
ieLayer->params["pad_end"] = "0";
|
||||
ieLayer->params["align_corners"] = "0";
|
||||
}
|
||||
else
|
||||
CV_Error(Error::StsNotImplemented, "Unsupported interpolation: " + interpolation);
|
||||
ieLayer->params["width"] = cv::format("%d", outWidth);
|
||||
ieLayer->params["height"] = cv::format("%d", outHeight);
|
||||
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(ieLayer));
|
||||
#endif // HAVE_INF_ENGINE
|
||||
return Ptr<BackendNode>();
|
||||
|
||||
Reference in New Issue
Block a user