biglam/loc_beyond_words
Viewer • Updated • 3.56k • 315 • 15
How to use harness-race/pi-r2-probe with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("object-detection", model="harness-race/pi-r2-probe") # Load model directly
from transformers import AutoImageProcessor, AutoModelForObjectDetection
processor = AutoImageProcessor.from_pretrained("harness-race/pi-r2-probe")
model = AutoModelForObjectDetection.from_pretrained("harness-race/pi-r2-probe", device_map="auto")Object detection model fine-tuned from facebook/detr-resnet-50
(Apache-2.0) on the biglam/loc_beyond_words
dataset (CC0): crowd-sourced bounding-box annotations of World War I-era newspaper pages
from the Library of Congress Chronicling America collection.
facebook/detr-resnet-50 — license Apache-2.0 (shareable).biglam/loc_beyond_words — license CC0-1.0 (public domain).pixel_mask. Training used random horizontal flips and random scale
(70–100% of the max size).WeightedRandomSampler when building training batches.Evaluated on the biglam/loc_beyond_words validation split (32 images)
with COCO-style IoU-matched metrics (area = all, max detections = 300, NMS IoU threshold 0.75).
| Metric | Value |
|---|---|
| mAP @[0.5:0.95] | 1.843759794973911e-06 |
| mAP @0.50 | 6.675969148985493e-05 |
| mAP @0.75 | 0.0 |
| AR @100 | 0.0021307798481711524 |
Per-class AP @0.50:
| Class | AP@0.50 |
|---|---|
| Photograph | - |
Raw per-image predictions and this training script are included in this repo (
eval_predictions.json,train_detr.py).
from transformers import AutoImageProcessor, DetrForObjectDetection
from PIL import Image
import torch
repo = "harness-race/pi-r2-probe"
processor = AutoImageProcessor.from_pretrained(repo)
model = DetrForObjectDetection.from_pretrained(repo)
img = Image.open("newspaper_page.jpg").convert("RGB")
inputs = processor(images=img, return_tensors="pt")
with torch.no_grad():
out = model(**inputs)
score_threshold = 0.5
for logits, box in zip(out.logits[0], out.pred_boxes[0]):
prob = logits.softmax(-1)
cls_idx, score = prob[:, :-1].max(-1)
if score.item() > score_threshold:
cx, cy, bw, bh = box.tolist()
W, H = img.size
x1, y1 = (cx - bw/2)*W, (cy - bh/2)*H
x2, y2 = (cx + bw/2)*W, (cy + bh/2)*H
print(model.config.id2label[cls_idx.item()], round(score.item(), 3), [round(x1), round(y1), round(x2), round(y2)])
facebook/detr-resnet-50: Apache-2.0.biglam/loc_beyond_words: CC0-1.0 (Public Domain Dedication).Base model
facebook/detr-resnet-50