OpenVINO获取模型输入节点信息

2022-01-23  本文已影响0人  LabVIEW_Python

OpenVINO可以获得模型的输入节点信息:

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,
};

input_data->getPreProcess().setResizeAlgorithm(InferenceEngine::RESIZE_BILINEAR);

Resize算法种类的代码定义如下

#include <ie_preprocess.hpp>

enum ResizeAlgorithm
{
    NO_RESIZE       = 0,
    RESIZE_BILINEAR,
    RESIZE_AREA,
};
#include <ie_common.h>

enum ColorFormat
{
    RAW  = 0u,
    RGB,
    BGR,
    RGBX,
    BGRX,
    NV12,
    I420,
};
#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;

//配置推理计算设备,IR文件路径,图片路径,阈值和标签
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" }; //标签输入

int main()
{

    // --------------------------- 1. 创建Core对象 --------------------------------------
    cout << "1.Create Core Object." << endl;
    Core ie;  // 创建Core对象
    cout << "InferenceEngine: " << GetInferenceEngineVersion() << endl;//输出IE版本信息
    cout << ie.GetVersions(DEVICE) << std::endl; //输出插件版本信息, “<<”运算符重载代码在common.hpp中

    // ------------------- 2. 将模型文件载入推理设备 ------------------------------------
    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;
}
运行结果如下所示: OpenVINO获取模型输入节点信息

结论

上一篇 下一篇

猜你喜欢

热点阅读