From 88507fa051d263a3d7aa934af1ab51c96d762c05 Mon Sep 17 00:00:00 2001 From: Li Peng Date: Mon, 11 Dec 2017 17:25:41 +0800 Subject: [PATCH] add command parser to caffe googlenet sample Signed-off-by: Li Peng --- samples/dnn/caffe_googlenet.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/samples/dnn/caffe_googlenet.cpp b/samples/dnn/caffe_googlenet.cpp index f40b0d713f..c1f0191948 100644 --- a/samples/dnn/caffe_googlenet.cpp +++ b/samples/dnn/caffe_googlenet.cpp @@ -83,13 +83,29 @@ static std::vector readClassNames(const char *filename = "synset_words.t return classNames; } +const char* params + = "{ help | false | Sample app for loading googlenet model }" + "{ proto | bvlc_googlenet.prototxt | model configuration }" + "{ model | bvlc_googlenet.caffemodel | model weights }" + "{ image | space_shuttle.jpg | path to image file }" + "{ opencl | false | enable OpenCL }" +; + int main(int argc, char **argv) { CV_TRACE_FUNCTION(); - String modelTxt = "bvlc_googlenet.prototxt"; - String modelBin = "bvlc_googlenet.caffemodel"; - String imageFile = (argc > 1) ? argv[1] : "space_shuttle.jpg"; + CommandLineParser parser(argc, argv, params); + + if (parser.get("help")) + { + parser.printMessage(); + return 0; + } + + String modelTxt = parser.get("proto"); + String modelBin = parser.get("model"); + String imageFile = parser.get("image"); Net net; try { @@ -112,6 +128,11 @@ int main(int argc, char **argv) //! [Check that network was read successfully] } + if (parser.get("opencl")) + { + net.setPreferableTarget(DNN_TARGET_OPENCL); + } + //! [Prepare blob] Mat img = imread(imageFile); if (img.empty()) @@ -124,8 +145,9 @@ int main(int argc, char **argv) Mat inputBlob = blobFromImage(img, 1.0f, Size(224, 224), Scalar(104, 117, 123), false); //Convert Mat to batch of images //! [Prepare blob] + net.setInput(inputBlob, "data"); //set the network input + Mat prob = net.forward("prob"); //compute output - Mat prob; cv::TickMeter t; for (int i = 0; i < 10; i++) {