From: Dmitry Kurtaev Date: Wed, 20 Jun 2018 11:25:24 +0000 (+0300) Subject: Remove undocumented feature to retreive layers outputs by indices X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~1^2~612^2~10^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=40b85c1cd9ede9717e6e09d1ef424dde90bb99ef;p=platform%2Fupstream%2Fopencv.git Remove undocumented feature to retreive layers outputs by indices --- diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index 84967ce..6a7c9d5 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -988,52 +988,26 @@ struct Net::Impl ld.inputBlobsId[inNum] = from; } - static void splitPin(const String &pinAlias, String &layerName, String &outName) - { - size_t delimPos = pinAlias.find('.'); - layerName = pinAlias.substr(0, delimPos); - outName = (delimPos == String::npos) ? String() : pinAlias.substr(delimPos + 1); - } - int resolvePinOutputName(LayerData &ld, const String &outName) { if (outName.empty()) return 0; - - if (std::isdigit(outName[0])) - { - char *lastChar; - long inum = std::strtol(outName.c_str(), &lastChar, 10); - - if (*lastChar == 0) - { - CV_Assert(inum == (int)inum); - return (int)inum; - } - } - return ld.getLayerInstance()->outputNameToIndex(outName); } - LayerPin getPinByAlias(const String &pinAlias) + LayerPin getPinByAlias(const String &layerName) { LayerPin pin; - String layerName, outName; - splitPin(pinAlias, layerName, outName); - pin.lid = (layerName.empty()) ? 0 : getLayerId(layerName); if (pin.lid >= 0) - pin.oid = resolvePinOutputName(getLayerData(pin.lid), outName); + pin.oid = resolvePinOutputName(getLayerData(pin.lid), layerName); return pin; } - std::vector getLayerOutPins(const String &pinAlias) + std::vector getLayerOutPins(const String &layerName) { - String layerName, outName; - splitPin(pinAlias, layerName, outName); - int lid = (layerName.empty()) ? 0 : getLayerId(layerName); std::vector pins; @@ -2044,12 +2018,6 @@ int Net::addLayer(const String &name, const String &type, LayerParams ¶ms) { CV_TRACE_FUNCTION(); - if (name.find('.') != String::npos) - { - CV_Error(Error::StsBadArg, "Added layer name \"" + name + "\" must not contain dot symbol"); - return -1; - } - if (impl->getLayerId(name) >= 0) { CV_Error(Error::StsBadArg, "Layer \"" + name + "\" already into net"); @@ -2689,7 +2657,7 @@ int Layer::inputNameToIndex(String) int Layer::outputNameToIndex(const String&) { - return -1; + return 0; } bool Layer::supportBackend(int backendId) diff --git a/modules/dnn/test/test_layers.cpp b/modules/dnn/test/test_layers.cpp index 111f354..77d69ce 100644 --- a/modules/dnn/test/test_layers.cpp +++ b/modules/dnn/test/test_layers.cpp @@ -1144,4 +1144,46 @@ TEST(Layer_Test_Interp, Accuracy) LayerFactory::unregisterLayer("Interp"); } +TEST(Layer_Test_PoolingIndices, Accuracy) +{ + Net net; + + LayerParams lp; + lp.set("pool", "max"); + lp.set("kernel_w", 2); + lp.set("kernel_h", 2); + lp.set("stride_w", 2); + lp.set("stride_h", 2); + lp.set("pad_w", 0); + lp.set("pad_h", 0); + lp.name = "testLayer.name"; // This test also checks that OpenCV lets use names with dots. + lp.type = "Pooling"; + net.addLayerToPrev(lp.name, lp.type, lp); + + Mat inp(10, 10, CV_8U); + randu(inp, 0, 255); + + Mat maxValues(5, 5, CV_32F, Scalar(-1)), indices(5, 5, CV_32F, Scalar(-1)); + for (int y = 0; y < 10; ++y) + { + int dstY = y / 2; + for (int x = 0; x < 10; ++x) + { + int dstX = x / 2; + uint8_t val = inp.at(y, x); + if ((float)inp.at(y, x) > maxValues.at(dstY, dstX)) + { + maxValues.at(dstY, dstX) = val; + indices.at(dstY, dstX) = y * 10 + x; + } + } + } + net.setInput(blobFromImage(inp)); + + std::vector outputs; + net.forward(outputs, lp.name); + normAssert(maxValues, outputs[0].reshape(1, 5)); + normAssert(indices, outputs[1].reshape(1, 5)); +} + }} // namespace diff --git a/modules/dnn/test/test_torch_importer.cpp b/modules/dnn/test/test_torch_importer.cpp index a8c1d15..5fe3fe1 100644 --- a/modules/dnn/test/test_torch_importer.cpp +++ b/modules/dnn/test/test_torch_importer.cpp @@ -87,7 +87,7 @@ static void runTorchNet(String prefix, int targetId = DNN_TARGET_CPU, String out if (outLayerName.empty()) outLayerName = net.getLayerNames().back(); - net.setInput(inp, "0"); + net.setInput(inp); std::vector outBlobs; net.forward(outBlobs, outLayerName); normAssert(outRef, outBlobs[0]);