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

Add a way to choose witch GPU to use #10

Closed
ghost opened this issue Apr 23, 2020 · 3 comments
Closed

Add a way to choose witch GPU to use #10

ghost opened this issue Apr 23, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@ghost
Copy link

ghost commented Apr 23, 2020

I'm have a PC with 2 GPU, the first is pretty bad and has very little memory and isn't very powerful, but the second one doesn't have that problem.
But when i use EasyOCR, it will always use GPU0 (the first one), and i couldn't find a way to change that
Currently i can't even run easyOCR since my first gpu doesn't have enough memory
RuntimeError: CUDA out of memory. Tried to allocate 736.00 MiB (GPU 0; 2.00 GiB total capacity; 1.04 GiB already allocated; 206.91 MiB free; 1.07 GiB reserved in total by PyTorch)
So would it please be possible to add a way to change witch GPU gets used?

@rkcosmos
Copy link
Contributor

OK, will add this feature soon. In the mean time, you can use cpu by using

reader = easyocr.Reader(['en'], gpu = False)

@rkcosmos rkcosmos added the enhancement New feature or request label Apr 24, 2020
@rkcosmos
Copy link
Contributor

rkcosmos commented Jun 5, 2020

Hi, you can now choose your gpu by

reader = easyocr.Reader(['en'], gpu = 'your choice here')

@akbir
Copy link

akbir commented Aug 19, 2021

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

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

No branches or pull requests

2 participants