OpenV是一個集成視覺和深度學習計算庫的開源庫,它基於OpenCV和OpenVX框架,並優化了在多種硬件上的性能表現,為計算機視覺應用提供了高效易用的解決方案。本文從多個方面介紹OpenV的特點和應用場景。
一、OpenVINO
OpenV根據應用場景提供了多個不同的接口,其中OpenVINO是它在視覺領域中最流行的接口之一。OpenVINO可以通過基於神經網絡的推理加速計算機視覺應用的運行速度。若使用CPU,OpenVINO可以利用多線程或OpenMP進行優化,而使用GPU可以利用OpenCL和CUDA等計算框架進行優化。OpenVINO還支持基於自定義硬件的推理,如神經網絡處理單元(NPU)。
二、OpenVINO撲克牌檢測示例
下面是一個OpenVINO撲克牌檢測示例,可以檢測圖片中的撲克牌,算法使用預訓練的神經網絡模型。
#include "opencv2/dnn.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include
#include
#include
#include
#include
#include
using namespace cv;
using namespace dnn;
using namespace std;
using namespace std::chrono;
int main(int argc, char** argv)
{
String modelTxt = "/path/to/model/deploy.prototxt";
String modelBin = "/path/to/model/snapshot_iter_8910.caffemodel";
// Initialize network
Net net = readNetFromCaffe(modelTxt, modelBin);
// Load image
Mat frame = imread("/path/to/image.jpg");
// Create 4D blob from input image
Mat blob;
blobFromImage(frame, blob, 1.0, Size(227, 227), Scalar(104, 117, 123), false, false);
// Set input blob
net.setInput(blob);
// Forward pass through network
Mat output = net.forward();
// Determine label with highest confidence
Point maxPt;
minMaxLoc(output.reshape(1, 1), 0, 0, 0, &maxPt);
// Read label names
vector classNames;
ifstream classNamesFile("/path/to/class/names/file.txt");
string className = "";
while (getline(classNamesFile, className))
{
classNames.push_back(className);
}
// Display results
string label = classNames[maxPt.x];
putText(frame, label, Point(10, 30), FONT_HERSHEY_SIMPLEX, 0.7, Scalar(0, 0, 255), 2);
imshow("Output", frame);
waitKey(0);
return 0;
}
三、OpenVPen
OpenVPen是OpenV在深度學習領域的另一個接口。它提供了基於GPU加速的代碼生成和優化工具,能夠優化和升級現有的深度學習模型,並將它們轉化為高效的計算圖,更好地運行於沒有GPU的平台上。OpenVPen內置了一系列的優化器,可以自動處理數據流中的優化問題,例如圖像歸一化等操作,從而加速深度學習應用的推理和訓練。
四、OpenVINO車輛檢測示例
下面是一個OpenVINO車輛檢測示例,可以檢測視頻中的汽車,算法使用預訓練的神經網絡模型。
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
using namespace InferenceEngine;
int main()
{
// Plugin initialization for specified device and load extensions library if specified
PluginDispatcher dispatcher({ "" });
auto plugin = dispatcher.getSuitablePlugin(TargetDevice::eCPU);
// Read IR generated by ModelOptimizer (.xml and .bin files)
CNNNetReader networkReader;
networkReader.ReadNetwork("vehicle-detection-adas-0002.xml");
networkReader.ReadWeights("vehicle-detection-adas-0002.bin");
// Configure input & output
auto inputInfo = networkReader.getNetwork().getInputInfo().begin()->second;
inputInfo->setPrecision(Precision::FP16);
inputInfo->setLayout(Layout::NHWC);
auto outputInfo = networkReader.getNetwork().getOutputsInfo().begin()->second;
outputInfo->setPrecision(Precision::FP16);
outputInfo->setLayout(Layout::NCHW);
// Load network to the plugin
ExecutableNetwork executableNetwork = plugin.LoadNetwork(networkReader.getNetwork(), {});
// Create inference request iterators
auto inputBlob = executableNetwork.CreateBlobProxy(inputInfo);
auto outputBlob = executableNetwork.GetOutputsInfo()[0]->GetBlob();
// Read input frame
Mat inFrame = cv::imread("/path/to/input/frame.jpg");
// Resize to network's input size and assign to input blob
Mat outFrame;
Size size(inputInfo->getTensorDesc().getDims()[3], inputInfo->getTensorDesc().getDims()[2]);
cv::resize(inFrame, outFrame, size);
std::memcpy(inputBlob->buffer(), outFrame.ptr(), outFrame.total() * outFrame.elemSize());
// Start inference
auto t0 = chrono::high_resolution_clock::now();
auto inferRequest = executableNetwork.CreateInferRequest();
inferRequest.SetBlob(inputInfo->name(), inputBlob);
inferRequest.Infer();
auto t1 = chrono::high_resolution_clock::now();
// Retrieve information from the output blob
MemoryBlob::Ptr moutput = as(outputBlob);
const auto loutputs = outputBlob->getTensorDesc().getDims();
const size_t lwidth = loutputs[3];
const size_t lheight = loutputs[2];
Mat detectionMat(lheight, lwidth, CV_32F, moutput->rmap().fptr());
// Draw bounding boxes around detected cars
float confidenceThreshold = 0.7f;
for (int i = 0; i < detectionMat.rows; i++)
{
float confidence = detectionMat.at(i, 2);
if (confidence > confidenceThreshold)
{
int xmin = static_cast(detectionMat.at(i, 3) * inFrame.cols);
int ymin = static_cast(detectionMat.at(i, 4) * inFrame.rows);
int xmax = static_cast(detectionMat.at(i, 5) * inFrame.cols);
int ymax = static_cast(detectionMat.at(i, 6) * inFrame.rows);
rectangle(inFrame, Point(xmin, ymin), Point(xmax, ymax), Scalar(0, 255, 255), 2);
}
}
// Show result
namedWindow("Vehicle Detection", WINDOW_AUTOSIZE);
imshow("Vehicle Detection", inFrame);
waitKey(0);
cout << "Inference time: " << chrono::duration(t1 - t0).count() << " seconds" << endl;
return 0;
}
五、OpenVPen Connect
OpenVPen Connect是一個基於Python的API,提供了為深度學習和計算機視覺應用編寫高性能、易擴展的代碼的能力。它允許用戶可以更方便地打包和部署應用,以及在更大的計算資源上運行。它還支持在多個主機之間進行分布式訓練。
六、OpenVINO硬件要求
OpenVINO支持各種平台和設備,尤其是CPU、GPU和FPGA等硬件設備。具體的要求取決於應用場景和硬件設備,通常可以滿足大多數現代設備的需求。
七、OpenVINO證書有用嗎?
OpenVINO提供了認證證書,它是一個針對OpenVINO的認證系統,考核申請人在OpenVINO框架的使用和應用上的技能和知識。OpenVINO證書可以證明一個人在OpenVINO技術上具有專業知識和技能,成為用戶找工作、轉行或證明自己的首選證明之一。
八、OpenVINO 多輸出推理
OpenVINO支持多輸出推理,這是在神經網絡中使用的一種技術。神經網絡通常包含多個輸出,每個輸出都用於區分不同的屬性或特徵。OpenVINO允許用戶獲取和處理多個輸出,從而可以在單次推理中獲得多個結果。
九、OpenVINO轉的模型預測不對
如果OpenVINO轉換模型所得到的預測結果不準確,可能是由於OpenVINO不支持模型中的某些特性導致的。這時需要對模型進行更深入的分析和調整,確保所用模型和參數與OpenVINO的要求相符合,以提高預測的準確度。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/150979.html
微信掃一掃
支付寶掃一掃