From b1b505f7833eb1a3317613c91f1d8dc5267f7668 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sun, 8 Dec 2019 22:11:55 +0000 Subject: [PATCH] dnn: clarify error message from getMemoryShapes() --- modules/dnn/src/dnn.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index cd51282626..eb87d2c348 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -2812,8 +2812,29 @@ struct Net::Impl ShapesVec& os = inOutShapes[id].out; ShapesVec& ints = inOutShapes[id].internal; int requiredOutputs = layers[id].requiredOutputs.size(); - inOutShapes[id].supportInPlace = - layers[id].getLayerInstance()->getMemoryShapes(is, requiredOutputs, os, ints); + Ptr l = layers[id].getLayerInstance(); + CV_Assert(l); + bool layerSupportInPlace = false; + try + { + layerSupportInPlace = l->getMemoryShapes(is, requiredOutputs, os, ints); + } + catch (const cv::Exception& e) + { + CV_LOG_ERROR(NULL, "OPENCV/DNN: [" << l->type << "]:(" << l->name << "): getMemoryShapes() throws exception." << + " inputs=" << is.size() << " outputs=" << os.size() << "/" << requiredOutputs); + for (size_t i = 0; i < is.size(); ++i) + { + CV_LOG_ERROR(NULL, " input[" << i << "] = " << toString(is[i])); + } + for (size_t i = 0; i < os.size(); ++i) + { + CV_LOG_ERROR(NULL, " output[" << i << "] = " << toString(os[i])); + } + CV_LOG_ERROR(NULL, "Exception message: " << e.what()); + throw; + } + inOutShapes[id].supportInPlace = layerSupportInPlace; for (int i = 0; i < ints.size(); i++) CV_Assert(total(ints[i]) > 0);