Views
No views yet
1from PIL import Image
2from doclayout_yolo import YOLOv10
3from huggingface_hub import hf_hub_download
4
5# Replace with the actual repository ID
6repo_id = "eazymlshubham/DocLayoutYOLO"
7# Replace with the actual .pt filename
8filename = "doclayout_yolo_docstructbench_imgsz1024.pt"
9
10# Download the model file from Hugging Face Hub
11# This will download the file to a local cache directory and return the local path
12local_file_path = hf_hub_download(repo_id=repo_id, filename=filename, repo_type="model")
13
14# Load the pre-trained model
15# The model is loaded from the local file path obtained from hf_hub_download
16model = YOLOv10(local_file_path)
17
18# Perform prediction
19det_res = model.predict(
20 r"images/clinical_trials9.jpg", # Image to predict
21 imgsz=1024, # Prediction image size
22 conf=0.2, # Confidence threshold
23 device="cpu" # Device to use (e.g., 'cuda:0' or 'cpu')
24)
25
26# Annotate and save the result
27annotated_frame = det_res[0].plot(pil=True, line_width=5, font_size=20)
28
29
30img = Image.fromarray(annotated_frame)
31img.show()