mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Merge remote-tracking branch 'upstream/3.4' into merge-3.4
This commit is contained in:
@@ -521,6 +521,54 @@ public:
|
||||
const int inpGroupCn = blobs[0].size[1];
|
||||
const int group = inpCn / inpGroupCn;
|
||||
|
||||
auto ieWeights = wrapToInfEngineBlob(blobs[0], InferenceEngine::Layout::OIHW);
|
||||
if (newWeightAndBias)
|
||||
{
|
||||
if (weightsMat.isContinuous())
|
||||
{
|
||||
Mat fusedWeights = weightsMat.reshape(1, blobs[0].dims, blobs[0].size);
|
||||
ieWeights = wrapToInfEngineBlob(fusedWeights, InferenceEngine::Layout::OIHW);
|
||||
}
|
||||
else
|
||||
{
|
||||
ieWeights = InferenceEngine::make_shared_blob<float>(
|
||||
InferenceEngine::Precision::FP32, InferenceEngine::Layout::OIHW,
|
||||
ieWeights->dims());
|
||||
ieWeights->allocate();
|
||||
|
||||
Mat newWeights = infEngineBlobToMat(ieWeights).reshape(1, outCn);
|
||||
Mat fusedWeights = weightsMat.colRange(0, newWeights.cols);
|
||||
fusedWeights.copyTo(newWeights);
|
||||
}
|
||||
}
|
||||
InferenceEngine::Blob::Ptr ieBiases;
|
||||
if (hasBias() || fusedBias)
|
||||
{
|
||||
Mat biasesMat({outCn}, CV_32F, &biasvec[0]);
|
||||
ieBiases = wrapToInfEngineBlob(biasesMat, {(size_t)outCn}, InferenceEngine::Layout::C);
|
||||
}
|
||||
|
||||
#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2018R5)
|
||||
InferenceEngine::Builder::ConvolutionLayer ieLayer(name);
|
||||
|
||||
ieLayer.setKernel({kernel.height, kernel.width});
|
||||
ieLayer.setStrides({stride.height, stride.width});
|
||||
ieLayer.setDilation({dilation.height, dilation.width});
|
||||
ieLayer.setPaddingsBegin({pad.height, pad.width});
|
||||
ieLayer.setPaddingsEnd({pad.height, pad.width});
|
||||
ieLayer.setGroup(group);
|
||||
ieLayer.setOutDepth(outCn);
|
||||
|
||||
ieLayer.setWeights(ieWeights);
|
||||
if (ieBiases)
|
||||
ieLayer.setBiases(ieBiases);
|
||||
|
||||
InferenceEngine::Builder::Layer l = ieLayer;
|
||||
if (!padMode.empty())
|
||||
l.getParameters()["auto_pad"] = padMode == "VALID" ? std::string("valid") : std::string("same_upper");
|
||||
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(l));
|
||||
#else
|
||||
InferenceEngine::LayerParams lp;
|
||||
lp.name = name;
|
||||
lp.type = "Convolution";
|
||||
@@ -557,32 +605,11 @@ public:
|
||||
ieLayer->_out_depth = outCn;
|
||||
ieLayer->_group = group;
|
||||
|
||||
ieLayer->_weights = wrapToInfEngineBlob(blobs[0], InferenceEngine::Layout::OIHW);
|
||||
if (newWeightAndBias)
|
||||
{
|
||||
if (weightsMat.isContinuous())
|
||||
{
|
||||
Mat fusedWeights = weightsMat.reshape(1, blobs[0].dims, blobs[0].size);
|
||||
ieLayer->_weights = wrapToInfEngineBlob(fusedWeights, InferenceEngine::Layout::OIHW);
|
||||
}
|
||||
else
|
||||
{
|
||||
ieLayer->_weights = InferenceEngine::make_shared_blob<float>(
|
||||
InferenceEngine::Precision::FP32, InferenceEngine::Layout::OIHW,
|
||||
ieLayer->_weights->dims());
|
||||
ieLayer->_weights->allocate();
|
||||
|
||||
Mat newWeights = infEngineBlobToMat(ieLayer->_weights).reshape(1, outCn);
|
||||
Mat fusedWeights = weightsMat.colRange(0, newWeights.cols);
|
||||
fusedWeights.copyTo(newWeights);
|
||||
}
|
||||
}
|
||||
if (hasBias() || fusedBias)
|
||||
{
|
||||
Mat biasesMat({outCn}, CV_32F, &biasvec[0]);
|
||||
ieLayer->_biases = wrapToInfEngineBlob(biasesMat, {(size_t)outCn}, InferenceEngine::Layout::C);
|
||||
}
|
||||
ieLayer->_weights = ieWeights;
|
||||
if (ieBiases)
|
||||
ieLayer->_biases = ieBiases;
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(ieLayer));
|
||||
#endif
|
||||
#endif // HAVE_INF_ENGINE
|
||||
return Ptr<BackendNode>();
|
||||
}
|
||||
@@ -1193,6 +1220,9 @@ public:
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE)
|
||||
{
|
||||
if (INF_ENGINE_RELEASE == 2018050000 && (adjustPad.height || adjustPad.width))
|
||||
return false;
|
||||
|
||||
const int outGroupCn = blobs[0].size[1]; // Weights are in IOHW layout
|
||||
const int group = numOutput / outGroupCn;
|
||||
if (group != 1)
|
||||
@@ -1747,6 +1777,27 @@ public:
|
||||
virtual Ptr<BackendNode> initInfEngine(const std::vector<Ptr<BackendWrapper> > &) CV_OVERRIDE
|
||||
{
|
||||
#ifdef HAVE_INF_ENGINE
|
||||
#if INF_ENGINE_VER_MAJOR_GE(INF_ENGINE_RELEASE_2018R5)
|
||||
const int outGroupCn = blobs[0].size[1]; // Weights are in IOHW layout
|
||||
const int group = numOutput / outGroupCn;
|
||||
|
||||
InferenceEngine::Builder::DeconvolutionLayer ieLayer(name);
|
||||
|
||||
ieLayer.setKernel({kernel.height, kernel.width});
|
||||
ieLayer.setStrides({stride.height, stride.width});
|
||||
ieLayer.setDilation({dilation.height, dilation.width});
|
||||
ieLayer.setPaddingsBegin({pad.height, pad.width});
|
||||
ieLayer.setPaddingsEnd({pad.height, pad.width});
|
||||
ieLayer.setGroup(group);
|
||||
ieLayer.setOutDepth(numOutput);
|
||||
|
||||
ieLayer.setWeights(wrapToInfEngineBlob(blobs[0], InferenceEngine::Layout::OIHW));
|
||||
if (hasBias())
|
||||
{
|
||||
ieLayer.setBiases(wrapToInfEngineBlob(blobs[1], {(size_t)numOutput}, InferenceEngine::Layout::C));
|
||||
}
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(ieLayer));
|
||||
#else
|
||||
const int outGroupCn = blobs[0].size[1]; // Weights are in IOHW layout
|
||||
const int group = numOutput / outGroupCn;
|
||||
|
||||
@@ -1786,6 +1837,7 @@ public:
|
||||
ieLayer->_biases = wrapToInfEngineBlob(blobs[1], {(size_t)numOutput}, InferenceEngine::Layout::C);
|
||||
}
|
||||
return Ptr<BackendNode>(new InfEngineBackendNode(ieLayer));
|
||||
#endif
|
||||
#endif // HAVE_INF_ENGINE
|
||||
return Ptr<BackendNode>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user