JaidedAI / EasyOCR

Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.
https://www.jaided.ai
Apache License 2.0
23.61k stars 3.1k forks source link

Runtime Error(Language Specific) #1120

Open Th3Tr1ckst3r opened 1 year ago

Th3Tr1ckst3r commented 1 year ago

The runtime error can be replicated with the following code, and the Tamil language model:

ta
Using CPU. Note: This module is much faster with a GPU.
Traceback (most recent call last):
  File "/home/th3tr1ckst3r/Desktop/test.py", line 15, in <module>
    reader = easyocr.Reader([lang], gpu=False)
  File "/home/th3tr1ckst3r/.local/lib/python3.9/site-packages/easyocr/easyocr.py", line 231, in __init__
    self.recognizer, self.converter = get_recognizer(recog_network, network_params,\
  File "/home/th3tr1ckst3r/.local/lib/python3.9/site-packages/easyocr/recognition.py", line 174, in get_recognizer
    model.load_state_dict(new_state_dict)
  File "/home/th3tr1ckst3r/.local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 2041, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for Model:
    size mismatch for Prediction.weight: copying a param with shape torch.Size([143, 512]) from checkpoint, the shape in current model is torch.Size([127, 512]).
    size mismatch for Prediction.bias: copying a param with shape torch.Size([143]) from checkpoint, the shape in current model is torch.Size([127]).

Python3 code used:

import easyocr

img_path = '/home/th3tr1ckst3r/Desktop/test123.jpg'
lang = 'ta'  
print(lang)
reader = easyocr.Reader([lang], gpu=False)
data = reader.readtext(img_path, detail=1)
for res in data:
    text = res[1]
    confidence = res[2]
    print(res[1], res[2], lang)
StaronDsilva commented 1 year ago

Even I ran into the exact problem , could you please pass me the solution if found any? Thanks.

Seoung-wook commented 11 months ago

no lang, if you recog english, reader = easyocr.Reader('en', gpu=False)

gnana70 commented 7 months ago

Please check this repo if you are interested in tamil ocr. It's capable of recognizing both tamil and English. https://github.com/gnana70/tamil_ocr

You can simply install using pip install ocr_tamil

from ocr_tamil.ocr import OCR
image_path = r"test_images\0.jpg" # insert your own path here
ocr = OCR(detect=True)
texts = ocr.predict(image_path)
with open("output.txt","w",encoding="utf-8") as f:
    f.write(texts)

>>>> கொடைக்கானல் Kodaikanal