OpenVINO可以獲得模型的輸入節(jié)點(diǎn)信息:
輸入節(jié)點(diǎn)的名字
-
Model Optimizer轉(zhuǎn)換后的模型精度選擇:對(duì)于IR模型來(lái)說(shuō),F(xiàn)P16 使用最普遍且性能最高對(duì)于IR模型來(lái)說(shuō)嗡贺,F(xiàn)P16 使用最普遍且性能最高
-
輸入節(jié)點(diǎn)數(shù)據(jù)的精度選擇:U8使用最普遍輸入節(jié)點(diǎn)數(shù)據(jù)的精度選擇:U8
-
輸出節(jié)點(diǎn)數(shù)據(jù)的精度選擇:FP32使用最普遍輸出節(jié)點(diǎn)數(shù)據(jù)的精度選擇:FP32
- 輸入節(jié)點(diǎn)數(shù)據(jù)的形狀(shape)
-
輸入節(jié)點(diǎn)數(shù)據(jù)的布局(layout),默認(rèn)情況下起胰,輸入節(jié)點(diǎn)的layout是Layout::NCHW;輸出節(jié)點(diǎn)由維度定義輸出節(jié)點(diǎn)的layout由數(shù)據(jù)維度決定
layout的代碼定義如下:
#include <ie_common.h>
enum Layout
{
ANY = 0,
NCHW = 1,
NHWC = 2,
NCDHW = 3,
NDHWC = 4,
OIHW = 64,
GOIHW = 65,
OIDHW = 66,
GOIDHW = 67,
SCALAR = 95,
C = 96,
CHW = 128,
HWC = 129,
HW = 192,
NC = 193,
CN = 194,
BLOCKED = 200,
};
- 輸入節(jié)點(diǎn)是否支持Resize算法整份,默認(rèn)是NO_RESIZE待错,即不會(huì)自動(dòng)縮放輸入數(shù)據(jù)籽孙。使用下面的代碼設(shè)置是否需要支持Resize烈评。
input_data->getPreProcess().setResizeAlgorithm(InferenceEngine::RESIZE_BILINEAR);
Resize算法種類的代碼定義如下
#include <ie_preprocess.hpp>
enum ResizeAlgorithm
{
NO_RESIZE = 0,
RESIZE_BILINEAR,
RESIZE_AREA,
};
- 數(shù)據(jù)的色彩模式(Color format):默認(rèn)情況下,Inference Engine假定輸入數(shù)據(jù)的色彩模式是BGR犯建,并且禁止色彩模式讲冠,即ColorFormat::RAW。注意:BGR是OpenCV的默認(rèn)色彩模式适瓦。
ColorFormat代碼定義如下:
#include <ie_common.h>
enum ColorFormat
{
RAW = 0u,
RGB,
BGR,
RGBX,
BGRX,
NV12,
I420,
};
- 輸入節(jié)點(diǎn)是否支持平均竿开,默認(rèn)是不支持對(duì)輸入數(shù)據(jù)做平均。MeanVariant代碼定義如下:
#include <ie_preprocess.hpp>
enum MeanVariant
{
MEAN_IMAGE, //mean value is specified for each input pixel
MEAN_VALUE, //mean value is specified for each input channel
NONE, //no mean value specified
};
整套范例程序如下所示:
// OpenVINO Sample code for PPYOLOv2
#include<string>
#include<iostream>
#include<map>
#include<inference_engine.hpp>
#include<ngraph/ngraph.hpp>
#include "ocv_common.hpp"
using namespace InferenceEngine;
using namespace std;
//配置推理計(jì)算設(shè)備玻熙,IR文件路徑否彩,圖片路徑,閾值和標(biāo)簽
string DEVICE = "CPU";
string IR_FileXML = "D:/pd/ov_model/ppyolov2.xml";
string imageFile = "road554.png";
float confidence_threshold = 0.7; //取值0~1
vector<string> labels = { "speedlimit","crosswalk","trafficlight","stop" }; //標(biāo)簽輸入
int main()
{
// --------------------------- 1. 創(chuàng)建Core對(duì)象 --------------------------------------
cout << "1.Create Core Object." << endl;
Core ie; // 創(chuàng)建Core對(duì)象
cout << "InferenceEngine: " << GetInferenceEngineVersion() << endl;//輸出IE版本信息
cout << ie.GetVersions(DEVICE) << std::endl; //輸出插件版本信息, “<<”運(yùn)算符重載代碼在common.hpp中
// ------------------- 2. 將模型文件載入推理設(shè)備 ------------------------------------
cout << "2.Load the Model to the Device..." <<endl;
CNNNetwork network = ie.ReadNetwork(IR_FileXML); //The CNNNetwork class contains all the information about the Neural Network
network.setBatchSize(1); //Set the inference batch size
cout << "The network's name: " << network.getName() <<std::endl;
cout << "The number of layers in the network : " << network.layerCount() << std::endl;
cout << "Collect all input nodes informations : " << std::endl;
auto inputNodes = network.getInputsInfo();
for (auto& i : inputNodes)
{
cout << "node name: " << i.first << "; the shape:";
for (auto& item : i.second->getTensorDesc().getDims())
{
cout << item << ",";
}
cout << "the precision: " << i.second->getPrecision() << "; ";
cout << "the layout: " << i.second->getLayout() << "; ";
cout << "the color format: " << i.second->getPreProcess().getColorFormat() << "; ";
cout << "the ResizeAlgorithm: " << i.second->getPreProcess().getResizeAlgorithm()<< endl;
i.second->getPreProcess().setResizeAlgorithm(InferenceEngine::RESIZE_BILINEAR);
cout << "Set the ResizeAlgorithm: " << i.second->getPreProcess().getResizeAlgorithm() << endl;
cout << "The Default mean variant: " << i.second->getPreProcess().getMeanVariant() << endl;
return 0;
}
運(yùn)行結(jié)果如下所示:OpenVINO獲取模型輸入節(jié)點(diǎn)信息
結(jié)論:
- 模型精度設(shè)置為FP16
- 模型的圖像數(shù)據(jù)輸入節(jié)點(diǎn)數(shù)據(jù)精度設(shè)置為U8嗦随,其余輔助信息節(jié)點(diǎn)保持默認(rèn)
- 模型的圖像數(shù)據(jù)輸入節(jié)點(diǎn)的color format保持默認(rèn)BGR列荔,不做自動(dòng)轉(zhuǎn)換;layout保持默認(rèn):NCHW枚尼。
- 模型的輸出數(shù)據(jù)精度為FP32
- OpenVINO的color format自動(dòng)轉(zhuǎn)換贴浙,圖像尺寸自動(dòng)放縮Resize和圖像數(shù)據(jù)自動(dòng)平均功能保持禁用;color format轉(zhuǎn)換為BGR在圖像采集時(shí)完成署恍;Resize和Normalize功能手動(dòng)寫一個(gè)preprocess函數(shù)來(lái)實(shí)現(xiàn)