Skip to content

Commit

Permalink
Use CUDA for TextDetector if available (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
kenrick95 authored Jul 9, 2024
1 parent 0c9a02f commit cbfd3d4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mokuro/manga_page_ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from mokuro import __version__
from mokuro.cache import cache
from mokuro.utils import imread
import torch


class InvalidImage(Exception):
Expand All @@ -35,9 +36,11 @@ def __init__(
self.disable_ocr = disable_ocr

if not self.disable_ocr:
logger.info("Initializing text detector")
cuda = torch.cuda.is_available()
device = 'cuda' if cuda and not force_cpu else 'cpu'
logger.info(f"Initializing text detector, using device {device}")
self.text_detector = TextDetector(
model_path=cache.comic_text_detector, input_size=detector_input_size, device="cpu", act="leaky"
model_path=cache.comic_text_detector, input_size=detector_input_size, device=device, act="leaky"
)
self.mocr = MangaOcr(pretrained_model_name_or_path, force_cpu)

Expand Down

0 comments on commit cbfd3d4

Please sign in to comment.