|
Install the Intel® Distribution of OpenVINO™ toolkit core components (latest version: openvino_2019.2.275 that comes with opencv411, without the contrib module and cuda support)
Install the dependencies:
Microsoft Visual Studio* with C++ 2019, 2017, or 2015 with MSBuild
NOTE: If you want to use Microsoft Visual Studio 2019, you are required to install CMake 3.14.
IMPORTANT: As part of this installation, make sure you click the option to add the application to your
PATH
environment variable.
cd C:\Program Files (x86)\IntelSWTools\openvino\bin\
setupvars.bat
cd C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\install_prerequisites
install_prerequisites.bat
Run two Verification Scripts to Verify Installation
cd C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\demo\
demo_security_barrier_camera.bat
Caffe model inference test:
string caffe_root = "C:/Users/FruitLab/OpenCV/OpenCV-Caffe/opencvvino-opencv/caffe-data-images-models/";
Mat image = imread(caffe_root+"cat.jpg");
string labels_file = caffe_root+"caffe_ilsvrc12/synset_words.txt";
string prototxt = caffe_root+"deploy.prototxt";
string model = caffe_root+"bvlc_reference_caffenet.caffemodel";
//load labels
ifstream ifs(labels_file.c_str());
if(!ifs.is_open())
{
CV_Error(Error::StsError, "File" + labels_file + "not found");
string line;
while(getline(ifs, line))
{
//classes.push_back(line);
}
}
Mat blob;
blobFromImage(image, blob, 1.0f, Size(224,224), Scalar(104,117,123),false);
//DNN_BACKEND_INFERENCE_ENGINE
Net net = readNetFromCaffe(prototxt, model);
net.setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE);
net.setPreferableTarget(DNN_TARGET_CPU);
cout<<"[INFO] loading model ..."<<endl;
//prediction
net.setInput(blob);
//vector<float> preds = net.forward();
Mat probs = net.forward();
double freq = getTickFrequency()/1000;
vector<double> layersTimes;
double t = net.getPerfProfile(layersTimes)/freq;
cout<<"[INFO] classification took "<<t<<" ms"<<endl;
It is noted that without openvino acceleration (just use self-built opencv410 for the task):
About 4-5 times faster due to the use of inference engine!!
References:
https://www.learnopencv.com/using-openvino-with-opencv/
https://github.com/spmallick/learnopencv/blob/master/OpenVINO-OpenCV/image-classification.cpp
https://www.pyimagesearch.com/2017/11/06/deep-learning-opencvs-blobfromimage-works/
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-25 02:11
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社