From e923712d817191c8981c863ef65537dd7b29627e Mon Sep 17 00:00:00 2001 From: Lubov Batanina Date: Wed, 25 Sep 2019 15:35:04 +0300 Subject: [PATCH] Merge pull request #15572 from l-bat:deconv3d Fix computation of internal shapes in Deconvolution layer * Fix computation of internal shapes * Refactoring --- modules/dnn/src/dnn.cpp | 6 ++++++ modules/dnn/src/layers/convolution_layer.cpp | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index c95a1a2..d41fc3b 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -2452,6 +2452,12 @@ struct Net::Impl int requiredOutputs = layers[id].requiredOutputs.size(); inOutShapes[id].supportInPlace = layers[id].getLayerInstance()->getMemoryShapes(is, requiredOutputs, os, ints); + + for (int i = 0; i < ints.size(); i++) + CV_Assert(total(ints[i]) > 0); + + for (int i = 0; i < os.size(); i++) + CV_Assert(total(os[i]) > 0); } void getLayersShapes(const ShapesVec& netInputShapes, diff --git a/modules/dnn/src/layers/convolution_layer.cpp b/modules/dnn/src/layers/convolution_layer.cpp index cec7bf1..0d5bef7 100644 --- a/modules/dnn/src/layers/convolution_layer.cpp +++ b/modules/dnn/src/layers/convolution_layer.cpp @@ -240,10 +240,14 @@ public: MatShape computeColRowShape(const MatShape &inpShape, const MatShape &outShape) const CV_OVERRIDE { - Size out(outShape[3], outShape[2]); + int dims = inpShape.size(); + int inpD = dims == 5 ? inpShape[2] : 1; + int inpH = inpShape[dims - 2]; + int inpW = inpShape.back(); int inpGroupCn = blobs[0].size[1]; - int ksize = inpGroupCn * kernel.height * kernel.width; - return shape(out.area(), ksize); + int ksize = inpGroupCn * std::accumulate(kernel_size.begin(), kernel_size.end(), + 1, std::multiplies()); + return shape(inpD * inpH * inpW, ksize); } virtual bool supportBackend(int backendId) CV_OVERRIDE @@ -1228,14 +1232,17 @@ public: MatShape computeColRowShape(const MatShape &inpShape, const MatShape &outShape) const CV_OVERRIDE { + int dims = inpShape.size(); int inpCn = inpShape[1]; - int inpH = inpShape[2]; - int inpW = inpShape[3]; + int inpD = dims == 5 ? inpShape[2] : 1; + int inpH = inpShape[dims - 2]; + int inpW = inpShape.back(); int outCn = outShape[1]; int ngroups = inpCn / blobs[0].size[0]; int outGroupCn = outCn / ngroups; - int ksize = outGroupCn * kernel.height * kernel.width; - return shape(ksize, inpH * inpW); + int ksize = outGroupCn * std::accumulate(kernel_size.begin(), kernel_size.end(), + 1, std::multiplies()); + return shape(ksize, inpD * inpH * inpW); } virtual bool supportBackend(int backendId) CV_OVERRIDE -- 2.7.4