mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Merge pull request #10529 from LaurentBerger:ExampleGoogleNet
* Add a parameter labels to command line * default value * samples: caffe_googlenet.cpp minor refactoring
This commit is contained in:
parent
d0b2e60edc
commit
004a1cd64a
@ -60,7 +60,7 @@ static void getMaxClass(const Mat &probBlob, int *classId, double *classProb)
|
||||
*classId = classNumber.x;
|
||||
}
|
||||
|
||||
static std::vector<String> readClassNames(const char *filename = "synset_words.txt")
|
||||
static std::vector<String> readClassNames(const char *filename )
|
||||
{
|
||||
std::vector<String> classNames;
|
||||
|
||||
@ -87,6 +87,7 @@ const char* params
|
||||
= "{ help | false | Sample app for loading googlenet model }"
|
||||
"{ proto | bvlc_googlenet.prototxt | model configuration }"
|
||||
"{ model | bvlc_googlenet.caffemodel | model weights }"
|
||||
"{ label | synset_words.txt | names of ILSVRC2012 classes }"
|
||||
"{ image | space_shuttle.jpg | path to image file }"
|
||||
"{ opencl | false | enable OpenCL }"
|
||||
;
|
||||
@ -106,6 +107,7 @@ int main(int argc, char **argv)
|
||||
String modelTxt = parser.get<string>("proto");
|
||||
String modelBin = parser.get<string>("model");
|
||||
String imageFile = parser.get<String>("image");
|
||||
String classNameFile = parser.get<String>("label");
|
||||
|
||||
Net net;
|
||||
try {
|
||||
@ -113,7 +115,7 @@ int main(int argc, char **argv)
|
||||
net = dnn::readNetFromCaffe(modelTxt, modelBin);
|
||||
//! [Read and initialize network]
|
||||
}
|
||||
catch (cv::Exception& e) {
|
||||
catch (const cv::Exception& e) {
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
//! [Check that network was read successfully]
|
||||
if (net.empty())
|
||||
@ -169,7 +171,7 @@ int main(int argc, char **argv)
|
||||
//! [Gather output]
|
||||
|
||||
//! [Print results]
|
||||
std::vector<String> classNames = readClassNames();
|
||||
std::vector<String> classNames = readClassNames(classNameFile.c_str());
|
||||
std::cout << "Best class: #" << classId << " '" << classNames.at(classId) << "'" << std::endl;
|
||||
std::cout << "Probability: " << classProb * 100 << "%" << std::endl;
|
||||
//! [Print results]
|
||||
|
Loading…
Reference in New Issue
Block a user