💗.NET Wrapper for PaddleInference
C API, include PaddleOCR, PaddleDetection, Rotation Detector, 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
).
Please checkout this page.
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:
Since GPU package are too large(>1.5GB), I cannot publish a NuGet package to nuget.org, there is a limitation of 250MB when upload to Github, there is some related issues to this:
However you're good to build your own GPU nuget package using 01-build-native.linq
.
Here is the GPU package that I compiled(not from baidu official):
NuGet Package | Version | Description |
---|---|---|
Sdcb.RotationDetector | RotationDetector library(based on Sdcb.PaddleInference) |
NuGet Package | Version | Description |
---|---|---|
Sdcb.PaddleDetection | PaddleDetection library(based on Sdcb.PaddleInference) |
- PaddleOCR: PaddleOCR
- PaddleDetection: PaddleDetection
-
Please ensure the latest Visual C++ Redistributable was installed in
Windows
(typically it should automatically installed if you haveVisual Studio
installed) Otherwise, it will failed with 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 windows server 2012 R2 machine:
-
Many old CPUs does not support AVX instructions, please ensure your CPU supports AVX, or download the x64-noavx-openblas dlls and disable Mkldnn:
PaddleConfig.Defaults.UseMkldnn = false;
-
If you're using Win7-x64, and your CPU do support AVX2, then you might also need to extract 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 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 follow the CUDA/cuDNN/TensorRT configuration tasks.
After these steps completed, you can try specify PaddleDevice.Gpu()
in paddle device configure parameter then enjoy🚀.
To use TensorRT, just specify PaddleDevice.Gpu().And(PaddleDevice.TensorRt("shape-info.txt"))
instead of PaddleDevice.Gpu()
to make it work.
Please aware, this shape info text file **.txt
is bind to your model, different model have different shape info, so if you're using complexed model like Sdcb.PaddleOCR
, you should use different shape for different model 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 :
First round of TensorRT
running will generate a shape info **.txt
file in this folder: %AppData%\Sdcb.PaddleInference\TensorRtCache
, it will takes around 100 seconds to finish TensorRT cache generation, after than it should be faster than general GPU
.
In this case, if something strange happened, (for example you mistakenly create a same shape-info.txt
file for different models), you can delete this folder to generate TensorRT cache again: %AppData%\Sdcb.PaddleInference\TensorRtCache
.
- 深圳-钱文松
- iNeuOS工业互联网操作系统:http://www.ineuos.net
QQ group of C#/.NET computer vision technical communicate(C#/.NET计算机视觉技术交流群): 579060605