Baiyinyou commited on
Commit
f676d76
·
verified ·
1 Parent(s): 79ebb5a

Update detection_ocr.py

Browse files
Files changed (1) hide show
  1. detection_ocr.py +10 -9
detection_ocr.py CHANGED
@@ -1,7 +1,6 @@
1
  import torch
2
  from PIL import Image, ImageDraw
3
  from typing import List, Dict, Any
4
- from huggingface_hub import hf_hub_download
5
  from doclayout_yolo import YOLOv10
6
  from pix2tex import cli as pix2tex
7
  from pathlib import Path
@@ -14,20 +13,22 @@ class DetectionOCR:
14
 
15
  def __init__(self, device=None):
16
  if device is None:
17
- device = "cuda:0" if torch.cuda.is_available() else "cpu"
18
  self.device = device
19
  print(f"[DetectionOCR] Using {self.device}")
20
 
21
- # Load YOLO model
22
- ckpt = "yolo.pt"
23
- print("[DetectionOCR] Loading YOLO checkpoint...")
24
- self.yolo = YOLOv10(ckpt).to(self.device)
25
- self.names = self.yolo.names # ← FIX
 
26
 
27
- # Load Pix2TeX OCR
28
- print("[DetectionOCR] Loading LatexOCR...")
29
  self.pix2tex = pix2tex.LatexOCR()
30
 
 
31
  # ------------------------------------------------------------
32
  # 1. DETECTION
33
  # ------------------------------------------------------------
 
1
  import torch
2
  from PIL import Image, ImageDraw
3
  from typing import List, Dict, Any
 
4
  from doclayout_yolo import YOLOv10
5
  from pix2tex import cli as pix2tex
6
  from pathlib import Path
 
13
 
14
  def __init__(self, device=None):
15
  if device is None:
16
+ device = "cuda" if torch.cuda.is_available() else "cpu"
17
  self.device = device
18
  print(f"[DetectionOCR] Using {self.device}")
19
 
20
+ # ---- YOLO (HF from_pretrained) ----
21
+ print("[DetectionOCR] Loading DocLayout-YOLO...")
22
+ self.yolo = YOLOv10.from_pretrained(
23
+ "juliozhao/DocLayout-YOLO-DocStructBench"
24
+ ).to(self.device)
25
+ self.names = self.yolo.names
26
 
27
+ # ---- Pix2TeX ----
28
+ print("[DetectionOCR] Loading pix2tex OCR...")
29
  self.pix2tex = pix2tex.LatexOCR()
30
 
31
+
32
  # ------------------------------------------------------------
33
  # 1. DETECTION
34
  # ------------------------------------------------------------