Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any one run SqueezeNet by opencv dnn module?? #26

Closed
chibai opened this issue Nov 2, 2016 · 4 comments
Closed

Any one run SqueezeNet by opencv dnn module?? #26

chibai opened this issue Nov 2, 2016 · 4 comments

Comments

@chibai
Copy link

chibai commented Nov 2, 2016

I tried to run SqueezeNet in opencv dnn module
but i got the opencv error
Assertion failed <dim <= 2> in cv::Mat::reshape..............................

Anyone succesfully run squeezeNet in opencv dnn module??!!

@chibai
Copy link
Author

chibai commented Nov 2, 2016

#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);

@chibai
Copy link
Author

chibai commented Nov 2, 2016

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

@forresti forresti closed this as completed Jan 1, 2017
@ZhangXinNan
Copy link

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

@chibai
Copy link
Author

chibai commented Oct 6, 2018

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants