Skip to content

Commit 004a1cd

Browse files
LaurentBergeralalek
authored andcommitted
Merge pull request opencv#10529 from LaurentBerger:ExampleGoogleNet
* Add a parameter labels to command line * default value * samples: caffe_googlenet.cpp minor refactoring
1 parent d0b2e60 commit 004a1cd

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

samples/dnn/caffe_googlenet.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void getMaxClass(const Mat &probBlob, int *classId, double *classProb)
6060
*classId = classNumber.x;
6161
}
6262

63-
static std::vector<String> readClassNames(const char *filename = "synset_words.txt")
63+
static std::vector<String> readClassNames(const char *filename )
6464
{
6565
std::vector<String> classNames;
6666

@@ -87,6 +87,7 @@ const char* params
8787
= "{ help | false | Sample app for loading googlenet model }"
8888
"{ proto | bvlc_googlenet.prototxt | model configuration }"
8989
"{ model | bvlc_googlenet.caffemodel | model weights }"
90+
"{ label | synset_words.txt | names of ILSVRC2012 classes }"
9091
"{ image | space_shuttle.jpg | path to image file }"
9192
"{ opencl | false | enable OpenCL }"
9293
;
@@ -106,14 +107,15 @@ int main(int argc, char **argv)
106107
String modelTxt = parser.get<string>("proto");
107108
String modelBin = parser.get<string>("model");
108109
String imageFile = parser.get<String>("image");
110+
String classNameFile = parser.get<String>("label");
109111

110112
Net net;
111113
try {
112114
//! [Read and initialize network]
113115
net = dnn::readNetFromCaffe(modelTxt, modelBin);
114116
//! [Read and initialize network]
115117
}
116-
catch (cv::Exception& e) {
118+
catch (const cv::Exception& e) {
117119
std::cerr << "Exception: " << e.what() << std::endl;
118120
//! [Check that network was read successfully]
119121
if (net.empty())
@@ -169,7 +171,7 @@ int main(int argc, char **argv)
169171
//! [Gather output]
170172

171173
//! [Print results]
172-
std::vector<String> classNames = readClassNames();
174+
std::vector<String> classNames = readClassNames(classNameFile.c_str());
173175
std::cout << "Best class: #" << classId << " '" << classNames.at(classId) << "'" << std::endl;
174176
std::cout << "Probability: " << classProb * 100 << "%" << std::endl;
175177
//! [Print results]

0 commit comments

Comments
 (0)