mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Merge pull request #10277 from pengli:dnn
This commit is contained in:
commit
766a0c0f25
@ -83,13 +83,29 @@ static std::vector<String> readClassNames(const char *filename = "synset_words.t
|
|||||||
return classNames;
|
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)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
CV_TRACE_FUNCTION();
|
CV_TRACE_FUNCTION();
|
||||||
|
|
||||||
String modelTxt = "bvlc_googlenet.prototxt";
|
CommandLineParser parser(argc, argv, params);
|
||||||
String modelBin = "bvlc_googlenet.caffemodel";
|
|
||||||
String imageFile = (argc > 1) ? argv[1] : "space_shuttle.jpg";
|
if (parser.get<bool>("help"))
|
||||||
|
{
|
||||||
|
parser.printMessage();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
String modelTxt = parser.get<string>("proto");
|
||||||
|
String modelBin = parser.get<string>("model");
|
||||||
|
String imageFile = parser.get<String>("image");
|
||||||
|
|
||||||
Net net;
|
Net net;
|
||||||
try {
|
try {
|
||||||
@ -112,6 +128,11 @@ int main(int argc, char **argv)
|
|||||||
//! [Check that network was read successfully]
|
//! [Check that network was read successfully]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (parser.get<bool>("opencl"))
|
||||||
|
{
|
||||||
|
net.setPreferableTarget(DNN_TARGET_OPENCL);
|
||||||
|
}
|
||||||
|
|
||||||
//! [Prepare blob]
|
//! [Prepare blob]
|
||||||
Mat img = imread(imageFile);
|
Mat img = imread(imageFile);
|
||||||
if (img.empty())
|
if (img.empty())
|
||||||
@ -124,8 +145,9 @@ int main(int argc, char **argv)
|
|||||||
Mat inputBlob = blobFromImage(img, 1.0f, Size(224, 224),
|
Mat inputBlob = blobFromImage(img, 1.0f, Size(224, 224),
|
||||||
Scalar(104, 117, 123), false); //Convert Mat to batch of images
|
Scalar(104, 117, 123), false); //Convert Mat to batch of images
|
||||||
//! [Prepare blob]
|
//! [Prepare blob]
|
||||||
|
net.setInput(inputBlob, "data"); //set the network input
|
||||||
|
Mat prob = net.forward("prob"); //compute output
|
||||||
|
|
||||||
Mat prob;
|
|
||||||
cv::TickMeter t;
|
cv::TickMeter t;
|
||||||
for (int i = 0; i < 10; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user