English | ็ฎไฝไธญๆ
๐ .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 usingC#
.
Please checkout this page ๐.
NuGet Package ๐ผ | Version ๐ | Description ๐ |
---|---|---|
Sdcb.PaddleInference | Paddle Inference C API .NET binding โ๏ธ |
Some of packages already deprecated(Version <= 2.5.0):
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:
You can also build your docker
images using these dockerfiles.
-
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
-
Please ensure the latest Visual C++ Redistributable was installed in
Windows
(typically it should automatically installed if you haveVisual 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:
-
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()
๐ -
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 โฌ๏ธ
Enable GPU support can significantly improve the throughput and lower the CPU usage. ๐
Steps to use GPU in Windows:
- (for Windows) Install the package:
Sdcb.PaddleInference.runtime.win64.cuda*
instead ofSdcb.PaddleInference.runtime.win64.mkl
, do not install both. ๐ฆ - Install CUDA from NVIDIA, and configure environment variables to
PATH
orLD_LIBRARY_PATH
(Linux) ๐ง - Install cuDNN from NVIDIA, and configure environment variables to
PATH
orLD_LIBRARY_PATH
(Linux) ๐ ๏ธ - Install TensorRT from NVIDIA, and configure environment variables to
PATH
orLD_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! ๐
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 usedet.txt
๐180DegreeClassificationModel
will usecls.txt
๐RecognitionModel
will userec.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
. ๐๏ธ
- ๅดไบฎ https://github.com/cuiliang
- ๆข็ฐไผ
- ๆทฑๅณ-้ฑๆๆพ
- iNeuOSๅทฅไธไบ่็ฝๆไฝ็ณป็ป๏ผhttp://www.ineuos.net
QQ group of C#/.NET computer vision technical communication (C#/.NET่ฎก็ฎๆบ่ง่งๆๆฏไบคๆต็พค): 579060605