Paddle OCR gives "device id must be less than GPU count" error
I am trying to use Paddle OCR for reading numbers from images, but it gives me this error:
"(InvalidArgument) Device id must be less than GPU count, but received id is: 0. GPU count is: 0.
[Hint: Expected id < GetGPUDeviceCount(), but received id:0 >= GetGPUDeviceCount():0.] (at ..paddlephibackendsgpucudacuda_info.cc:242)"
The error comes from this line of code :
ocr = PaddleOCR(use_angle_cls=True, lang='en')
Does anyone know how to solve this issue? I can’t find the solution on the internet.
This is the code that I am using:
# Paddleocr supports Chinese, English, French, German, Korean and Japanese. # You can set the parameter `lang` as `ch`, `en`, `french`, `german`, `korean`, `japan` # to switch the language model in order. ocr = PaddleOCR(use_angle_cls=True, lang='en') # need to run only once to download and load model into memory img_path = 'capture.png' result = ocr.ocr(img_path, cls=True) for idx in range(len(result)): res = result[idx] for line in res: print(line) # draw result from PIL import Image result = result image = Image.open(img_path).convert('RGB') boxes = [line for line in result] txts = [line for line in result] scores = [line for line in result] im_show = draw_ocr(image, boxes, txts, scores, font_path='/path/to/PaddleOCR/doc/fonts/simfang.ttf') im_show = Image.fromarray(im_show) im_show.save('result.jpg')`
Solution – 1
Default value of PaddleOCR for GPU is True, you would need to disable it if you don’t have GPU.
ocr = PaddleOCR(use_angle_cls=True, lang='en', use_gpu=False)