Git Product home page Git Product logo

Comments (4)

chibai avatar chibai commented on June 21, 2024

#include <opencv2\opencv.hpp>
#include <opencv2\dnn.hpp>
#include
#include
#include

using namespace std;
using namespace cv;
using namespace cv::dnn;

int main()
{
//input
string classNameFile = "synset_words.txt";
String imageFile = "1.jpg";
String modelTxt = "deploy.prototxt";
String modelBin = "squeezenet_v1.0.caffemodel";
// image preprocessing
Mat img = imread(imageFile);
if (img.empty())
{
cerr << "fail to load the image" << endl;
exit(-1);
}
resize(img, img, Size(227, 227));
//read class name syssets word
vector className;
string name;
ifstream fp(classNameFile);
if (!fp.is_open())
{
cerr << "fail to load the class names";
}
while (!fp.eof())
{
getline(fp, name);
if (name.length())
{
className.push_back(name.substr(name.find(' ') + 1));
}
}
fp.close();
//load caffe model
cv::dnn::initModule();
Net CaffeNet = dnn::readNetFromCaffe(modelTxt, modelBin);
if (CaffeNet.empty())
{
cerr << "fail to load model" << endl;
exit(-1);
}
// forward pass
dnn::Blob imgBlob = dnn::Blob::fromImages(img);
CaffeNet.setBlob(".data", imgBlob);
CaffeNet.forward();
dnn::Blob probBlob = CaffeNet.getBlob("prob");
Mat proMat = probBlob.matRefConst().reshape(1, 1);
//

return 0;

}

this is the full code, and the problem comes from the last line
Mat proMat = probBlob.matRefConst().reshape(1, 1);

from squeezenet.

chibai avatar chibai commented on June 21, 2024

I somehow solved this by probBlob.getPlane()function
but still do not know why probBlob.matRefConst() didn't work

from squeezenet.

ZhangXinNan avatar ZhangXinNan commented on June 21, 2024

@chibai I download pre-built opencv 3.4.3 on my windows 10. But init_module is not the member of cv::dnn .

from squeezenet.

chibai avatar chibai commented on June 21, 2024

@chibai I download pre-built opencv 3.4.3 on my windows 10. But init_module is not the member of cv::dnn .

API always changed. Please refer the newest version https://github.com/opencv/opencv/blob/master/samples/dnn/classification.cpp

from squeezenet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.