sdcb / PaddleSharp

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

Downloads for English V3 and English V4 Stalling #105

Closed TheWorldEndsWithUs closed 1 month ago

TheWorldEndsWithUs commented 1 month ago

Describe the bug

Whenever I run the default code found from the online docs example on my Windows 11 64 bit machine the download stalls. It hangs forever.

Steps to reproduce the bug

` private async Task<Rectangle[]> runPaddleOCR(Mat src) { List ocrResults = new List(); FullOcrModel model = await OnlineFullModels.EnglishV4.DownloadAsync(); using (PaddleOcrAll all = new PaddleOcrAll(model, PaddleDevice.Mkldnn()) { AllowRotateDetection = true, Enable180Classification = false, }) { PaddleOcrResult result = all.Run(src); Console.WriteLine("Detected all texts: \n" + result.Text); foreach (PaddleOcrResultRegion region in result.Regions) { var boundingRect = region.Rect.BoundingRect(); Rectangle rect = new Rectangle(boundingRect.X, boundingRect.Y, boundingRect.Width, boundingRect.Height); ocrResults.Add(rect); Console.WriteLine($"Text: {region.Text}, Score: {region.Score}, RectCenter: {region.Rect.Center}, RectSize: {region.Rect.Size}, Angle: {region.Rect.Angle}"); } }

        return ocrResults.ToArray();

    }`

My code is above it always hangs on the downloadAsync line never reaching the using statement. I've tried EnglishV3 and EnglishV4.

Expected behavior

I'd like the file to download and run the model.

Screenshots

No response

Release version

No response

IDE

Visual Studio 2022 Community

OS version

Windows 11 64 bit

Additional context

No response

n0099 commented 1 month ago

104 #84 #80 #62 #32

tl;dr: Download models from upstream: https://paddlepaddle.github.io/PaddleOCR/ppocr/model_list.html and put them under the configured https://github.com/sdcb/PaddleSharp/blob/475ed956cf4da1b4bbfb09c6f0b8246e6703f6fb/src/Sdcb.PaddleOCR.Models.Online/Settings.cs#L17

Deeplink for EnglishV(3|4) models: env4 env3 If it's still hard for you to connect these servers in China, here's mirrors on github: en_PP-OCRv4_rec_infer.tar.zip en_PP-OCRv3_det_infer.tar.zip (rename to remove .zip extension)

TheWorldEndsWithUs commented 1 month ago

Hey! Thank you for getting back to me! I downloaded the models and put them in the AppData folder as instructed, however the download still stalls for some reason. Thank you for your response, but I might use Tesseract for the time being so no rush to figure it out.

n0099 commented 1 month ago

Did you uncompressed that .tar? Also feel free to modify the value of global variable GlobalModelDirectory before using it.

TheWorldEndsWithUs commented 1 month ago

Yes the file is unzipped and in the correct folder. I don't mind using the GlobalModelDirectory as the folder for now. The application refuses to load the model for some reason. image

n0099 commented 1 month ago

Please remove the suffix _infer from the unextracted folder name following https://github.com/sdcb/PaddleSharp/blob/475ed956cf4da1b4bbfb09c6f0b8246e6703f6fb/src/Sdcb.PaddleOCR.Models.Online/OnlineDetectionModel.cs#L96 https://github.com/sdcb/PaddleSharp/blob/475ed956cf4da1b4bbfb09c6f0b8246e6703f6fb/src/Sdcb.PaddleOCR.Models.LocalV4/KnownModels.cs#L16-L28

TheWorldEndsWithUs commented 1 month ago

This worked! I got rid of the Online Model library and downloaded the Local model library. Now the local example works perfectly. Thank you!