biglam/loc_beyond_words
Viewer โข Updated โข 3.56k โข 315 โข 15
How to use harness-race/pi-r2 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("object-detection", model="harness-race/pi-r2") # Load model directly
from transformers import AutoImageProcessor, AutoModelForObjectDetection
processor = AutoImageProcessor.from_pretrained("harness-race/pi-r2")
model = AutoModelForObjectDetection.from_pretrained("harness-race/pi-r2", device_map="auto")Fine-tuned DETR (ResNet-50) for detecting layout regions in historical newspaper
page scans, trained on biglam/loc_beyond_words
(2,846 train / 712 validation images, 7 classes).
facebook/detr-resnet-50 โ Apache-2.0 (open license, free to share).biglam/loc_beyond_words is CC0-1.0 (public domain).Photograph, Illustration, Map, Comics/Cartoon, Editorial Cartoon, Headline, Advertisement
| Metric | Value |
|---|---|
| AP @[IoU .50:.95] | 0.423 |
| AP @IoU .50 | 0.566 |
| AP @IoU .75 | 0.486 |
| AP small | 0.050 |
| AP medium | 0.250 |
| AP large | 0.453 |
| AR max=1 | 0.286 |
| AR max=10 | 0.574 |
| AR max=100 | 0.625 |
| Class | AP |
|---|---|
| Photograph | n/a |
| Illustration | n/a |
| Map | n/a |
| Comics/Cartoon | n/a |
| Editorial Cartoon | n/a |
| Headline | n/a |
| Advertisement | n/a |
Note:
AP_small/AP_medium/AP_largeare computed on the resized evaluation inputs, not original pixel areas; treat small-object numbers cautiously.
from transformers import DetrImageProcessor, DetrForObjectDetection
from PIL import Image
import torch
processor = DetrImageProcessor.from_pretrained("harness-race/pi-r2")
model = DetrForObjectDetection.from_pretrained("harness-race/pi-r2")
image = Image.open("page.png").convert("RGB")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
results = processor.post_process_object_detection(
outputs, threshold=0.5, target_sizes=[(image.height, image.width)])[0]
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
print(model.config.id2label[label.item()], round(score.item(), 3), [round(v, 1) for v in box.tolist()])
model.safetensors, config.json, preprocessor_config.json โ fine-tuned model + processorval_metrics.json โ full COCO validation metrics (incl. per-class AP)figures/ โ sample predictions on the validation settrain_detr.py, requirements.txt โ training code for reproducibilityBase model
facebook/detr-resnet-50