C# OpenVINO 模型信息查看工具

目录

效果

支持模型

项目

代码

下载


C# OpenVINO 模型信息查看工具

效果

支持模型

ONNX format (*.onnx)
PDPD (*.pdmodel)
TF (*.pb)
TFLite (*.tflite) 

项目

代码

using Sdcb.OpenVINO;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace OpenVINO_Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /*
        模型可选类型
        ONNX format (*.onnx)
        PDPD (*.pdmodel)
        TF (*.pb)
        TFLite (*.tflite)
         */
        string fileFilter = "*.*|*.onnx;*.pdmodel;*.pb;*.tflite;*.tiff;";

        StringBuilder sb = new StringBuilder();
        string model_path = "";

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;

            txtInfo.Text = "";
            model_path = ofd.FileName;
            txtPath.Text = model_path;

            txtInfo.Text = "正在读取,请稍后……";
            Application.DoEvents();

            sb.Clear();
            txtInfo.Text = "";

            try
            {
                var v = OVCore.Version.ToString();
                sb.AppendLine(v);
                sb.AppendLine("---------------------------------------------------------------");
                var ad = OVCore.Shared.AvailableDevices;
                sb.AppendLine("本机可用设备");
                foreach (var item in ad)
                {
                    sb.AppendLine(item.ToString());
                }
                sb.AppendLine("---------------------------------------------------------------");

                Model rawModel = OVCore.Shared.ReadModel(model_path);
                //Inputs
                sb.AppendLine("");
                sb.AppendLine("Inputs");
                sb.AppendLine("-------------------------");

                IOPort temp;
                Dimension[] dim;
                IEnumerator<IOPort> items = rawModel.Inputs.GetEnumerator();
                while (items.MoveNext())
                {
                    temp = items.Current;
                    sb.AppendLine("name:" + temp.Name);
                    dim = temp.PartialShape.Dimensions;
                    sb.AppendLine("tensor:" + temp.ElementType + "[" + String.Join(", ", dim) + "]");
                    sb.AppendLine("");
                }
                sb.AppendLine("---------------------------------------------------------------");

                //Outputs
                sb.AppendLine("");
                sb.AppendLine("Outputs");
                sb.AppendLine("-------------------------");
                items = rawModel.Outputs.GetEnumerator();
                while (items.MoveNext())
                {
                    temp = items.Current;
                    sb.AppendLine("name:" + temp.Name);
                    dim = temp.PartialShape.Dimensions;
                    sb.AppendLine("tensor:" + temp.ElementType + "[" + String.Join(", ", dim) + "]");
                    sb.AppendLine("");
                }
                sb.AppendLine("---------------------------------------------------------------");
                txtInfo.Text = sb.ToString();

            }
            catch (Exception ex)
            {
                txtInfo.Text = "加载模型出错,请选择正确的模型!\r\n";
                txtInfo.Text += "错误信息:\r\n";
                txtInfo.Text += ex.Message;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }
    }
}

using Sdcb.OpenVINO;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace OpenVINO_Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /*
        模型可选类型
        ONNX format (*.onnx)
        PDPD (*.pdmodel)
        TF (*.pb)
        TFLite (*.tflite)
         */
        string fileFilter = "*.*|*.onnx;*.pdmodel;*.pb;*.tflite;*.tiff;";

        StringBuilder sb = new StringBuilder();
        string model_path = "";

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;

            txtInfo.Text = "";
            model_path = ofd.FileName;
            txtPath.Text = model_path;

            txtInfo.Text = "正在读取,请稍后……";
            Application.DoEvents();

            sb.Clear();
            txtInfo.Text = "";

            try
            {
                var v = OVCore.Version.ToString();
                sb.AppendLine(v);
                sb.AppendLine("---------------------------------------------------------------");
                var ad = OVCore.Shared.AvailableDevices;
                sb.AppendLine("本机可用设备");
                foreach (var item in ad)
                {
                    sb.AppendLine(item.ToString());
                }
                sb.AppendLine("---------------------------------------------------------------");

                Model rawModel = OVCore.Shared.ReadModel(model_path);
                //Inputs
                sb.AppendLine("");
                sb.AppendLine("Inputs");
                sb.AppendLine("-------------------------");

                IOPort temp;
                Dimension[] dim;
                IEnumerator<IOPort> items = rawModel.Inputs.GetEnumerator();
                while (items.MoveNext())
                {
                    temp = items.Current;
                    sb.AppendLine("name:" + temp.Name);
                    dim = temp.PartialShape.Dimensions;
                    sb.AppendLine("tensor:" + temp.ElementType + "[" + String.Join(", ", dim) + "]");
                    sb.AppendLine("");
                }
                sb.AppendLine("---------------------------------------------------------------");

                //Outputs
                sb.AppendLine("");
                sb.AppendLine("Outputs");
                sb.AppendLine("-------------------------");
                items = rawModel.Outputs.GetEnumerator();
                while (items.MoveNext())
                {
                    temp = items.Current;
                    sb.AppendLine("name:" + temp.Name);
                    dim = temp.PartialShape.Dimensions;
                    sb.AppendLine("tensor:" + temp.ElementType + "[" + String.Join(", ", dim) + "]");
                    sb.AppendLine("");
                }
                sb.AppendLine("---------------------------------------------------------------");
                txtInfo.Text = sb.ToString();

            }
            catch (Exception ex)
            {
                txtInfo.Text = "加载模型出错,请选择正确的模型!\r\n";
                txtInfo.Text += "错误信息:\r\n";
                txtInfo.Text += ex.Message;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }
    }
}

下载

源码下载

猜你喜欢

转载自blog.csdn.net/lw112190/article/details/134771928