Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The same ppocrV4 model returns inconsistent results #95

Open
lindadamama opened this issue May 13, 2024 · 6 comments
Open

The same ppocrV4 model returns inconsistent results #95

lindadamama opened this issue May 13, 2024 · 6 comments

Comments

@lindadamama
Copy link

lindadamama commented May 13, 2024

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
Copy link
Owner

sdcb commented May 13, 2024

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.

@lindadamama
Copy link
Author

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

@sdcb
Copy link
Owner

sdcb commented May 13, 2024

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

@lindadamama
Copy link
Author

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

@lindadamama
Copy link
Author

lindadamama commented May 13, 2024

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

@lindadamama
Copy link
Author

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants