Skip to content

Commit

Permalink
fix(EasyOcrModel): Support the use_gpu pipeline parameter in EasyOcrM…
Browse files Browse the repository at this point in the history
…odel. Initialize easyocr (#282)

fix(EasyOcrModel): Support the use_gpu pipeline parameter in EasyOcrModel. Initialize easyocr without GPU if MPS is available.

Signed-off-by: Nikos Livathinos <nli@zurich.ibm.com>
  • Loading branch information
nikos-livathinos authored Nov 8, 2024
1 parent 118f162 commit 0eb065e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docling/models/easyocr_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Iterable

import numpy
import torch
from docling_core.types.doc import BoundingBox, CoordOrigin

from docling.datamodel.base_models import OcrCell, Page
Expand Down Expand Up @@ -30,8 +31,12 @@ def __init__(self, enabled: bool, options: EasyOcrOptions):
"Alternatively, Docling has support for other OCR engines. See the documentation."
)

use_gpu = (
False if torch.backends.mps.is_available() else self.options.use_gpu
)
self.reader = easyocr.Reader(
lang_list=self.options.lang,
gpu=use_gpu,
model_storage_directory=self.options.model_storage_directory,
download_enabled=self.options.download_enabled,
)
Expand Down

0 comments on commit 0eb065e

Please sign in to comment.