EasyOCR icon indicating copy to clipboard operation
EasyOCR copied to clipboard

multi GPUs Issue

Open anhncs opened this issue 5 years ago • 4 comments

Hi tried this but still had issues:

/katakana/notebooks/vision/ocr_hybrid.py in easy_ocr_no_table(img, device)
     69     img = prep_img_for_easyocr(img)
     70     img = remove_table_from_scan(img)
---> 71     result = run_easy_ocr(img, device)
     72     return result
     73 

~/katakana/notebooks/vision/ocr_hybrid.py in run_easy_ocr(img, device)
     60     if easyocr_reader is None:
     61         load_easyocr_reader(device)  # to prevent slow import
---> 62     result = easyocr_reader.readtext(
     63         img, link_threshold=0.99, text_threshold=0.7, add_margin=0.02
     64     )

~/.local/lib/python3.8/site-packages/easyocr/easyocr.py in 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, output_format)
    383         img, img_cv_grey = reformat_input(image)
    384 
--> 385         horizontal_list, free_list = self.detect(img, min_size, text_threshold,\
    386                                                  low_text, link_threshold,\
    387                                                  canvas_size, mag_ratio,\

~/.local/lib/python3.8/site-packages/easyocr/easyocr.py in detect(self, img, min_size, text_threshold, low_text, link_threshold, canvas_size, mag_ratio, slope_ths, ycenter_ths, height_ths, width_ths, add_margin, reformat, optimal_num_chars)
    273             img, img_cv_grey = reformat_input(img)
    274 
--> 275         text_box_list = get_textbox(self.detector, img, canvas_size, mag_ratio,
    276                                     text_threshold, link_threshold, low_text,
    277                                     False, self.device, optimal_num_chars)

~/.local/lib/python3.8/site-packages/easyocr/detection.py in get_textbox(detector, image, canvas_size, mag_ratio, text_threshold, link_threshold, low_text, poly, device, optimal_num_chars)
     92     result = []
     93     estimate_num_chars = optimal_num_chars is not None
---> 94     bboxes_list, polys_list = test_net(canvas_size, mag_ratio, detector,
     95                                        image, text_threshold,
     96                                        link_threshold, low_text, poly,

~/.local/lib/python3.8/site-packages/easyocr/detection.py in test_net(canvas_size, mag_ratio, net, image, text_threshold, link_threshold, low_text, poly, device, estimate_num_chars)
     43     # forward pass
     44     with torch.no_grad():
---> 45         y, feature = net(x)
     46 
     47     boxes_list, polys_list = [], []

/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    887             result = self._slow_forward(*input, **kwargs)
    888         else:
--> 889             result = self.forward(*input, **kwargs)
    890         for hook in itertools.chain(
    891                 _global_forward_hooks.values(),

/usr/local/lib/python3.8/dist-packages/torch/nn/parallel/data_parallel.py in forward(self, *inputs, **kwargs)
    151         for t in chain(self.module.parameters(), self.module.buffers()):
    152             if t.device != self.src_device_obj:
--> 153                 raise RuntimeError("module must have its parameters and buffers "
    154                                    "on device {} (device_ids[0]) but found one of "
    155                                    "them on device: {}".format(self.src_device_obj, t.device))

RuntimeError: module must have its parameters and buffers on device cuda:0 (device_ids[0]) but found one of them on device: cuda:3

Originally posted by @akbir in https://github.com/JaidedAI/EasyOCR/issues/10#issuecomment-902039791

I have same exact issues when using multi GPU.

anhncs avatar Oct 28 '21 07:10 anhncs

Hey @anhncs

Have you checked all of your modules are set on device cuda:0 because one of your modules is still set on Cuda: 3. Can you paste your code where you have set GPU parameters?

Shwetago avatar Jan 03 '22 19:01 Shwetago

+1 same issue as @anhncs

@Shwetago How can you switch other modules? There is no direct control of EasyOCR model via the library API. All you can do is to pass a gpu index. E.g. easyocr.Reader(['en'], gpu="cuda:1") I actually checked the code of the Reader constructor. It seems in spite of this comment https://github.com/JaidedAI/EasyOCR/issues/10#issuecomment-639233692, t doesn't handle numbers, only boolean values.

oshev avatar Jun 07 '22 13:06 oshev

Was this solved?, I have not been able to use easyocr in a different GPU than the default one

cvelas11 avatar Feb 16 '23 06:02 cvelas11

Thanks for letting me know @oshev. I did not know it was only accepting boolean values.

Shwetago avatar Feb 28 '23 11:02 Shwetago