当前位置: 首页 > news >正文

C#Onnx模型信息查看工具

效果

Netron效果

项目

代码

using Microsoft.ML.OnnxRuntime;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;namespace Onnx_Demo
{public partial class frmMain : Form{public frmMain(){InitializeComponent();}string fileFilter = "*.*|*.onnx;";string model_path;StringBuilder sb = new StringBuilder();InferenceSession onnx_session;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();ShowInfo(model_path);}void ShowInfo(string model_path){try{onnx_session = new InferenceSession(model_path);}catch (Exception ex){MessageBox.Show("读取模型异常:" + ex.Message);}sb.Clear();//Model Propertiessb.AppendLine("Model Properties");sb.AppendLine("-------------------------");Dictionary<string, string> CustomMetadataMap = onnx_session.ModelMetadata.CustomMetadataMap;foreach (string key in CustomMetadataMap.Keys){sb.AppendLine(String.Format("{0}:{1}",key, CustomMetadataMap[key])) ;}sb.AppendLine("---------------------------------------------------------------");IReadOnlyList<string> InputNames = onnx_session.InputNames;IReadOnlyDictionary<string, NodeMetadata> InputMetadata = onnx_session.InputMetadata;//Inputssb.AppendLine("");sb.AppendLine("Inputs");sb.AppendLine("-------------------------");foreach (var item in InputMetadata){sb.AppendLine("name:" + item.Key);NodeMetadata  nmData= item.Value;int[] dim = nmData.Dimensions;sb.AppendLine("tensor:" + nmData.ElementDataType.ToString()+"["+ String.Join(", ", dim)+"]");}sb.AppendLine("---------------------------------------------------------------");IReadOnlyList<string> OutputNames = onnx_session.OutputNames;IReadOnlyDictionary<string, NodeMetadata> OutputMetadata = onnx_session.OutputMetadata;//Outputssb.AppendLine("");sb.AppendLine("Outputs");sb.AppendLine("-------------------------");foreach (var item in OutputMetadata){sb.AppendLine("name:" + item.Key);NodeMetadata nmData = item.Value;int[] dim = nmData.Dimensions;sb.AppendLine("tensor:" + nmData.ElementDataType.ToString() + "[" + String.Join(", ", dim) + "]");}sb.AppendLine("---------------------------------------------------------------");txtInfo.Text = sb.ToString();}private void Form1_Load(object sender, EventArgs e){}}
}

下载

可执行程序exe包下载

源码下载

http://www.lryc.cn/news/215898.html

相关文章:

  • RK3588 ubuntu系统安装opencv
  • 常用的vue UI组件库
  • 防范欺诈GPT
  • 【Java】多线程案例(单例模式,阻塞队列,定时器,线程池)
  • STM32:使用蓝牙模块
  • Blazor 虚拟滚动/瀑布流加载Table数据
  • 数字化浪潮下,AI数字人融入多元化应用场景
  • JVM虚拟机:JVM的垃圾回收清除算法(GC)有哪些
  • 我应该删除低质量页面以提高Google排名吗?
  • 【实战Flask API项目指南】之六 数据库集成 SQLAlchemy
  • MFC网络通信-Udp服务端
  • 最简单且有效的msvcp140.dll丢失的解决方法,有效的解决msvcp140.dll丢失
  • HBase理论与实践-基操与实践
  • 内存管理设计精要
  • Java——StringBuffer与StringBuilder的区别
  • 基于深度学习的菠萝与果叶视觉识别及切断机构设计
  • springboot整合七牛云oss操作文件
  • 跨国传输的常见问题与对应解决方案
  • Git(七).git 文件夹瘦身,GitLab 永久删除文件
  • 多线程锁的升级原理是什么
  • 金山文档轻维表之删除所有行记录
  • 站坑站坑站坑站坑站坑
  • 在Vue中,你可以使用动态import()语法来动态加载组件
  • 金蝶云星空表单插件获取日期控件判空处理(代码示例)
  • 通过xshell传输文件到服务器
  • centos7.9编译安装python3.7.2
  • 【教3妹学编程-算法题】2913. 子数组不同元素数目的平方和 I
  • 是否会有 GPT-5 的发布?
  • 使用 Selenium Python 检查元素是否存在
  • const迭代器与模板构造函数