Object Detection
Safetensors
detr
davanstrien HF Staff commited on
Commit
f663929
·
verified ·
1 Parent(s): a55239a

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +45 -53
README.md CHANGED
@@ -1,75 +1,67 @@
1
  ---
2
- license: bsd-3-clause
3
- language:
4
- - en
5
  tags:
6
  - object-detection
7
- - faster-rcnn
8
- - resnet50
9
- - document-layout
10
- - historical-newspapers
11
  pipeline_tag: object-detection
 
 
12
  metrics:
13
- - 0.3251
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
- Object detection model fine-tuned from **torchvision Faster R-CNN (ResNet-50-FPN)**
21
- pre-trained on COCO (base model license: BSD-3-Clause, open and shareable) on the
22
- [`biglam/loc_beyond_words`](https://huggingface.co/datasets/biglam/loc_beyond_words) dataset
23
- (Library of Congress "Beyond Words", data license CC0-1.0).
24
 
25
- ## Classes (7) + background
26
 
27
- Photograph, Illustration, Map, Comics/Cartoon, Editorial Cartoon, Headline, Advertisement
28
 
29
- ## Validation results (COCO-style, biglam/loc_beyond_words validation set)
 
 
 
 
 
 
30
 
31
- | Metric | Value |
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
- ## Training
 
38
 
39
- | Setting | Value |
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
- Images are downscaled so the largest dimension is 520px (aspect preserved);
50
- boxes scaled accordingly. Predictions below score 0.5 are discarded.
 
 
 
 
 
51
 
52
- ## To load and run
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
- img = Image.open("page.jpg").convert("RGB")
71
- # resize to max-dim 520 like training, then:
72
- x = torch.as_tensor(np.asarray(img), dtype=torch.float32).permute(2, 0, 1) / 255.0
73
- with torch.no_grad():
74
- dets = model([x])[0]
 
 
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**