Sdcb.Paddle2Onnx
1.0.0-preview.1
Prefix Reserved
See the version list below for details.
dotnet add package Sdcb.Paddle2Onnx --version 1.0.0-preview.1
NuGet\Install-Package Sdcb.Paddle2Onnx -Version 1.0.0-preview.1
<PackageReference Include="Sdcb.Paddle2Onnx" Version="1.0.0-preview.1" />
paket add Sdcb.Paddle2Onnx --version 1.0.0-preview.1
#r "nuget: Sdcb.Paddle2Onnx, 1.0.0-preview.1"
// Install Sdcb.Paddle2Onnx as a Cake Addin #addin nuget:?package=Sdcb.Paddle2Onnx&version=1.0.0-preview.1&prerelease // Install Sdcb.Paddle2Onnx as a Cake Tool #tool nuget:?package=Sdcb.Paddle2Onnx&version=1.0.0-preview.1&prerelease
Sdcb.Paddle2Onnx
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.
Installation
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
Packages
NuGet Package 💼 | Version 📌 | Description 📚 |
---|---|---|
Sdcb.Paddle2Onnx | Paddle2Onnx C++ API .NET binding | |
Sdcb.Paddle2Onnx.runtime.win64 | wi-x64 Paddle2Onnx runtime |
Usage
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.InputShapes));
Console.WriteLine():
Console.WriteLine("Output shapes:");
Console.WriteLine(string.Join("\n", info.OutputShapes));
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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.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. |
-
.NETStandard 2.0
- System.Memory (>= 4.5.5)
-
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 | 178 | 7/13/2023 |
1.0.0-preview.1 | 98 | 7/12/2023 |