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<LayerPin> getLayerOutPins(const String &pinAlias)
+ std::vector<LayerPin> getLayerOutPins(const String &layerName)
{
- String layerName, outName;
- splitPin(pinAlias, layerName, outName);
-
int lid = (layerName.empty()) ? 0 : getLayerId(layerName);
std::vector<LayerPin> pins;
{
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");
int Layer::outputNameToIndex(const String&)
{
- return -1;
+ return 0;
}
bool Layer::supportBackend(int backendId)
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<uint8_t>(y, x);
+ if ((float)inp.at<uint8_t>(y, x) > maxValues.at<float>(dstY, dstX))
+ {
+ maxValues.at<float>(dstY, dstX) = val;
+ indices.at<float>(dstY, dstX) = y * 10 + x;
+ }
+ }
+ }
+ net.setInput(blobFromImage(inp));
+
+ std::vector<Mat> outputs;
+ net.forward(outputs, lp.name);
+ normAssert(maxValues, outputs[0].reshape(1, 5));
+ normAssert(indices, outputs[1].reshape(1, 5));
+}
+
}} // namespace