Fail using MobileSSD caffe model
I downloaded MobileNetSSD_deploy.caffemodel from https://github.com/chuanqi305/MobileN... I renamed deploy.prototxt to MobileNetSSD_deploy.txt. I used the supplied routine in OpenCvDnn example - I succeeded using Google Net caffe model. I changed the code to load the model - succeeded loading. I changed to :
Mat inputBlob = blobFromImage(img, 1, Size(*300,300*), Scalar(104, 117, 123)); //Convert Mat to batch of images
cv::Mat prob = net.forward("detection_out");
I get an assertion at getMaxClass(prob, &classId, &classProb)
Seem like prob not created at the forward.
I am using 3.4.1 on windows 7 with vs2015.
The full code:
cv::String modelTxt = "MobileNetSSD_deploy.txt";
cv::String modelBin = "MobileNetSSD_deploy.caffemodel";
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);
}
std::cout << "Network loaded successfuly\n";
cv::String imageFile = "Goose.bmp";
// cv::String imageFile = "space_shuttle.jpg";
Mat img = imread(imageFile, IMREAD_UNCHANGED);
int nChan = img.channels();
cout << nChan;
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(300, 300), Scalar(104, 117, 123)); //Convert Mat to batch of images
net.setInput(inputBlob, "data"); //set the network input
cv::Mat prob = net.forward("detection_out"); //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;
btw, ScaleFactor should be 0.007843f, not 1