pythonocreasyocr

Can't use DBnet in EasyOCR


I am trying to use DBnet model with EasyOCR, through using:

reader = Reader(['ar'], gpu = False,detect_network = 'dbnet18')

EasyOCR has downloaded the model, however, when detecting text I got the following error:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[116], line 1
----> 1 easy_ocr(res,r"C:\Users\PC\OCR-App 1\data\interim\iscore\file.txt",r"C:\Users\PC\OCR-App 1\data\interim\iscore\out.jpg")

Cell In[115], line 15, in easy_ocr(image, out_txt, out_image)
     12 ts = time.time()
     13 #min_size=10,width_ths=0.5,add_margin=0.1,paragraph = False,text_threshold =0.15,low_text=0.2
     14 #text_threshold =0.15,low_text=0.2,add_margin=0.09
---> 15 results = reader.readtext(image,paragraph = True)
     16 te = time.time()
     17 td = te - ts

File c:\Users\PC\anaconda3\envs\easyocr\Lib\site-packages\easyocr\easyocr.py:452, in Reader.readtext(self, image, decoder, beamWidth, batch_size, workers, allowlist, blocklist, detail, rotation_info, paragraph, min_size, contrast_ths, adjust_contrast, filter_ths, text_threshold, low_text, link_threshold, canvas_size, mag_ratio, slope_ths, ycenter_ths, height_ths, width_ths, y_ths, x_ths, add_margin, threshold, bbox_min_score, bbox_min_size, max_candidates, output_format)
    446 '''
    447 Parameters:
    448 image: file path or numpy-array or a byte stream object
    449 '''
    450 img, img_cv_grey = reformat_input(image)
--> 452 horizontal_list, free_list = self.detect(img, 
    453                                          min_size = min_size, text_threshold = text_threshold,\
    454                                          low_text = low_text, link_threshold = link_threshold,\
    455                                          canvas_size = canvas_size, mag_ratio = mag_ratio,\
    456                                          slope_ths = slope_ths, ycenter_ths = ycenter_ths,\
    457                                          height_ths = height_ths, width_ths= width_ths,\
...
    231         "Input type is {}, but 'deform_conv_{}.*.so' is not imported successfully.".format(device_, device_),
    232         )
    233 return output

RuntimeError: Input type is cpu, but 'deform_conv_cpu.*.so' is not imported successfully.

Solution

  • its because it should be use in a diferent paramater like this

    Correct way: reader easyocr.Reader(['ar'], detector='dbnet18')

    Not too correct: reader = Reader(['ar'], gpu = False,detect_network = 'dbnet18')

    here's the documentation:

    change the parameter from 'detec_network' to 'detector'