biglam/loc_beyond_words
Viewer • Updated • 3.56k • 195 • 15
How to use harness-race/opencode-r2 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("object-detection", model="harness-race/opencode-r2") # Load model directly
from transformers import AutoImageProcessor, AutoModelForObjectDetection
processor = AutoImageProcessor.from_pretrained("harness-race/opencode-r2")
model = AutoModelForObjectDetection.from_pretrained("harness-race/opencode-r2", device_map="auto")# Load model directly
from transformers import AutoImageProcessor, AutoModelForObjectDetection
processor = AutoImageProcessor.from_pretrained("harness-race/opencode-r2")
model = AutoModelForObjectDetection.from_pretrained("harness-race/opencode-r2", device_map="auto")A fine-tuned object-detection model for fine-grained content detection in historical newspaper and periodical pages, built on the Beyond Words dataset (BigLam / Library of Congress). It detects the 7 page-layout content classes listed below.
facebook/detr-resnet-50 (DETR, Apache-2.0)Photograph, Illustration, Map, Comics/Cartoon, Editorial Cartoon, Headline, Advertisementbiglam/loc_beyond_wordsfacebook/detr-resnet-50) with the classification head re-initialized to 8 outputs (7 classes + no-object).Evaluated on the 712-example biglam/loc_beyond_words validation split (COCO metrics via pycocotools).
| Metric | Value |
|---|---|
| COCO mAP @ IoU [0.5:0.95] | 0.2842 |
| COCO AP @ IoU 0.5 | 0.4189 |
| COCO AP @ IoU 0.75 | 0.3196 |
| AR@maxDets=100 | 0.4302 |
Per-class COCO mAP @ [0.5:0.95]:
| Class | mAP |
|---|---|
| Photograph | 0.4027 |
| Illustration | 0.0485 |
| Map | 0.0431 |
| Comics/Cartoon | 0.2761 |
| Editorial Cartoon | 0.1702 |
| Headline | 0.5226 |
| Advertisement | 0.5259 |
Training loss: 21.06 (epoch 0) → 7.44 (epoch 4).
from transformers import AutoImageProcessor, AutoModelForObjectDetection
import torch
from PIL import Image
processor = AutoImageProcessor.from_pretrained("harness-race/opencode-r2")
model = AutoModelForObjectDetection.from_pretrained("harness-race/opencode-r2")
img = Image.open("page.png").convert("RGB")
inputs = processor(images=img, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
target_sizes = torch.tensor([[img.height, img.width]])
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.5)[0]
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
box = [round(i, 1) for i in box.tolist()]
print(f"{model.config.id2label[label.item()]}: {round(score.item(),3)} {box}")
biglam/loc_beyond_words.Base model
facebook/detr-resnet-50
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("object-detection", model="harness-race/opencode-r2")