Skip to content

Commit

Permalink
fix: Do proper check to set the device in EasyOCR, RapidOCR.
Browse files Browse the repository at this point in the history
Signed-off-by: Nikos Livathinos <[email protected]>
  • Loading branch information
nikos-livathinos committed Dec 13, 2024
1 parent bb1774d commit 30dbab5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions docling/models/easyocr_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ def __init__(
if self.options.use_gpu:
device = decide_device(accelerator_options.device)
# Enable easyocr GPU if running on CUDA, MPS
use_gpu = device in [
AcceleratorDevice.CUDA,
AcceleratorDevice.MPS,
]
use_gpu = any(
filter(
lambda x: str(x).lower() in device,
[AcceleratorDevice.CUDA.value, AcceleratorDevice.MPS.value],
)
)

self.reader = easyocr.Reader(
lang_list=self.options.lang,
gpu=use_gpu,
Expand Down
2 changes: 1 addition & 1 deletion docling/models/rapid_ocr_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(

# Decide the accelerator devices
device = decide_device(accelerator_options.device)
use_cuda = device == AcceleratorDevice.CUDA
use_cuda = str(AcceleratorDevice.CUDA.value).lower() in device
use_dml = accelerator_options.device == AcceleratorDevice.AUTO
intra_op_num_threads = accelerator_options.num_threads

Expand Down

0 comments on commit 30dbab5

Please sign in to comment.