Update README.md

#2
by hietraan - opened
Files changed (1) hide show
  1. README.md +198 -61
README.md CHANGED
@@ -1,94 +1,231 @@
1
  ---
 
 
2
  license: apache-2.0
 
 
3
  tags:
 
4
  - object-detection
5
- - vision
6
- datasets:
7
- - coco
8
- pipeline_tag: object-detection
9
- library_name: transformers
10
  ---
11
 
12
- # RF-DETR (Large)
13
 
14
- RF-DETR is a real-time detection transformer family introduced in [RF-DETR: Neural Architecture Search for Real-Time Detection Transformers](https://huggingface.co/papers/2511.09554) by Robinson et al. and integrated in πŸ€— Transformers via [PR #36895](https://github.com/huggingface/transformers/pull/36895).
15
 
16
- ## Model description
17
 
18
- RF-DETR is an end-to-end object detection model that combines ideas from LW-DETR and Deformable DETR: a DINOv2-with-registers style ViT backbone (with an RF-DETR windowing pattern for efficient attention), a multi-scale projector between encoder and decoder, and a multi-scale deformable DETR decoder for fast convergence and strong accuracy–latency tradeoffs.
 
 
 
 
19
 
20
- Key Architectural Details:
21
- - **Backbone:** DINOv2-with-registers style ViT with RF-DETR **windowed / full** attention alternation (instead of a purely convolutional encoder).
22
- - **Multi-scale fusion:** **RF-DETR multi-scale projector** (C2f-style blocks in the LW-DETR lineage) to aggregate multi-level backbone features before the decoder.
23
- - **Decoder:** **Deformable DETR**-style decoder with multi-scale deformable cross-attention; depth and input resolution vary by checkpoint (NAS frontier).
24
- - **Queries:** DETR-style object queries with bipartite matching and auxiliary decoder losses for training stability.
25
 
26
- Training Details:
27
- - **Detection losses:** classification plus bounding-box L1 and GIoU, with auxiliary losses on intermediate decoder layers.
28
- - **Group DETR:** parallel decoder copies during training for faster convergence (same high-level idea as LW-DETR's Group DETR).
29
- - **NAS (family-level):** the RF-DETR paper uses weight-sharing neural architecture search over practical accuracy–latency knobs after adapting a shared backbone on the target dataset, so many checkpoints correspond to different subnets without full independent retrains for every point on the frontier.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- ### How to use
32
 
33
- You can use the raw model for object detection. See the [model hub](https://huggingface.co/models?search=stevenbucaille/rf-detr) to look for all available RF-DETR models.
34
 
35
- Here is how to use this model:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  ```python
38
- from transformers import AutoImageProcessor, RfDetrForObjectDetection
39
- import torch
40
  from PIL import Image
41
- import requests
42
 
43
- url = "http://images.cocodataset.org/val2017/000000039769.jpg"
44
- image = Image.open(requests.get(url, stream=True).raw)
 
 
 
45
 
46
- processor = AutoImageProcessor.from_pretrained("stevenbucaille/rf-detr-large")
47
- model = RfDetrForObjectDetection.from_pretrained("stevenbucaille/rf-detr-large")
48
 
49
- inputs = processor(images=image, return_tensors="pt")
50
- outputs = model(**inputs)
 
51
 
52
- # convert outputs (bounding boxes and class logits) to COCO API
53
- # let's only keep detections with score > 0.35
54
- target_sizes = torch.tensor([image.size[::-1]])
55
- results = processor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.35)[0]
56
 
57
- for score, label, box in list(zip(results["scores"], results["labels"], results["boxes"]))[:8]:
58
- box = [round(i, 2) for i in box.tolist()]
59
- print(
60
- f"Detected {model.config.id2label[label.item()]} with confidence "
61
- f"{round(score.item(), 3)} at location {box}"
62
- )
63
  ```
64
- This should output:
 
 
 
 
65
  ```
66
- Detected remote with confidence 0.99 at location [40.68, 73.34, 175.62, 118.01]
67
- Detected cat with confidence 0.986 at location [348.33, 24.59, 640.12, 373.98]
68
- Detected cat with confidence 0.986 at location [13.36, 54.71, 316.59, 473.24]
69
- Detected remote with confidence 0.947 at location [334.29, 76.64, 370.47, 187.34]
70
- Detected couch with confidence 0.549 at location [1.67, 0.92, 639.56, 474.81]
71
- Detected remote with confidence 0.135 at location [338.6, 76.26, 369.93, 130.59]
72
- Detected remote with confidence 0.268 at location [258.99, 54.31, 291.03, 78.72]
73
- Detected remote with confidence 0.119 at location [335.04, 150.52, 352.63, 186.95]
74
  ```
75
 
76
- ## Training data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
- These checkpoints are trained on the standard [COCO 2017 object detection dataset](https://cocodataset.org/#home) label space (80 categories) as reflected in `config.id2label`.
79
 
80
- ### BibTeX entry and citation info
81
 
82
  ```bibtex
83
- @misc{robinson2026rfdetrneuralarchitecturesearch,
84
- title={RF-DETR: Neural Architecture Search for Real-Time Detection Transformers},
85
- author={Isaac Robinson and Peter Robicheaux and Matvei Popov and Deva Ramanan and Neehar Peri},
86
- year={2026},
87
- eprint={2511.09554},
88
- archivePrefix={arXiv},
89
- primaryClass={cs.CV},
90
- url={https://huggingface.co/papers/2511.09554},
91
  }
92
  ```
93
 
94
- This model was originally contributed by stevenbucaille in πŸ€— transformers.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ language:
3
+ - vi
4
  license: apache-2.0
5
+ library_name: rfdetr
6
+ pipeline_tag: object-detection
7
  tags:
8
+ - rf-detr
9
  - object-detection
10
+ - document-layout
11
+ - textbook
12
+ - fine-tuned
13
+
 
14
  ---
15
 
16
+ <div align="center">
17
 
18
+ # πŸ” VT-DETR β€” Textbook Layout Detection
19
 
20
+ **RF-DETR Large fine-tuned for Vietnamese textbook document layout analysis**
21
 
22
+ [![license](https://img.shields.io/badge/license-Apache%202.0-green.svg)](https://github.com/roboflow/rf-detr/blob/develop/LICENSE)
23
+ [![mAP50:95](https://img.shields.io/badge/mAP@50%3A95-83.0%25-blue)](.)
24
+ [![mAP50](https://img.shields.io/badge/mAP@50-92.2%25-blue)](.)
25
+ [![F1](https://img.shields.io/badge/F1-88.8%25-blue)](.)
26
+ [![Python](https://img.shields.io/badge/python-3.8%2B-blue)](.)
27
 
28
+ </div>
29
+
30
+ ---
 
 
31
 
32
+ ## Overview
33
+
34
+ **VT-DETR** stands for **Vietnamese Textbook Detection Transformer** β€” a fine-tuned variant of **RF-DETR Large** targeting automated detection of structural elements in Vietnamese textbook pages. It identifies four layout classes with high accuracy, enabling downstream document parsing, indexing, and educational content extraction pipelines.
35
+
36
+ | Property | Value |
37
+ |---|---|
38
+ | Base model | RF-DETR Large (pretrained) |
39
+ | Task | Object Detection |
40
+ | Domain | Document Layout / Textbook Pages |
41
+ | Language | Vietnamese |
42
+ | Input resolution | 640 Γ— 640 |
43
+
44
+ ---
45
+
46
+ ## Classes
47
+
48
+ | ID | Label | Description |
49
+ |:---:|---|---|
50
+ | 0 | `Object-detection` | Generic detectable region |
51
+ | 1 | `Figure` | Diagrams, illustrations, charts |
52
+ | 2 | `Icon` | Small symbolic graphics |
53
+ | 3 | `Table` | Tabular data structures |
54
+
55
+ ---
56
+
57
+ ## Demo
58
+
59
+ | Input | Inference Output |
60
+ |:---:|:---:|
61
+ | ![Input sample](./page077.png) | ![Inference result](./inference.webp) |
62
+
63
+ ---
64
 
65
+ ## Benchmark
66
 
67
+ ### βœ… Best validation metrics
68
 
69
+ | Metric | Value |
70
+ |---|---:|
71
+ | mAP @ \[0.50 : 0.95\] | **0.8304** |
72
+ | mAP @ 0.50 | **0.9216** |
73
+ | mAP @ 0.75 | **0.8992** |
74
+ | Precision | **0.9471** |
75
+ | Recall | **0.8997** |
76
+ | F1 | **0.8875** |
77
+
78
+ ### πŸ“‰ Last epoch metrics
79
+
80
+ | Metric | Value |
81
+ |---|---:|
82
+ | mAP @ \[0.50 : 0.95\] | 0.8161 |
83
+ | mAP @ 0.50 | 0.9074 |
84
+ | mAP @ 0.75 | 0.8811 |
85
+ | Precision | 0.9184 |
86
+ | Recall | 0.8272 |
87
+ | F1 | 0.8694 |
88
+
89
+ > Metrics sourced from `outputs/rfdetr_textbook/metrics.csv` (full training run). A separate single-image eval run in `outputs/exp_rfdetr_textbook/eval/metrics.json` (`num_images=1`) is not representative and excluded from this report.
90
+
91
+ ---
92
+
93
+ ## Training Configuration
94
+
95
+ ```yaml
96
+ model:
97
+ size: large
98
+
99
+ training:
100
+ epochs: 20
101
+ batch_size: 4
102
+ grad_accum_steps: 8
103
+ resolution: 640
104
+ device: cuda
105
+
106
+ augmentation:
107
+ mosaic: true
108
+ mixup: 0.1
109
+
110
+ early_stopping:
111
+ enabled: true
112
+ monitor: mAP50:95
113
+ patience_logs: 4
114
+ min_delta: 0.005
115
+ ```
116
+
117
+ ### Dataset split (COCO format)
118
+
119
+ ```
120
+ data_resplit/
121
+ β”œβ”€β”€ train/
122
+ β”‚ └── _annotations.coco.json
123
+ β”œβ”€β”€ valid/
124
+ β”‚ └── _annotations.coco.json
125
+ └── test/
126
+ └── _annotations.coco.json
127
+ ```
128
+
129
+ ---
130
+
131
+ ## Usage
132
+
133
+ ### Install
134
+
135
+ ```bash
136
+ pip install "rfdetr[train,loggers]"
137
+ ```
138
+
139
+ ### Inference
140
 
141
  ```python
142
+ from rfdetr import RFDETRLarge
 
143
  from PIL import Image
 
144
 
145
+ model = RFDETRLarge(pretrain_weights="checkpoint_best_total.pth")
146
+ image = Image.open("page077.png")
147
+ detections = model.predict(image, threshold=0.5)
148
+ print(detections)
149
+ ```
150
 
151
+ ### Train
 
152
 
153
+ ```bash
154
+ python -m rfdetr_finetune.train
155
+ ```
156
 
157
+ ### Evaluate
 
 
 
158
 
159
+ ```bash
160
+ python -m rfdetr_finetune.evaluate
 
 
 
 
161
  ```
162
+
163
+ ---
164
+
165
+ ## Repository Structure
166
+
167
  ```
168
+ huggingface/
169
+ β”œβ”€β”€ README.md # Model card
170
+ β”œβ”€β”€ checkpoint_best_total.pth # Best checkpoint (by mAP50:95)
171
+ β”œβ”€β”€ inference.webp # Demo output
172
+ └── page077.png # Demo input
 
 
 
173
  ```
174
 
175
+ ---
176
+
177
+ ## Limitations
178
+
179
+ - Trained and evaluated on Vietnamese textbook domain; generalization to other document types is not guaranteed.
180
+ - Test set benchmark not yet finalized β€” reported metrics are from the validation split.
181
+ - Robustness may be improved with additional data augmentation, larger datasets, or LR schedule tuning.
182
+
183
+ ---
184
+
185
+ ## License
186
+
187
+ This model is released under the **Apache License 2.0**, inherited from the base RF-DETR Large model by Roboflow.
188
+
189
+ > Copyright 2025 Roboflow, Inc.
190
+ > Licensed under the Apache License, Version 2.0. See [LICENSE](https://github.com/roboflow/rf-detr/blob/develop/LICENSE) for details.
191
+
192
+ Fine-tuned weights and additional code in this repository are also distributed under Apache 2.0.
193
+
194
+ ---
195
+
196
+ ## Citation
197
 
198
+ If you use this model or the RF-DETR framework, please cite:
199
 
200
+ **Base model (RF-DETR Large):**
201
 
202
  ```bibtex
203
+ @misc{rf-detr,
204
+ title = {RF-DETR: Neural Architecture Search for Real-Time Detection Transformers},
205
+ author = {Isaac Robinson and Peter Robicheaux and Matvei Popov and Deva Ramanan and Neehar Peri},
206
+ year = {2025},
207
+ eprint = {2511.09554},
208
+ archivePrefix= {arXiv},
209
+ primaryClass = {cs.CV},
210
+ url = {https://arxiv.org/abs/2511.09554}
211
  }
212
  ```
213
 
214
+ > Base weights: [Roboflow/rf-detr-large](https://huggingface.co/Roboflow/rf-detr-large) β€” Apache 2.0
215
+
216
+ **This fine-tuned model (VT-DETR):**
217
+
218
+ ```bibtex
219
+ @misc{vtdetr2025,
220
+ title = {VT-DETR: RF-DETR Large Fine-tuned for Textbook Layout Detection},
221
+ author = {hieptran318204},
222
+ year = {2025},
223
+ howpublished = {\url{https://huggingface.co/hieptran318204/vt-detr}}
224
+ }
225
+ ```
226
+
227
+ ---
228
+
229
+ <div align="center">
230
+ <sub>Fine-tuned with ❀️ for Vietnamese educational document processing</sub>
231
+ </div>