Sdcb.Paddle2Onnx 1.0.0-preview.2

The ID prefix of this package has been reserved for one of the owners of this package by Prefix Reserved
This is a prerelease version of Sdcb.Paddle2Onnx.
dotnet add package Sdcb.Paddle2Onnx --version 1.0.0-preview.2
NuGet\Install-Package Sdcb.Paddle2Onnx -Version 1.0.0-preview.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sdcb.Paddle2Onnx" Version="1.0.0-preview.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sdcb.Paddle2Onnx --version 1.0.0-preview.2
#r "nuget: Sdcb.Paddle2Onnx, 1.0.0-preview.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Sdcb.Paddle2Onnx as a Cake Addin
#addin nuget:?package=Sdcb.Paddle2Onnx&version=1.0.0-preview.2&prerelease

// Install Sdcb.Paddle2Onnx as a Cake Tool
#tool nuget:?package=Sdcb.Paddle2Onnx&version=1.0.0-preview.2&prerelease


Sdcb.Paddle2Onnx is an open-source project that provides C#/.NET wrapper for Paddle2Onnx, a tool to convert PaddlePaddle models to ONNX models. It allows users to convert PaddlePaddle models to ONNX models and use them in various deep learning frameworks.

NOTE: This project is only supported in Windows.


To use Sdcb.Paddle2Onnx, you need to install .NET standard 2.0 or later.

To install Sdcb.Paddle2Onnx, you can use the following command in the Package Manager Console:

Install-Package Sdcb.Paddle2Onnx
Install-Package Sdcb.Paddle2Onnx.runtime.win64


NuGet Package 💼 Version 📌 Description 📚
Sdcb.Paddle2Onnx NuGet Paddle2Onnx C++ API .NET binding
Sdcb.Paddle2Onnx.runtime.win64 NuGet win-x64 Paddle2Onnx runtime


Checking If a Model Can Be Converted

To check if a PaddlePaddle model can be converted to an ONNX model, you can use the Paddle2OnnxConverter.CanConvert method. You can provide either the file paths or the byte arrays of the model and the parameter files.

string modelFile = "model.pdmodel";
string paramsFile = "model.pdiparams";
bool can = Paddle2OnnxConverter.CanConvert(modelFile, paramsFile);

Converting PaddlePaddle Models to ONNX Models

To convert a PaddlePaddle model to an ONNX model, you can use the Paddle2OnnxConverter.ConvertToOnnx method. You can provide either the file paths or the byte arrays of the model and the parameter files.

byte[] modelBuffer = File.ReadAllBytes("model.pdmodel");
byte[] paramsBuffer = File.ReadAllBytes("model.pdiparams");
byte[] onnxModel = Paddle2OnnxConverter.ConvertToOnnx(modelBuffer, paramsBuffer);

Describing a PaddlePaddle Model

To describe a PaddlePaddle model, you can use the Paddle2OnnxConverter.DescribePaddleModel method. You need to provide the byte array of the model file.

byte[] modelBuffer = File.ReadAllBytes("model.pdmodel");
PaddleModelInfo info = Paddle2OnnxConverter.DescribePaddleModel(modelBuffer);
Console.WriteLine($"Input shapes: {string.Join(", ", info.InputShapes)}");
Console.WriteLine($"Output shapes: {string.Join(", ", info.OutputShapes)}");

Describing an ONNX Model

To describe an ONNX model, you can use the Paddle2OnnxConverter.DescribeOnnxModel method. You need to provide the byte array of the ONNX model.

OnnxModelInfo info = Paddle2OnnxConverter.DescribeOnnxModel(onnxModel);
Console.WriteLine("Input shapes:");
Console.WriteLine(string.Join("\n", info.Inputs.Select(x => x.ToString())));
Console.WriteLine("Output shapes:");
Console.WriteLine(string.Join("\n", info.Outputs.Select(x => x.ToString())));

Using Custom Operators

To use custom operators when converting a PaddlePaddle model to an ONNX model, you can provide an array of CustomOp objects to the Paddle2OnnxConverter.CanConvert method.

CustomOp[] ops = new[]
    new CustomOp("fc", "FC"),
    new CustomOp("softmax", "Softmax")

bool can = Paddle2OnnxConverter.CanConvert(modelFile, paramsFile, customOps: ops);

Using a Different Backend

To use a different backend when converting a PaddlePaddle model to an ONNX model, you can provide the name of the backend to the Paddle2OnnxConverter.CanConvert method. Currently, the only supported backend is TensorRT.

bool can = Paddle2OnnxConverter.CanConvert(modelFile, paramsFile, deployBackend: "tensorrt");
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0-preview.2 116 7/13/2023
1.0.0-preview.1 75 7/12/2023