sdcb/PaddleSharp

The same ppocrV4 model returns inconsistent results

lindadamama opened this issue · 6 comments

Describe the bug

The path to another library:https://gitee.com/raoyutian/PaddleOCRSharp
The running speed of another library is only one tenth of yours
I just tested the REC model
“”“”c#
public class PaddleOCR
{

 PaddleOcrRecognizer paddleOcrRecognizer;
 public void Init(string ModelDiretoryPath, string keyFilePath)
 {
     FullOcrModel model = FullOcrModel.FromDirectory(ModelDiretoryPath, keyFilePath, ModelVersion.V4);

     paddleOcrRecognizer = new PaddleOcrRecognizer(model.RecognizationModel, PaddleDevice.Mkldnn());

 }
 public string Predict(Mat mat)
 {
     if (mat.Channels() == 1)
     {
         using Mat dst= new Mat();
         Cv2.Merge(new Mat[] { mat,mat,mat},dst);
         return paddleOcrRecognizer.Run(dst).Text;
     }
     else 
     {
         return paddleOcrRecognizer.Run(mat).Text;
     }
 }
 public void Dispose()
 {
     this.paddleOcrRecognizer?.Dispose();
 }

}
“”“”

Steps to reproduce the bug

Bug titleI used two libraries to call the same V4 model, but the returned results were different. It seems that many of the returned values from your library are empty
img.zip
OCRModel.zip

Expected behavior

No response

Screenshots

No response

Release version

No response

IDE

No response

OS version

No response

Additional context

No response

sdcb commented

PaddleOCRSharp this project enlarged the image source in code level, if you enlarge the source image 2 times or 3 times, it should be exactly the same.

Is it like this when the length and width of the original image are magnified twice?I‘ll have a try

sdcb commented

I did a short debugging for your code, it shows really bad for ChineseV4 model:
image

But it seems relatively good for EnglishV4 model:
image

I loaded my own training AI model, found that the picture increased, and there is no effect, the same model, the output of the two libraries are not the same

Identify the incorrect image, no matter how many times the magnification, the return value is the same, the wrong is always wrong, but change another library, the return value is correct, the loaded image is the picture of the training Dataset

using Sdcb.PaddleOCR.Models.Local;
using Sdcb.PaddleOCR;
using Sdcb.PaddleOCR.Models;
using Sdcb.PaddleInference;
using OpenCvSharp;
var img = Cv2.ImRead("D:\\dataset\\test\\23.jpg");
var modelPath = @"D:\OcrModel";
var keyPath = @"D:\OcrModel\ppocr_keys.txt";
int scale = 30;
FullOcrModel model = FullOcrModel.FromDirectory(modelPath, keyPath, ModelVersion.V4);

var ocr = new PaddleOcrRecognizer(model.RecognizationModel, PaddleDevice.Gpu());
using var dst = new Mat();
Cv2.Resize(img, dst, new Size() { Width = img.Width * scale, Height = img.Height * scale });
Cv2.ImShow("dst",dst);
Cv2.WaitKey();
for (int i = 0; i < 10000; i++) 
{
   
    var a = ocr.Run(dst);
    Console.WriteLine($"{i}"+a.Text);
}
Console.ReadKey();