sdcb / PaddleSharp

.NET/C# binding for Baidu paddle inference library and PaddleOCR
Apache License 2.0
1.06k stars 200 forks source link

Error: System.Runtime.InteropServices.SEHException: "External component has thrown an exception." - using PaddleDevice.Gpu() #107

Open PavlikBender opened 2 months ago

PavlikBender commented 2 months ago

Description

Today i've download your magnificent project. And I wrote sample from https://github.com/sdcb/PaddleSharp/blob/master/docs/ocr.md . It was worked perfectly, but very CPU demanding. And I'm trying to start program using GPU but I have error here -> _paddleOcrAll.Run(src).Text;

System.Runtime.InteropServices.SEHException: "External component has thrown an exception."
в Sdcb.PaddleInference.Native.PaddleNative.PD_TensorCopyFromCpuFloat(IntPtr pd_tensor, IntPtr data)
   в Sdcb.PaddleInference.PaddleTensor.SetData(Single[] data)
   в Sdcb.PaddleOCR.PaddleOcrDetector.RunRaw(Mat src, Size& resizedSize)
   в Sdcb.PaddleOCR.PaddleOcrDetector.Run(Mat src)
   в Sdcb.PaddleOCR.PaddleOcrAll.Run(Mat src, Int32 recognizeBatchSize)
   в ScreTran.ExecutionService.PaddleOCRRecognize(Byte[] sampleImageData) в C:\Users\bbben\source\repos\ScreTran\Services\ExecutionService.cs:строка 131
   в ScreTran.ExecutionService.RecognizeTextAndTranslate() в C:\Users\bbben\source\repos\ScreTran\Services\ExecutionService.cs:строка 141
   в System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

BTW: I have Nvidia 4060 GPU. Maybe I need something else install except nuget packages?

Steps to reproduce the bug

Install latest nuget packages: Sdcb.PaddleInference Sdcb.PaddleInference.runtime.win64.cu120-sm86-89 Sdcb.PaddleOCR Sdcb.PaddleOCR.Models.Local OpenCvSharp4.runtime.win

Minimal program:

byte[] myPng = File.ReadAllBytes("..filename.png");

using var _paddleOcrAll = new PaddleOcrAll(LocalFullModels.EnglishV4, PaddleDevice.Gpu())
{
    AllowRotateDetection = false,
    Enable180Classification = false,
};

using var src = Cv2.ImDecode(myPng , ImreadModes.Color);
var resultText = _paddleOcrAll.Run(src).Text;

IDE

Visual Studio 2022

OS version

Windows 11

PavlikBender commented 2 months ago

I've installed CUDA and cuDNN. It's already work with GPU. And how I understand I need to install TensorRT, but this page https://www.pythonf.cn/read/64495 unavailable.

PavlikBender commented 2 months ago

@sdcb do the end user need to install CUDA and cuDNN? I've compiled sample project and send to my friend and program doesn't work. Friend doesn't install CUDA and cuDNN

n0099 commented 2 months ago

do the end user need to install CUDA and cuDNN?

Yes.

PavlikBender commented 2 months ago

Yes.

That's very sad. I thought it compiles with all needed libs. I can't force end user download CUDA and cuDNN. Then only thing left is stay on CPU recognition :C