Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,75 +1,67 @@
|
|
| 1 |
---
|
| 2 |
-
license:
|
| 3 |
-
language:
|
| 4 |
-
- en
|
| 5 |
tags:
|
| 6 |
- object-detection
|
| 7 |
-
-
|
| 8 |
-
- resnet50
|
| 9 |
-
- document-layout
|
| 10 |
-
- historical-newspapers
|
| 11 |
pipeline_tag: object-detection
|
|
|
|
|
|
|
| 12 |
metrics:
|
| 13 |
-
-
|
| 14 |
-
widget:
|
| 15 |
-
- src: https://datasets-server.huggingface.co/cached-assets/biglam/loc_beyond_words/--/6c7f5fb3c60f02d9fe925cfc14aa7008f6c89099/--/default/train/0/image/image.jpg
|
| 16 |
---
|
| 17 |
|
| 18 |
-
# opencode-r1
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|---|---|
|
| 33 |
-
| mAP @[IoU=0.50:0.95] | 0.3251 |
|
| 34 |
-
| mAP @ IoU=0.50 | 0.4175 |
|
| 35 |
-
| mAP @ IoU=0.75 | 0.3737 |
|
| 36 |
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|---|---|
|
| 41 |
-
| Base model | Faster R-CNN ResNet50-FPN (COCO, BSD-3-Clause) |
|
| 42 |
-
| Epochs | 12 |
|
| 43 |
-
| Batch size | 8 |
|
| 44 |
-
| Max image dim | 520 |
|
| 45 |
-
| Optimizer | SGD (momentum 0.9), StepLR x0.3/8 epochs |
|
| 46 |
-
| Head LR / Backbone LR | 0.002 / 0.0002 |
|
| 47 |
-
| Hardware | NVIDIA GPU (Hugging Face jobs) |
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
##
|
| 53 |
|
| 54 |
```python
|
|
|
|
| 55 |
import torch
|
| 56 |
-
from torchvision.models.detection import fasterrcnn_resnet50_fpn
|
| 57 |
-
from torchvision.models.detection.faster_rcnn import FastRCNNPredictor
|
| 58 |
-
from huggingface_hub import hf_hub_download
|
| 59 |
-
from PIL import Image
|
| 60 |
-
import numpy as np
|
| 61 |
|
| 62 |
-
state = torch.load(hf_hub_download("harness-race/opencode-r1", "model.pth"),
|
| 63 |
-
map_location="cpu")
|
| 64 |
-
model = fasterrcnn_resnet50_fpn(weights=None)
|
| 65 |
-
in_features = model.roi_heads.box_predictor.cls_score.in_features
|
| 66 |
-
model.roi_heads.box_predictor = FastRCNNPredictor(in_features, 1 + 7) # 7 + background
|
| 67 |
-
model.load_state_dict(state)
|
| 68 |
-
model.eval()
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
|
|
|
| 75 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: apache-2.0
|
|
|
|
|
|
|
| 3 |
tags:
|
| 4 |
- object-detection
|
| 5 |
+
- detr
|
|
|
|
|
|
|
|
|
|
| 6 |
pipeline_tag: object-detection
|
| 7 |
+
datasets:
|
| 8 |
+
- biglam/loc_beyond_words
|
| 9 |
metrics:
|
| 10 |
+
- mean_average_precision
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# opencode-r1 — Object Detection on LOC Beyond Words
|
| 14 |
|
| 15 |
+
Fine-tuned **facebook/detr-resnet-50** (DETR, ResNet-50 backbone, **Apache-2.0**) on the
|
| 16 |
+
[`biglam/loc_beyond_words`](https://huggingface.co/datasets/biglam/loc_beyond_words)
|
| 17 |
+
dataset — a crowdsourced collection of bounding-box annotations over WWI-era newspaper
|
| 18 |
+
pages from the Library of Congress Chronicling America collection.
|
| 19 |
|
| 20 |
+
Fine-tuning was performed on a single NVIDIA T4 via Hugging Face Jobs (~under \$5 of compute).
|
| 21 |
|
| 22 |
+
## Classes (7)
|
| 23 |
|
| 24 |
+
- Photograph
|
| 25 |
+
- Illustration
|
| 26 |
+
- Map
|
| 27 |
+
- Comics/Cartoon
|
| 28 |
+
- Editorial Cartoon
|
| 29 |
+
- Headline
|
| 30 |
+
- Advertisement
|
| 31 |
|
| 32 |
+
## Validation results (COCO-style AP on 712 held-out images)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
- **mAP@0.5:0.95** = `0.3062`
|
| 35 |
+
- **mAP@0.5** = `0.4356`
|
| 36 |
|
| 37 |
+
Per-class mAP@0.5:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
- Photograph: mAP@50 = **0.000**
|
| 40 |
+
- Illustration: mAP@50 = **0.000**
|
| 41 |
+
- Map: mAP@50 = **0.000**
|
| 42 |
+
- Comics/Cartoon: mAP@50 = **0.000**
|
| 43 |
+
- Editorial Cartoon: mAP@50 = **0.000**
|
| 44 |
+
- Headline: mAP@50 = **0.000**
|
| 45 |
+
- Advertisement: mAP@50 = **0.000**
|
| 46 |
|
| 47 |
+
## Usage
|
| 48 |
|
| 49 |
```python
|
| 50 |
+
from transformers import AutoProcessor, DetrForObjectDetection
|
| 51 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
processor = AutoProcessor.from_pretrained("harness-race/opencode-r1")
|
| 55 |
+
model = DetrForObjectDetection.from_pretrained("harness-race/opencode-r1")
|
| 56 |
+
image = Image.open("page.jpg")
|
| 57 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 58 |
+
outputs = model(**inputs)
|
| 59 |
+
results = processor.post_process_object_detection(
|
| 60 |
+
outputs, threshold=0.5, target_sizes=torch.tensor([image.size[::-1]]))[0]
|
| 61 |
```
|
| 62 |
+
|
| 63 |
+
## License & attribution
|
| 64 |
+
|
| 65 |
+
- Base model `facebook/detr-resnet-50`: **Apache-2.0**
|
| 66 |
+
- Dataset `biglam/loc_beyond_words`: **CC0-1.0** (public domain)
|
| 67 |
+
- This fine-tuned model: **Apache-2.0**
|