|
|
@@ -4,7 +4,6 @@ import logging
|
|
|
import sys
|
|
|
from io import StringIO
|
|
|
from typing import Any, BinaryIO, Container, Iterator, Optional, cast
|
|
|
-import torch
|
|
|
import numpy as np
|
|
|
import tqdm
|
|
|
from pymupdf import Document
|
|
|
@@ -22,7 +21,7 @@ from pdf2zh.pdfdevice import PDFDevice, TagExtractor
|
|
|
from pdf2zh.pdfexceptions import PDFValueError
|
|
|
from pdf2zh.pdfinterp import PDFPageInterpreter, PDFResourceManager
|
|
|
from pdf2zh.pdfpage import PDFPage
|
|
|
-from pdf2zh.utils import AnyIO, FileOrName, open_filename
|
|
|
+from pdf2zh.utils import AnyIO, FileOrName, open_filename, get_device
|
|
|
|
|
|
|
|
|
def extract_text_to_fp(
|
|
|
@@ -176,11 +175,7 @@ def extract_text_to_fp(
|
|
|
pix.height, pix.width, 3
|
|
|
)[:, :, ::-1]
|
|
|
page_layout = model.predict(
|
|
|
- image,
|
|
|
- imgsz=int(pix.height / 32) * 32,
|
|
|
- device=(
|
|
|
- "cuda:0" if torch.cuda.is_available() else "cpu"
|
|
|
- ), # Auto-select GPU if available
|
|
|
+ image, imgsz=int(pix.height / 32) * 32, device=get_device()
|
|
|
)[0]
|
|
|
# kdtree 是不可能 kdtree 的,不如直接渲染成图片,用空间换时间
|
|
|
box = np.ones((pix.height, pix.width))
|