What | Links and Status |
---|---|
OnnxSharp |
|
dotnet-onnx |
ONNX format parsing and manipulation in C# and with command line .NET tool.
Install latest version of .NET:
- PowerShell (Windows): https://dot.net/v1/dotnet-install.ps1
- Bash (Linux/macOS): https://dot.net/v1/dotnet-install.sh
What | How |
---|---|
Install | dotnet add PROJECT.csproj package OnnxSharp |
Parse | var model = ModelProto.Parser.ParseFromFile("mnist-8.onnx"); |
Info | var info = model.Graph.Info(); |
Clean | model.Graph.Clean(); |
SetDim | model.Graph.SetDim(); |
Write | model.WriteToFile("mnist-8-clean-dynamic.onnx"); |
What | How |
---|---|
Install | dotnet tool install dotnet-onnx -g |
Info | dotnet onnx info mnist-8.onnx |
Info | dotnet onnx info mnist-8.onnx |
Clean | dotnet onnx clean mnist-8.onnx mnist-8-clean.onnx |
SetDim | dotnet onnx setdim mnist-8.onnx mnist-8-setdim.onnx |
Base functionality is based on:
.\protoc.exe .\onnx.proto3 --csharp_out=OnnxSharp
Everything else written in beautiful C# 9.0 as extensions to this.
using Onnx;
// Examples see https://github.com/onnx/models
var onnxInputFilePath = @"mnist-8.onnx";
var model = ModelProto.Parser.ParseFromFile(onnxInputFilePath);
var graph = model.Graph;
// Clean graph e.g. remove initializers from inputs that may prevent constant folding
graph.Clean();
// Set dimension in graph to enable dynamic batch size during inference
graph.SetDim(dimIndex: 0, DimParamOrValue.New("N"));
// Get summarized info about the graph
var info = graph.Info();
System.Console.WriteLine(info);
model.WriteToFile(@"mnist-8-clean-dynamic-batch-size.onnx");