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


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

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


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

示例1: 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

示例2: inputSize

TEST(Reproducibility_AlexNet, Accuracy)
{
    Net net;
    {
        const string proto = findDataFile("dnn/bvlc_alexnet.prototxt", false);
        const string model = findDataFile("dnn/bvlc_alexnet.caffemodel", false);
        Ptr<Importer> importer = createCaffeImporter(proto, model);
        ASSERT_TRUE(importer != NULL);
        importer->populateNet(net);
    }

    Mat sample = imread(_tf("grace_hopper_227.png"));
    ASSERT_TRUE(!sample.empty());

    Size inputSize(227, 227);

    if (sample.size() != inputSize)
        resize(sample, sample, inputSize);

    net.setBlob(".data", blobFromImage(sample, 1.));
    net.forward();

    Mat out = net.getBlob("prob");
    Mat ref = blobFromNPY(_tf("caffe_alexnet_prob.npy"));
    normAssert(ref, out);
}
开发者ID:VladX,项目名称:opencv_contrib,代码行数:26,代码来源:test_caffe_importer.cpp

示例3: inputSize

TEST(Reproducibility_AlexNet, Accuracy)
{
    Net net;
    {
        Ptr<Importer> importer = createCaffeImporter(_tf("bvlc_alexnet.prototxt"), _tf("bvlc_alexnet.caffemodel"));
        ASSERT_TRUE(importer != NULL);
        importer->populateNet(net);
    }

    Mat sample = imread(_tf("grace_hopper_227.png"));
    ASSERT_TRUE(!sample.empty());
    cv::cvtColor(sample, sample, cv::COLOR_BGR2RGB);

    Size inputSize(227, 227);

    if (sample.size() != inputSize)
        resize(sample, sample, inputSize);

    net.setBlob(".data", dnn::Blob::fromImages(sample));
    net.forward();

    Blob out = net.getBlob("prob");
    Blob ref = blobFromNPY(_tf("caffe_alexnet_prob.npy"));
    normAssert(ref, out);
}
开发者ID:LorenaGdL,项目名称:opencv_contrib,代码行数:25,代码来源:test_caffe_importer.cpp

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