PaddleOcrNet.Gpu
2.2.0
See the version list below for details.
dotnet add package PaddleOcrNet.Gpu --version 2.2.0
NuGet\Install-Package PaddleOcrNet.Gpu -Version 2.2.0
<PackageReference Include="PaddleOcrNet.Gpu" Version="2.2.0" />
<PackageVersion Include="PaddleOcrNet.Gpu" Version="2.2.0" />
<PackageReference Include="PaddleOcrNet.Gpu" />
paket add PaddleOcrNet.Gpu --version 2.2.0
#r "nuget: PaddleOcrNet.Gpu, 2.2.0"
#:package PaddleOcrNet.Gpu@2.2.0
#addin nuget:?package=PaddleOcrNet.Gpu&version=2.2.0
#tool nuget:?package=PaddleOcrNet.Gpu&version=2.2.0
PaddleOcrNet.Gpu
CUDA GPU acceleration for PaddleOcrNet — high-accuracy native .NET OCR powered by PaddleOCR's neural models on ONNX Runtime.
This is a metapackage. It contains no code of its own: it pulls in PaddleOcrNet together with
Microsoft.ML.OnnxRuntime.Gpu, so the CUDA execution provider is present at runtime and PaddleOcrNet
can select it.
dotnet add package PaddleOcrNet.Gpu
Installing this package instead of PaddleOcrNet is all that is required — it brings the core library
with it.
Usage
There is no separate GPU API. Existing code is unchanged; PaddleOcrNet detects the CUDA provider and uses it automatically:
using PaddleOcrNet.Models;
using PaddleOcrNet.Services;
await using var ocr = new PaddleOcrService();
OcrResult result = await ocr.ExtractTextFromImage("invoice.png", OcrLanguage.English);
Console.WriteLine(result.UsedGpu); // true when a GPU provider was selected
Console.WriteLine(result.FullText);
ExecutionProvider defaults to OcrExecutionProvider.Auto, which probes the loaded ONNX Runtime and
picks the best accelerator available, falling back to CPU when none is:
| Platform | Auto-detect order |
|---|---|
| Windows | DirectML → CUDA → CPU |
| Linux | CUDA → CPU |
| macOS | CoreML → CPU |
To pin a provider rather than auto-detecting:
await using var ocr = new PaddleOcrService(new PaddleOcrServiceOptions
{
ExecutionProvider = OcrExecutionProvider.Cuda, // or Cpu / DirectMl / CoreMl / Auto
});
PaddleOcrServiceOptions.UseGpu = true is kept as shorthand for forcing CUDA, but prefer leaving
ExecutionProvider at Auto — it already enables a GPU when one is present.
Requirements
- An NVIDIA GPU with the proprietary driver installed, and the CUDA 13.x toolkit with cuDNN 9 (CUDA 12 is supported by pinning ONNX Runtime yourself — see below).
- Windows or Linux.
Microsoft.ML.OnnxRuntime.Gpuships native assets for those two platforms only. On macOS this package has nothing to contribute; install plainPaddleOcrNetand letAutoselect CoreML.
Running on CUDA 12
This package brings in ONNX Runtime 1.30, whose GPU build targets CUDA 13 — as has every ONNX Runtime release since 1.27:
| ONNX Runtime | CUDA | cuDNN |
|---|---|---|
| 1.27.x and later | 13.0 | 9.x |
| 1.21.x – 1.26.x | 12.8 | 9.x |
On a machine with only the CUDA 12 toolkit, that runtime looks for cublasLt64_13.dll
(libcublasLt.so.13), fails to attach the CUDA provider, and PaddleOcrNet falls back to CPU. The warning it
logs names the missing library and the CUDA major version the runtime wanted, so the mismatch is visible
without decoding Error 126.
There are three ways to get a GPU out of a CUDA 12 machine. Installing an older PaddleOcrNet does not help — every release so far has referenced a CUDA 13 build of ONNX Runtime (1.27 up to 2.1.0, 1.30 since 2.2.0).
1. Install the CUDA 13 runtime next to CUDA 12. The two majors coexist: their libraries are suffixed
(cublasLt64_12.dll vs cublasLt64_13.dll), so adding CUDA 13 leaves existing CUDA 12 workloads alone. This
keeps you on the current ONNX Runtime and needs no project changes.
2. Pin ONNX Runtime 1.26 in your own project. Pin both packages — they ship the same managed assembly
and must not split — and suppress NU1605, which NuGet raises because a direct reference below a transitive
one counts as a downgrade:
<PropertyGroup>
<NoWarn>$(NoWarn);NU1605</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ML.OnnxRuntime.Gpu" Version="1.26.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.26.0" />
</ItemGroup>
A direct reference always wins over the transitive one, so this is all that is needed — nothing about
PaddleOcrNet itself changes, and ExecutionProvider still resolves CUDA automatically.
3. Use DirectML instead of CUDA (Windows only). DirectML runs on any DirectX 12 GPU — NVIDIA included —
with no CUDA toolkit at all. Install Microsoft.ML.OnnxRuntime.DirectML instead of this package;
ExecutionProvider.Auto already prefers DirectML over CUDA on Windows, so no code changes are needed:
dotnet add package Microsoft.ML.OnnxRuntime.DirectML
If CUDA is unavailable at runtime — no driver, missing libraries, no compatible device — provider
selection logs the reason and falls back to CPU rather than throwing. OcrResult.UsedGpu reports
what was actually used, so a silent fallback is still observable.
Diagnosing a CPU fallback
When OCR runs on CPU and you expected a GPU, ask the service what happened:
await using var ocr = new PaddleOcrService();
Console.WriteLine(ocr.GetRuntimeInfo());
PaddleOcrNet runtime:
ONNX Runtime: 1.30.0
Available providers: TensorrtExecutionProvider, CUDAExecutionProvider, CPUExecutionProvider
Requested provider: Auto
Resolved provider: Cuda
Active provider: Cpu
GPU probe: NVIDIA GPU detected
Hint: ...
Read it top-down. Available providers is fixed at build time by the ONNX Runtime package you
installed: if CUDAExecutionProvider is not in that list, no runtime setting can bring it back.
Resolved is the provider PaddleOcrNet attempted and Active is what it is really running on; when
those differ, the accelerator failed to attach and Hint says why. The same text is on
PaddleOcrService.GpuAccelerationHint, and an attach failure is written once to standard error even when
no ILogger is configured.
The native-asset conflict (fixed in this package)
Before the fix, PaddleOcrNet.Gpu could never reach the GPU on any machine. PaddleOcrNet depends on
Microsoft.ML.OnnxRuntime (the CPU native package) and this package adds
Microsoft.ML.OnnxRuntime.Gpu, so both ended up in the graph. They ship the same asset path —
runtimes/win-x64/native/onnxruntime.dll, runtimes/linux-x64/native/libonnxruntime.so — and NuGet
gives that single slot to exactly one of them: the CPU package. Applications got the 246 MB
onnxruntime_providers_cuda.dll deployed next to a core runtime with no CUDA support compiled in, which
never loads it. GetAvailableProviders() reported only CPUExecutionProvider and AzureExecutionProvider,
Auto resolved to CPU, and — because no provider was ever attempted — nothing threw and nothing logged.
This package now carries an MSBuild targets file that copies the GPU build's core runtime over the CPU one after build and after publish, so the CUDA provider has a runtime that can load it. It needs no change in your project. To opt out (for instance to deliberately ship the CPU runtime), set:
<PropertyGroup>
<PaddleOcrNetGpuPreferGpuRuntime>false</PaddleOcrNetGpuPreferGpuRuntime>
</PropertyGroup>
On an older version, the equivalent manual fix is to keep the CPU package's natives out of the build:
<PackageReference Include="Microsoft.ML.OnnxRuntime" Version="1.30.0" ExcludeAssets="native" />
Notes
- Install either
PaddleOcrNetorPaddleOcrNet.Gpu, not both — this package already references the core library and pins it to a matching version. - The GPU packages add a substantial native payload. For CPU-only deployments, and for Native AOT,
trimmed or container images where size matters, use plain
PaddleOcrNet. - OCR models are downloaded and cached on first use exactly as with the CPU package; GPU selection does not change model sourcing.
Links
- Source, documentation and issues: https://github.com/FarhanLodi/PaddleOcrNet
- Core package: https://www.nuget.org/packages/PaddleOcrNet
License
MIT © PaddleOcrNet contributors. Downloaded models are Apache-2.0 / MIT and attributed to their authors.
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.ML.OnnxRuntime.Gpu (>= 1.30.0)
- PaddleOcrNet (>= 2.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.