[Python] PaddleOCR rec_model_dir gives incorrect text results – Why does lang='en' work but...

Discussão em 'Python' iniciado por Stack, Março 27, 2025.

  1. Stack

    Stack Membro Participativo

    my problem is that I dont understand why paddleocr gives me weird text recognition results if I put a model in PaddleOCR(rec_model_dir="[modelPath]") . My goal is to use a custom fine tuned model on pictures so I get the best possible recognition result. So I tried to use the "en_PP-OCRv4_rec_infer" model and put the path to the folder that contains the "inference.pdiparams, inference.pdiparams.info, inference.pdmodel" files into the [modelPath] gap for rec_model_dir. I got weird results like "7????????7:???"or "7消先7:昏" for a picture that clearly doesnt show that text (I tried more pictures and I got the same problem with also weird results similar to this one). After that I found out that if I do PaddleOCR(lang="en") it uses the same model, but it is working fine. -> The result is "LV-LOW" But I need to use rec_model_dir for my custom model. whats the problem that I cant use rec_model_dir ? Here is my Code:

    import cv2
    from paddleocr import PaddleOCR

    image_path = r"./Picture.jpg"
    image_path.replace("\\", "/")

    model_path = r"./model"
    model_path.replace("\\", "/")

    def extract_text(image_path, model_path):
    ocr_model = PaddleOCR(rec_model_dir= model_path, det=False, show_log=False, use_angle_cls=True)
    image = cv2.imread(image_path)

    result = ocr_model.ocr(image, cls=True)
    text_detected = ", ".join(row[1][0] for row in result[0]) if result and result[0] else "NOINFO"
    print(text_detected)

    extract_text(image_path, model_path)


    Used Picture

    Continue reading...

Compartilhe esta Página