• Stars
    star
    896
  • Rank 49,280 (Top 1.0 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

.NET/C# binding for Baidu paddle inference library and PaddleOCR

PaddleSharp 🌟 main QQ

💗 .NET Wrapper for PaddleInference C API, support Windows(x64) 💻, NVIDIA Cuda 10.2+ based GPU 🎮 and Linux(Ubuntu-22.04 x64) 🐧, currently contained following main components:

  • PaddleOCR 📖 support 14 OCR languages model download on-demand, allow rotated text angle detection, 180 degree text detection, also support table recognition 📊.
  • PaddleDetection 🎯 support PPYolo detection model and PicoDet model 🏹.
  • RotationDetection 🔄 use Baidu's official text_image_orientation_infer model to detect text picture's rotation angle(0, 90, 180, 270).
  • Paddle2Onnx 🔄 Allow user export ONNX model using C#.

NuGet Packages/Docker Images 📦

Release notes 📝

Please checkout this page 📄.

Infrastructure packages 🏗️

NuGet Package 💼 Version 📌 Description 📚
Sdcb.PaddleInference NuGet Paddle Inference C API .NET binding ⚙️

Native packages 🏗️

Package Version 📌 Description
Sdcb.PaddleInference.runtime.win64.mkl NuGet win64+mkldnn
Sdcb.PaddleInference.runtime.win64.openblas NuGet win64+openblas
Sdcb.PaddleInference.runtime.win64.openblas-noavx NuGet win64+openblas(no AVX, for old CPUs)
Sdcb.PaddleInference.runtime.win64.cuda102_cudnn76_tr72_sm61_75 NuGet win64/CUDA 10.2/cuDNN 7.6/TensorRT 7.2/sm61+sm75
Sdcb.PaddleInference.runtime.win64.cuda118_cudnn86_tr85_sm86_89 NuGet win64/CUDA 11.8/cuDNN 8.6/TensorRT 8.5/sm86+sm89

Some of packages already deprecated(Version <= 2.5.0):

Package Version 📌 Description
Sdcb.PaddleInference.runtime.win64.cuda117_cudnn84_tr84_sm86 NuGet win64/CUDA 11.7/cuDNN 8.4/TensorRT 8.4/sm86
Sdcb.PaddleInference.runtime.win64.cuda102_cudnn76_sm61_75 NuGet win64/CUDA 10.2/cuDNN 7.6/sm61+sm75
Sdcb.PaddleInference.runtime.win64.cuda116_cudnn84_sm86_onnx NuGet win64/CUDA 11.6/cuDNN 8.4/sm86/onnx

Any other packages that starts with Sdcb.PaddleInference.runtime might deprecated.

Baidu packages were downloaded from here: https://www.paddlepaddle.org.cn/inference/master/guides/install/download_lib.html#windows

My Sdcb packages were self compiled.

Baidu official GPU packages are too large(>1.5GB) to publish to nuget.org, there is a limitation of 250MB when upload to Github, there is some related issues to this:

But You're good to build your own GPU nuget package using 01-build-native.linq 🛠️.

Note: Linux does not need a native binding NuGet package like windows(Sdcb.PaddleInference.runtime.win64.mkl), instead, you can/should based from a Dockerfile🐳 to development:

Docker Images 🐳 Version 📌 Description 📚
sdflysha/dotnet6-paddle Docker PaddleInference 2.5.0, OpenCV 4.7.0, based on official Ubuntu 22.04 .NET 6 Runtime 🌐
sdflysha/dotnet6sdk-paddle Docker PaddleInference 2.5.0, OpenCV 4.7.0, based on official Ubuntu 22.04 .NET 6 SDK 🌐

Paddle Devices

  • Mkldnn - PaddleDevice.Mkldnn()

    Based on Mkldnn, generally fast

  • Openblas - PaddleDevice.Openblas()

    Based on openblas, slower, but dependencies file smaller and consume lesser memory

  • Onnx - PaddleDevice.Onnx()

    Based on onnxruntime, is also pretty fast and consume less memory

  • Gpu - PaddleDevice.Gpu()

    Much faster but relies on NVIDIA GPU and CUDA

    If you wants to use GPU, you should refer to FAQ How to enable GPU? section, CUDA/cuDNN/TensorRT need to be installed manually.

  • TensorRT - PaddleDevice.Gpu().And(PaddleDevice.TensorRt("shape-info.txt"))

    Even faster than raw Gpu but need install TensorRT environment.

    Please refer to tensorrt section for more details

FAQ ❓

Why my code runs good in my windows machine, but DllNotFoundException in other machine: 💻

  1. Please ensure the latest Visual C++ Redistributable was installed in Windows (typically it should automatically installed if you have Visual Studio installed) 🛠️ Otherwise, it will fail with the following error (Windows only):

    DllNotFoundException: Unable to load DLL 'paddle_inference_c' or one of its dependencies (0x8007007E)
    

    If it's Unable to load DLL OpenCvSharpExtern.dll or one of its dependencies, then most likely the Media Foundation is not installed in the Windows Server 2012 R2 machine: image

  2. Many old CPUs do not support AVX instructions, please ensure your CPU supports AVX, or download the x64-noavx-openblas DLLs and disable Mkldnn: PaddleDevice.Openblas() 🚀

  3. If you're using Win7-x64, and your CPU does support AVX2, then you might also need to extract the following 3 DLLs into C:\Windows\System32 folder to make it run: 💾

    • api-ms-win-core-libraryloader-l1-2-0.dll
    • api-ms-win-core-processtopology-obsolete-l1-1-0.dll
    • API-MS-Win-Eventing-Provider-L1-1-0.dll

    You can download these 3 DLLs here: win7-x64-onnxruntime-missing-dlls.zip ⬇️

How to enable GPU? 🎮

Enable GPU support can significantly improve the throughput and lower the CPU usage. 🚀

Steps to use GPU in Windows:

  1. (for Windows) Install the package: Sdcb.PaddleInference.runtime.win64.cuda* instead of Sdcb.PaddleInference.runtime.win64.mkl, do not install both. 📦
  2. Install CUDA from NVIDIA, and configure environment variables to PATH or LD_LIBRARY_PATH (Linux) 🔧
  3. Install cuDNN from NVIDIA, and configure environment variables to PATH or LD_LIBRARY_PATH (Linux) 🛠️
  4. Install TensorRT from NVIDIA, and configure environment variables to PATH or LD_LIBRARY_PATH (Linux) ⚙️

You can refer to this blog page for GPU in Windows: 关于PaddleSharp GPU使用 常见问题记录 📝

If you're using Linux, you need to compile your own OpenCvSharp4 environment following the docker build scripts and the CUDA/cuDNN/TensorRT configuration tasks. 🐧

After these steps are completed, you can try specifying PaddleDevice.Gpu() in the paddle device configuration parameter, then enjoy the performance boost! 🎉

TensorRT 🚄

To use TensorRT, just specify PaddleDevice.Gpu().And(PaddleDevice.TensorRt("shape-info.txt")) instead of PaddleDevice.Gpu() to make it work. 💡

Please be aware, this shape info text file **.txt is bound to your model. Different models have different shape info, so if you're using a complex model like Sdcb.PaddleOCR, you should use different shapes for different models like this:

using PaddleOcrAll all = new(model,
   PaddleDevice.Gpu().And(PaddleDevice.TensorRt("det.txt")),
   PaddleDevice.Gpu().And(PaddleDevice.TensorRt("cls.txt")),
   PaddleDevice.Gpu().And(PaddleDevice.TensorRt("rec.txt")))
{
   Enable180Classification = true,
   AllowRotateDetection = true,
};

In this case:

  • DetectionModel will use det.txt 🔍
  • 180DegreeClassificationModel will use cls.txt 🔃
  • RecognitionModel will use rec.txt 🔡

NOTE 📝:

The first round of TensorRT running will generate a shape info **.txt file in this folder: %AppData%\Sdcb.PaddleInference\TensorRtCache. It will take around 100 seconds to finish TensorRT cache generation. After that, it should be faster than the general GPU. 🚀

In this case, if something strange happens (for example, you mistakenly create the same shape-info.txt file for different models), you can delete this folder to generate TensorRT cache again: %AppData%\Sdcb.PaddleInference\TensorRtCache. 🗑️

Thanks & Sponsors 🙏

Contact 📞

QQ group of C#/.NET computer vision technical communication (C#/.NET计算机视觉技术交流群): 579060605

More Repositories

1

OpenVINO.NET

High quality .NET wrapper for OpenVINO™ toolkit.
C#
337
star
2

Sdcb.FFmpeg

FFmpeg basic .NET API generated by CppSharp
C#
268
star
3

Sdcb.Arithmetic

A modern .NET library that can PInvoke to gmp and mpfr, that enable both high performance and best .NET convenience.
C#
122
star
4

sdmap

A template engine for writing dynamic sql.
C#
97
star
5

blog-data

《.NET骚操作》的博客数据
C#
78
star
6

Sdcb.LibRaw

Advanced raw image processing library in C# based on LibRaw.
C#
60
star
7

Sdcb.WordCloud

Generate WordCloud image from .NET/.NET Core
C#
59
star
8

FlysEngine

Real-time 2D rendering utilities based on Vortice.Windows/Direct2D.
C#
50
star
9

blade

旋刃竞技场
JavaScript
40
star
10

Sdcb.DashScope

为阿里云灵积模型服务DashScope开发的非官方.NET SDK
C#
39
star
11

Sdcb.SparkDesk

讯飞星火大模型非官方.NET SDK Xunfei's "Xinghuo" SparkDesk big model unofficial sdk for .NET
C#
33
star
12

dotnet-cv2021

2021 .NET Conf China 《.NET玩转计算机视觉OpenCV》 源代码仓库 (周杰)
C#
24
star
13

mini-openvino-paddleocr

Simple Sdcb.OpenVINO demo for PaddleOCR
C#
23
star
14

Sdcb.ScreenCapture

C#
23
star
15

2019-ncp-simulation

C#
20
star
16

Sdcb.StabilityAI

Unofficial Stability AI rest API C# SDK
C#
19
star
17

Sdcb.Imaging

Direct2D based watermark/captcha tool.
C#
14
star
18

sdcb-openvino-yolov8-det

Sdcb.OpenVINO demo project to infer yolov8 detection model
C#
14
star
19

dx

A modern C++ library for DirectX programming
C++
14
star
20

ffmpeg-wjz-sorry-generator

Create wjz/sorry gif by ASP.NET Core & Sdcb.FFmpeg
C#
14
star
21

Sdcb.FFmpegAPIWrapper

.NET FFmpeg API Warpper Library.
C#
10
star
22

mini-openvino-facedetection

A mini face detection demo using OpenVINO.NET
C#
9
star
23

opencvsharp-mini-runtime

mini runtime that suitable for model inference in server.
9
star
24

sdcb-openvino-yolov8-cls

Demo for Sdcb.OpenVINO project to infer yolov8 cls model
C#
9
star
25

Sdcb.PictureSpeaks

画中有话·基于azure chatgpt和dalle3的猜成语app
C#
9
star
26

paddlesharp-ocr-aspnetcore-demo

PaddleSharp OCR ASP.NET Core 6 demo
HTML
8
star
27

Ecd2Pem

Convert .NET ECD CngKey/key pair into PEM file.
C#
6
star
28

Sdcb.WenXinQianFan

百度文心千帆平台非官方.NET SDK
C#
6
star
29

TypeScriptAST

TypeScript AST Parser, .NET Core standard 2.0 library, forked from: https://github.com/ToCSharp/TypeScriptAST
C#
6
star
30

dotnetconf-changsha-20240225

C#
5
star
31

Sdcb.System.Range

Provide System.Index, System.Range for C# 8.0.
C#
3
star
32

Sdcb.Mattermost.DotNetSdk

.NET SDK for Mattermost
C#
3
star
33

Antlr4Test

C#
2
star
34

TellyouMsdn

对msdn.itellyou.cn的C#爬虫
C#
2
star
35

sdlife

Life related tools for sdcb.
C#
1
star
36

YeluCasSsoClient

One line code to integrate your Yelu CAS SSO
C#
1
star
37

GPTCodingAssistant

TypeScript
1
star
38

ibatis2sdmap

Migrate iBatis xml to sdmap script.
C#
1
star
39

MFPL

My First Programming Language
C#
1
star
40

sdsky

TypeScript
1
star
41

Sdcb.Collections

Useful collections by sdcb.
C#
1
star
42

2048

Another 2048 game for mobile device.
TypeScript
1
star
43

RtPaint

Real-time paint tool for presentation.
JavaScript
1
star