Skip to content

Commit 88507fa

Browse files
committed
add command parser to caffe googlenet sample
Signed-off-by: Li Peng <peng.li@intel.com>
1 parent 9665dde commit 88507fa

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

samples/dnn/caffe_googlenet.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,29 @@ static std::vector<String> readClassNames(const char *filename = "synset_words.t
8383
return classNames;
8484
}
8585

86+
const char* params
87+
= "{ help | false | Sample app for loading googlenet model }"
88+
"{ proto | bvlc_googlenet.prototxt | model configuration }"
89+
"{ model | bvlc_googlenet.caffemodel | model weights }"
90+
"{ image | space_shuttle.jpg | path to image file }"
91+
"{ opencl | false | enable OpenCL }"
92+
;
93+
8694
int main(int argc, char **argv)
8795
{
8896
CV_TRACE_FUNCTION();
8997

90-
String modelTxt = "bvlc_googlenet.prototxt";
91-
String modelBin = "bvlc_googlenet.caffemodel";
92-
String imageFile = (argc > 1) ? argv[1] : "space_shuttle.jpg";
98+
CommandLineParser parser(argc, argv, params);
99+
100+
if (parser.get<bool>("help"))
101+
{
102+
parser.printMessage();
103+
return 0;
104+
}
105+
106+
String modelTxt = parser.get<string>("proto");
107+
String modelBin = parser.get<string>("model");
108+
String imageFile = parser.get<String>("image");
93109

94110
Net net;
95111
try {
@@ -112,6 +128,11 @@ int main(int argc, char **argv)
112128
//! [Check that network was read successfully]
113129
}
114130

131+
if (parser.get<bool>("opencl"))
132+
{
133+
net.setPreferableTarget(DNN_TARGET_OPENCL);
134+
}
135+
115136
//! [Prepare blob]
116137
Mat img = imread(imageFile);
117138
if (img.empty())
@@ -124,8 +145,9 @@ int main(int argc, char **argv)
124145
Mat inputBlob = blobFromImage(img, 1.0f, Size(224, 224),
125146
Scalar(104, 117, 123), false); //Convert Mat to batch of images
126147
//! [Prepare blob]
148+
net.setInput(inputBlob, "data"); //set the network input
149+
Mat prob = net.forward("prob"); //compute output
127150

128-
Mat prob;
129151
cv::TickMeter t;
130152
for (int i = 0; i < 10; i++)
131153
{

0 commit comments

Comments
 (0)