当前位置: 首页>>代码示例>>C++>>正文


C++ Net::getLayerNames方法代码示例

本文整理汇总了C++中Net::getLayerNames方法的典型用法代码示例。如果您正苦于以下问题:C++ Net::getLayerNames方法的具体用法?C++ Net::getLayerNames怎么用?C++ Net::getLayerNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Net的用法示例。


在下文中一共展示了Net::getLayerNames方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: runTorchNet

static void runTorchNet(String prefix, int targetId = DNN_TARGET_CPU, String outLayerName = "",
                        bool check2ndBlob = false, bool isBinary = false)
{
    String suffix = (isBinary) ? ".dat" : ".txt";

    Net net = readNetFromTorch(_tf(prefix + "_net" + suffix), isBinary);
    ASSERT_FALSE(net.empty());

    net.setPreferableBackend(DNN_BACKEND_DEFAULT);
    net.setPreferableTarget(targetId);

    Mat inp, outRef;
    ASSERT_NO_THROW( inp = readTorchBlob(_tf(prefix + "_input" + suffix), isBinary) );
    ASSERT_NO_THROW( outRef = readTorchBlob(_tf(prefix + "_output" + suffix), isBinary) );

    if (outLayerName.empty())
        outLayerName = net.getLayerNames().back();

    net.setInput(inp, "0");
    std::vector<Mat> outBlobs;
    net.forward(outBlobs, outLayerName);
    normAssert(outRef, outBlobs[0]);

    if (check2ndBlob)
    {
        Mat out2 = outBlobs[1];
        Mat ref2 = readTorchBlob(_tf(prefix + "_output_2" + suffix), isBinary);
        normAssert(out2, ref2);
    }
}
开发者ID:MCobias,项目名称:opencv,代码行数:30,代码来源:test_torch_importer.cpp

示例2: runTorchNet

    void runTorchNet(const String& prefix, String outLayerName = "",
                     bool check2ndBlob = false, bool isBinary = false,
                     double l1 = 0.0, double lInf = 0.0)
    {
        String suffix = (isBinary) ? ".dat" : ".txt";

        Mat inp, outRef;
        ASSERT_NO_THROW( inp = readTorchBlob(_tf(prefix + "_input" + suffix), isBinary) );
        ASSERT_NO_THROW( outRef = readTorchBlob(_tf(prefix + "_output" + suffix), isBinary) );

        checkBackend(backend, target, &inp, &outRef);

        Net net = readNetFromTorch(_tf(prefix + "_net" + suffix), isBinary);
        ASSERT_FALSE(net.empty());

        net.setPreferableBackend(backend);
        net.setPreferableTarget(target);

        if (outLayerName.empty())
            outLayerName = net.getLayerNames().back();

        net.setInput(inp);
        std::vector<Mat> outBlobs;
        net.forward(outBlobs, outLayerName);
        l1 = l1 ? l1 : default_l1;
        lInf = lInf ? lInf : default_lInf;
        normAssert(outRef, outBlobs[0], "", l1, lInf);

        if (check2ndBlob && backend != DNN_BACKEND_INFERENCE_ENGINE)
        {
            Mat out2 = outBlobs[1];
            Mat ref2 = readTorchBlob(_tf(prefix + "_output_2" + suffix), isBinary);
            normAssert(out2, ref2, "", l1, lInf);
        }
    }
开发者ID:Kumataro,项目名称:opencv,代码行数:35,代码来源:test_torch_importer.cpp

示例3: runTorchNet

static void runTorchNet(String prefix, String outLayerName = "",
                        bool check2ndBlob = false, bool isBinary = false)
{
    String suffix = (isBinary) ? ".dat" : ".txt";

    Net net;
    Ptr<Importer> importer = createTorchImporter(_tf(prefix + "_net" + suffix), isBinary);
    ASSERT_TRUE(importer != NULL);
    importer->populateNet(net);

    Blob inp, outRef;
    ASSERT_NO_THROW( inp = readTorchBlob(_tf(prefix + "_input" + suffix), isBinary) );
    ASSERT_NO_THROW( outRef = readTorchBlob(_tf(prefix + "_output" + suffix), isBinary) );

    net.setBlob(".0", inp);
    net.forward();
    if (outLayerName.empty())
        outLayerName = net.getLayerNames().back();
    Blob out = net.getBlob(outLayerName);

    normAssert(outRef, out);

    if (check2ndBlob)
    {
        Blob out2 = net.getBlob(outLayerName + ".1");
        Blob ref2 = readTorchBlob(_tf(prefix + "_output_2" + suffix), isBinary);
        normAssert(out2, ref2);
    }
}
开发者ID:LorenaGdL,项目名称:opencv_contrib,代码行数:29,代码来源:test_torch_importer.cpp

示例4: getOutputsNames

static std::vector<String> getOutputsNames(const Net& net)
{
    std::vector<String> names;
    std::vector<int> outLayers = net.getUnconnectedOutLayers();
    std::vector<String> layersNames = net.getLayerNames();
    names.resize(outLayers.size());
    for (size_t i = 0; i < outLayers.size(); ++i)
          names[i] = layersNames[outLayers[i] - 1];
    return names;
}
开发者ID:bramton,项目名称:opencv,代码行数:10,代码来源:test_darknet_importer.cpp

示例5: expectNoFallbacks

    void expectNoFallbacks(Net& net)
    {
        // Check if all the layers are supported with current backend and target.
        // Some layers might be fused so their timings equal to zero.
        std::vector<double> timings;
        net.getPerfProfile(timings);
        std::vector<String> names = net.getLayerNames();
        CV_Assert(names.size() == timings.size());

        for (int i = 0; i < names.size(); ++i)
        {
            Ptr<dnn::Layer> l = net.getLayer(net.getLayerId(names[i]));
            bool fused = !timings[i];
            if ((!l->supportBackend(backend) || l->preferableTarget != target) && !fused)
                CV_Error(Error::StsNotImplemented, "Layer [" + l->name + "] of type [" +
                         l->type + "] is expected to has backend implementation");
        }
    }
开发者ID:janstarzy,项目名称:opencv,代码行数:18,代码来源:test_common.hpp

示例6: createTorchImporter

TEST(Torch_Importer, ENet_accuracy)
{
    Net net;
    {
        Ptr<Importer> importer = createTorchImporter(_tf("Enet-model-best.net", false));
        ASSERT_TRUE(importer != NULL);
        importer->populateNet(net);
    }

    Mat sample = imread(_tf("street.png", false));
    cv::cvtColor(sample, sample, cv::COLOR_BGR2RGB);
    sample.convertTo(sample, CV_32F, 1/255.0);
    dnn::Blob inputBlob = dnn::Blob::fromImages(sample);

    net.setBlob("", inputBlob);
    net.forward();
    dnn::Blob out = net.getBlob(net.getLayerNames().back());

    Blob ref = blobFromNPY(_tf("torch_enet_prob.npy", false));
    normAssert(ref, out);
}
开发者ID:LorenaGdL,项目名称:opencv_contrib,代码行数:21,代码来源:test_torch_importer.cpp


注:本文中的Net::getLayerNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。