首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法通过opencv3.2加载squeezeNet 1.0或1.1

无法通过opencv3.2加载squeezeNet 1.0或1.1
EN

Stack Overflow用户
提问于 2017-06-28 04:05:21
回答 1查看 413关注 0票数 1

我今天从opencv和opencv_contrib中提取源代码(2017/06/28),试图在这里加载squeezeNet模型列表,如下所示

代码语言:javascript
复制
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace cv::dnn;
#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;
/* Find best class for the blob (i. e. class with maximal probability) */
static void getMaxClass(const Mat &probBlob, int *classId, double *classProb)
{
    Mat probMat = probBlob.reshape(1, 1); //reshape the blob to 1x1000 matrix
    Point classNumber;
    minMaxLoc(probMat, NULL, classProb, NULL, &classNumber);
    *classId = classNumber.x;
}
static std::vector<String> readClassNames(const char *filename = "synset_words.txt")
{
    std::vector<String> classNames;
    std::ifstream fp(filename);
    if (!fp.is_open())
    {
        std::cerr << "File with classes labels not found: " << filename << std::endl;
        exit(-1);
    }
    std::string name;
    while (!fp.eof())
    {
        std::getline(fp, name);
        if (name.length())
            classNames.push_back( name.substr(name.find(' ')+1) );
    }
    fp.close();
    return classNames;
}
int main(int argc, char **argv)
{
    cv::dnn::initModule();  //Required if OpenCV is built as static libs
    String modelTxt = "train_val.prototxt";
    String modelBin = "squeezenet_v1.1.caffemodel";
    String imageFile = (argc > 1) ? argv[1] : "space_shuttle.jpg";
    Net net = dnn::readNetFromCaffe(modelTxt, modelBin);
    if (net.empty())
    {
        std::cerr << "Can't load network by using the following files: " << std::endl;
        std::cerr << "prototxt:   " << modelTxt << std::endl;
        std::cerr << "caffemodel: " << modelBin << std::endl;
        std::cerr << "bvlc_googlenet.caffemodel can be downloaded here:" << std::endl;
        std::cerr << "http://dl.caffe.berkeleyvision.org/bvlc_googlenet.caffemodel" << std::endl;
        exit(-1);
    }
    Mat img = imread(imageFile);
    if (img.empty())
    {
        std::cerr << "Can't read image from the file: " << imageFile << std::endl;
        exit(-1);
    }
    //GoogLeNet accepts only 224x224 RGB-images
    Mat inputBlob = blobFromImage(img, 1, Size(224, 224),
                                  Scalar(104, 117, 123));   //Convert Mat to batch of images
    net.setInput(inputBlob, "data");        //set the network input
    Mat prob = net.forward("prob");                          //compute output
    int classId;
    double classProb;
    getMaxClass(prob, &classId, &classProb);//find the best class
    std::vector<String> classNames = readClassNames();
    std::cout << "Best class: #" << classId << " '" << classNames.at(classId) << "'" << std::endl;
    std::cout << "Probability: " << classProb * 100 << "%" << std::endl;
    return 0;
} //main

但是它给了我以下错误(在google中很好用)

错误:错误参数(由多个源产生的重复blobs ),文件/home/ramsus/Qt/3rdLibs/opencv/modules/dnn/src/caffe/caffe_importer.cpp,第327行/home/ramsus/Qt/3rdLibs/opencv/modules/dnn/src/caffe/caffe_importer.cpp:327:错误:(-5)函数addOutput中的多个源产生的重复blobs

如何通过opencv导入squeezeNet_v1.1 ?谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-05-07 17:45:20

Mat prob = net.forward(" prob ");改为Mat prob= net.forward("softmax");

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44793472

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档