reshape mat before doing computation in fc layer
authorLi Peng <peng.li@intel.com>
Mon, 13 Nov 2017 01:06:41 +0000 (09:06 +0800)
committerLi Peng <peng.li@intel.com>
Mon, 13 Nov 2017 01:29:50 +0000 (09:29 +0800)
Signed-off-by: Li Peng <peng.li@intel.com>
modules/dnn/src/layers/fully_connected_layer.cpp

index 184e2b8..59d8ed9 100644 (file)
@@ -286,8 +286,13 @@ public:
         UMat biasOnesMat = UMat::ones(outerSize, 1, umat_blobs[0].type());
         for (size_t i = 0; i < inputs.size(); i++)
         {
-            UMat& srcMat = inputs[i];
-            UMat& dstMat = outputs[i];
+            MatShape inshape, outshape;
+            inshape = shape(outerSize, innerSize);
+            outshape = shape(outerSize, numOutput);
+
+            UMat srcMat, dstMat;
+            srcMat = inputs[i].reshape(1, inshape.size(), &inshape[0]);
+            dstMat = outputs[i].reshape(1, outshape.size(), &outshape[0]);
             dstMat.setTo(0.0f);
 
             if (!innerProductOp->Forward(srcMat, umat_blobs[0], (bias) ? umat_blobs[1] : UMat(), dstMat))