Object Detection
Transformers
Safetensors
detr
computer-vision
text-detection
historical-documents
Eval Results (legacy)
Instructions to use harness-race/opencode-r2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
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")# pip install -U transformers accelerate # 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") - Notebooks
- Google Colab
- Kaggle
add model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
base_model: facebook/detr-resnet-50
|
| 4 |
+
tags:
|
| 5 |
+
- object-detection
|
| 6 |
+
- transformers
|
| 7 |
+
- detr
|
| 8 |
+
- computer-vision
|
| 9 |
+
- text-detection
|
| 10 |
+
- historical-documents
|
| 11 |
+
widget:
|
| 12 |
+
- enable_torchscript: false
|
| 13 |
+
datasets:
|
| 14 |
+
- biglam/loc_beyond_words
|
| 15 |
+
library_name: transformers
|
| 16 |
+
pipeline_tag: object-detection
|
| 17 |
+
model-index:
|
| 18 |
+
- name: opencode-r2
|
| 19 |
+
results:
|
| 20 |
+
- task:
|
| 21 |
+
type: object-detection
|
| 22 |
+
name: Object Detection
|
| 23 |
+
dataset:
|
| 24 |
+
type: biglam/loc_beyond_words
|
| 25 |
+
name: Beeyond Words (Beyond Words) fine-grained illustration detection
|
| 26 |
+
split: validation
|
| 27 |
+
metrics:
|
| 28 |
+
- type: mean_average_precision
|
| 29 |
+
value: 0.00
|
| 30 |
+
name: COCO mAP @ [0.5:0.95]
|
| 31 |
+
- type: coco_ap_50
|
| 32 |
+
value: 0.00
|
| 33 |
+
name: COCO AP@IoU0.5
|
| 34 |
+
- type: metric
|
| 35 |
+
value: 0.00
|
| 36 |
+
name: per-class mAP
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
# opencode-r2
|
| 40 |
+
|
| 41 |
+
A fine-tuned object-detection model for fine-grained content detection in historical newspaper
|
| 42 |
+
and periodical pages, built on the [Beyond Words](https://huggingface.co/datasets/biglam/loc_beyond_words)
|
| 43 |
+
dataset (BigLam / Library of Congress). It detects the 7 page-layout content classes listed below.
|
| 44 |
+
|
| 45 |
+
## Model
|
| 46 |
+
|
| 47 |
+
- **Base model:** [`facebook/detr-resnet-50`](https://huggingface.co/facebook/detr-resnet-50) (DETR, **Apache-2.0**)
|
| 48 |
+
- **Task:** Object detection (COCO-style bounding boxes)
|
| 49 |
+
- **Classes (7):** `Photograph`, `Illustration`, `Map`, `Comics/Cartoon`, `Editorial Cartoon`, `Headline`, `Advertisement`
|
| 50 |
+
|
| 51 |
+
## Dataset
|
| 52 |
+
|
| 53 |
+
- **Source:** [`biglam/loc_beyond_words`](https://huggingface.co/datasets/biglam/loc_beyond_words)
|
| 54 |
+
- **Training:** 2,846 examples
|
| 55 |
+
- **Validation:** 712 examples
|
| 56 |
+
|
| 57 |
+
## Training
|
| 58 |
+
|
| 59 |
+
- Detector: DETR (`facebook/detr-resnet-50`) with the classification head re-initialized to 8 outputs (7 classes + no-object).
|
| 60 |
+
- Loss: DETR set-prediction loss (classification + L1 box + GIoU).
|
| 61 |
+
- Optimizer: AdamW (lr 1e-4), cosine/linear schedule with warmup, grad clip 1.0.
|
| 62 |
+
- Image size: shortest edge 560 px (longest edge 800 px).
|
| 63 |
+
- Backbone, transformer, and classifier all fine-tuned end-to-end.
|
| 64 |
+
|
| 65 |
+
### Validation results
|
| 66 |
+
|
| 67 |
+
| Metric | Value |
|
| 68 |
+
|---|---|
|
| 69 |
+
| COCO mAP @ IoU [0.5:0.95] | _TBD_ |
|
| 70 |
+
| COCO AP @ IoU 0.5 | _TBD_ |
|
| 71 |
+
| COCO AP @ IoU 0.75 | _TBD_ |
|
| 72 |
+
| AR@maxDets=100 | _TBD_ |
|
| 73 |
+
| Per-class mean AP | _TBD_ |
|
| 74 |
+
|
| 75 |
+
**Validation results will be reported here after training completes.**
|
| 76 |
+
|
| 77 |
+
## Usage
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
from transformers import AutoImageProcessor, AutoModelForObjectDetection
|
| 81 |
+
import torch
|
| 82 |
+
from PIL import Image
|
| 83 |
+
|
| 84 |
+
processor = AutoImageProcessor.from_pretrained("harness-race/opencode-r2")
|
| 85 |
+
model = AutoModelForObjectDetection.from_pretrained("harness-race/opencode-r2")
|
| 86 |
+
|
| 87 |
+
img = Image.open("page.png").convert("RGB")
|
| 88 |
+
inputs = processor(images=img, return_tensors="pt")
|
| 89 |
+
with torch.no_grad():
|
| 90 |
+
outputs = model(**inputs)
|
| 91 |
+
|
| 92 |
+
target_sizes = torch.tensor([[img.height, img.width]])
|
| 93 |
+
results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.5)[0]
|
| 94 |
+
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]):
|
| 95 |
+
box = [round(i, 1) for i in box.tolist()]
|
| 96 |
+
print(f"{model.config.id2label[label.item()]}: {round(score.item(),3)} {box}")
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
## License and attribution
|
| 100 |
+
|
| 101 |
+
- The fine-tuned weights in this repository are released under **Apache-2.0** (same as the base DETR model), so the model is free to share and use.
|
| 102 |
+
- Base detector: *End-to-End Object Detection with Transformers* (Carion et al., 2020).
|
| 103 |
+
- Data: Beyond Words (Library of Congress) via `biglam/loc_beyond_words`.
|
| 104 |
+
|
| 105 |
+
## Caveats
|
| 106 |
+
|
| 107 |
+
- Model was fine-tuned on a single GPU with a limited training budget; results reflect that constraint.
|
| 108 |
+
- Detection resolution and accuracy trade-offs exist for very small text blocks.
|