models-tmp commited on
Commit
893375f
·
verified ·
1 Parent(s): f679d1c

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +360 -0
README.md ADDED
@@ -0,0 +1,360 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: agpl-3.0
3
+ base_model:
4
+ - Ultralytics/YOLOv8
5
+ pipeline_tag: object-detection
6
+ datasets:
7
+ - tech4humans/signature-detection
8
+ metrics:
9
+ - f1
10
+ - precision
11
+ - recall
12
+ library_name: ultralytics
13
+ library_version: 8.0.239
14
+ inference: false
15
+ tags:
16
+ - object-detection
17
+ - signature-detection
18
+ - yolo
19
+ - yolov8
20
+ - pytorch
21
+ model-index:
22
+ - name: tech4humans/yolov8s-signature-detector
23
+ results:
24
+ - task:
25
+ type: object-detection
26
+ dataset:
27
+ type: tech4humans/signature-detection
28
+ name: tech4humans/signature-detection
29
+ split: test
30
+ metrics:
31
+ - type: precision
32
+ value: 0.94499
33
+ name: mAP@0.5
34
+ - type: precision
35
+ value: 0.6735
36
+ name: mAP@0.5:0.95
37
+ - type: precision
38
+ value: 0.947396
39
+ name: precision
40
+ - type: recall
41
+ value: 0.897216
42
+ name: recall
43
+ - type: f1
44
+ value: 0.921623
45
+ ---
46
+
47
+ # **YOLOv8s - Handwritten Signature Detection**
48
+
49
+ This repository presents a YOLOv8s-based model, fine-tuned to detect handwritten signatures in document images.
50
+
51
+ | Resource | Links / Badges | Details |
52
+ |---------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
53
+ | **Article** | [![Paper page](https://huggingface.co/datasets/huggingface/badges/resolve/main/paper-page-md.svg)](https://huggingface.co/blog/samuellimabraz/signature-detection-model) | A detailed community article covering the full development process of the project |
54
+ | **Model Files** | [![HF Model](https://huggingface.co/datasets/huggingface/badges/resolve/main/model-on-hf-md.svg)](https://huggingface.co/tech4humans/yolov8s-signature-detector) | **Available formats:** [![PyTorch](https://img.shields.io/badge/PyTorch-%23EE4C2C.svg?style=flat&logo=PyTorch&logoColor=white)](https://pytorch.org/) [![ONNX](https://img.shields.io/badge/ONNX-005CED.svg?style=flat&logo=ONNX&logoColor=white)](https://onnx.ai/) [![TensorRT](https://img.shields.io/badge/TensorRT-76B900.svg?style=flat&logo=NVIDIA&logoColor=white)](https://developer.nvidia.com/tensorrt) |
55
+ | **Dataset – Original** | [![Roboflow](https://app.roboflow.com/images/download-dataset-badge.svg)](https://universe.roboflow.com/tech-ysdkk/signature-detection-hlx8j) | 2,819 document images annotated with signature coordinates |
56
+ | **Dataset – Processed** | [![HF Dataset](https://huggingface.co/datasets/huggingface/badges/resolve/main/dataset-on-hf-md.svg)](https://huggingface.co/datasets/tech4humans/signature-detection) | Augmented and pre-processed version (640px) for model training |
57
+ | **Notebooks – Model Experiments** | [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1wSySw_zwyuv6XSaGmkngI4dwbj-hR4ix) [![W&B Training](https://img.shields.io/badge/W%26B_Training-FFBE00?style=flat&logo=WeightsAndBiases&logoColor=white)](https://api.wandb.ai/links/samuel-lima-tech4humans/30cmrkp8) | Complete training and evaluation pipeline with selection among different architectures (yolo, detr, rt-detr, conditional-detr, yolos) |
58
+ | **Notebooks – HP Tuning** | [![Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1wSySw_zwyuv6XSaGmkngI4dwbj-hR4ix) [![W&B HP Tuning](https://img.shields.io/badge/W%26B_HP_Tuning-FFBE00?style=flat&logo=WeightsAndBiases&logoColor=white)](https://api.wandb.ai/links/samuel-lima-tech4humans/31a6zhb1) | Optuna trials for optimizing the precision/recall balance |
59
+ | **Inference Server** | [![GitHub](https://img.shields.io/badge/Deploy-ffffff?style=for-the-badge&logo=github&logoColor=black)](https://github.com/tech4ai/t4ai-signature-detect-server) | Complete deployment and inference pipeline with Triton Inference Server<br> [![OpenVINO](https://img.shields.io/badge/OpenVINO-00c7fd?style=flat&logo=intel&logoColor=white)](https://docs.openvino.ai/2025/index.html) [![Docker](https://img.shields.io/badge/Docker-2496ED?logo=docker&logoColor=fff)](https://www.docker.com/) [![Triton](https://img.shields.io/badge/Triton-Inference%20Server-76B900?labelColor=black&logo=nvidia)](https://developer.nvidia.com/triton-inference-server) |
60
+ | **Live Demo** | [![HF Space](https://huggingface.co/datasets/huggingface/badges/resolve/main/open-in-hf-spaces-md.svg)](https://huggingface.co/spaces/tech4humans/signature-detection) | Graphical interface with real-time inference<br> [![Gradio](https://img.shields.io/badge/Gradio-FF5722?style=flat&logo=Gradio&logoColor=white)](https://www.gradio.app/) [![Plotly](https://img.shields.io/badge/PLotly-000000?style=flat&logo=plotly&logoColor=white)](https://plotly.com/python/) |
61
+
62
+ ---
63
+
64
+ ## **Dataset**
65
+
66
+ <table>
67
+ <tr>
68
+ <td style="text-align: center; padding: 10px;">
69
+ <a href="https://universe.roboflow.com/tech-ysdkk/signature-detection-hlx8j">
70
+ <img src="https://app.roboflow.com/images/download-dataset-badge.svg">
71
+ </a>
72
+ </td>
73
+ <td style="text-align: center; padding: 10px;">
74
+ <a href="https://huggingface.co/datasets/tech4humans/signature-detection">
75
+ <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/dataset-on-hf-md-dark.svg" alt="Dataset on HF">
76
+ </a>
77
+ </td>
78
+ </tr>
79
+ </table>
80
+
81
+ The training utilized a dataset built from two public datasets: [Tobacco800](https://paperswithcode.com/dataset/tobacco-800) and [signatures-xc8up](https://universe.roboflow.com/roboflow-100/signatures-xc8up), unified and processed in [Roboflow](https://roboflow.com/).
82
+
83
+ **Dataset Summary:**
84
+ - Training: 1,980 images (70%)
85
+ - Validation: 420 images (15%)
86
+ - Testing: 419 images (15%)
87
+ - Format: COCO JSON
88
+ - Resolution: 640x640 pixels
89
+
90
+ ![Roboflow Dataset](./assets/roboflow_ds.png)
91
+
92
+ ---
93
+
94
+ ## **Training Process**
95
+
96
+ The training process involved the following steps:
97
+
98
+ ### 1. **Model Selection:**
99
+
100
+ Various object detection models were evaluated to identify the best balance between precision, recall, and inference time.
101
+
102
+
103
+ | **Metric** | [rtdetr-l](https://github.com/ultralytics/assets/releases/download/v8.2.0/rtdetr-l.pt) | [yolos-base](https://huggingface.co/hustvl/yolos-base) | [yolos-tiny](https://huggingface.co/hustvl/yolos-tiny) | [conditional-detr-resnet-50](https://huggingface.co/microsoft/conditional-detr-resnet-50) | [detr-resnet-50](https://huggingface.co/facebook/detr-resnet-50) | [yolov8x](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8x.pt) | [yolov8l](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8l.pt) | [yolov8m](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8m.pt) | [yolov8s](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8s.pt) | [yolov8n](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov8n.pt) | [yolo11x](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x.pt) | [yolo11l](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11l.pt) | [yolo11m](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11m.pt) | [yolo11s](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s.pt) | [yolo11n](https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11n.pt) | [yolov10x](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov10x.pt) | [yolov10l](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov10l.pt) | [yolov10b](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov10b.pt) | [yolov10m](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov10m.pt) | [yolov10s](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov10s.pt) | [yolov10n](https://github.com/ultralytics/assets/releases/download/v8.2.0/yolov10n.pt) |
104
+ |:---------------------|---------:|-----------:|-----------:|---------------------------:|---------------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|--------:|---------:|---------:|---------:|---------:|---------:|---------:|
105
+ | **Inference Time - CPU (ms)** | 583.608 | 1706.49 | 265.346 | 476.831 | 425.649 | 1259.47 | 871.329 | 401.183 | 216.6 | 110.442 | 1016.68 | 518.147 | 381.652 | 179.792 | 106.656 | 821.183 | 580.767 | 473.109 | 320.12 | 150.076 | **73.8596** |
106
+ | **mAP50** | 0.92709 | 0.901154 | 0.869814 | **0.936524** | 0.88885 | 0.794237| 0.800312| 0.875322| 0.874721| 0.816089| 0.667074| 0.707409| 0.809557| 0.835605| 0.813799| 0.681023| 0.726802| 0.789835| 0.787688| 0.663877| 0.734332 |
107
+ | **mAP50-95** | 0.622364 | 0.583569 | 0.469064 | 0.653321 | 0.579428 | 0.552919| 0.593976| **0.665495**| 0.65457 | 0.623963| 0.482289| 0.499126| 0.600797| 0.638849| 0.617496| 0.474535| 0.522654| 0.578874| 0.581259| 0.473857| 0.552704 |
108
+
109
+
110
+ ![Model Selection](./assets/model_selection.png)
111
+
112
+ #### Highlights:
113
+ - **Best mAP50:** `conditional-detr-resnet-50` (**0.936524**)
114
+ - **Best mAP50-95:** `yolov8m` (**0.665495**)
115
+ - **Fastest Inference Time:** `yolov10n` (**73.8596 ms**)
116
+
117
+ Detailed experiments are available on [**Weights & Biases**](https://api.wandb.ai/links/samuel-lima-tech4humans/30cmrkp8).
118
+
119
+ ### 2. **Hyperparameter Tuning:**
120
+
121
+ The YOLOv8s model, which demonstrated a good balance of inference time, precision, and recall, was selected for hyperparameter tuning.
122
+
123
+ [Optuna](https://optuna.org/) was used for 20 optimization trials.
124
+ The hyperparameter tuning used the following parameter configuration:
125
+
126
+ ```python
127
+ dropout = trial.suggest_float("dropout", 0.0, 0.5, step=0.1)
128
+ lr0 = trial.suggest_float("lr0", 1e-5, 1e-1, log=True)
129
+ box = trial.suggest_float("box", 3.0, 7.0, step=1.0)
130
+ cls = trial.suggest_float("cls", 0.5, 1.5, step=0.2)
131
+ opt = trial.suggest_categorical("optimizer", ["AdamW", "RMSProp"])
132
+ ```
133
+
134
+ Results can be visualized here: [**Hypertuning Experiment**](https://api.wandb.ai/links/samuel-lima-tech4humans/31a6zhb1).
135
+
136
+ ![Hypertuning Sweep](./assets/sweep.png)
137
+
138
+ ### 3. **Evaluation:**
139
+
140
+ The models were evaluated on the test set at the end of training in ONNX (CPU) and TensorRT (GPU - T4) formats. Performance metrics included precision, recall, mAP50, and mAP50-95.
141
+
142
+ ![Trials](./assets/trials.png)
143
+
144
+ #### Results Comparison:
145
+
146
+ | Metric | Base Model | Best Trial (#10) | Difference |
147
+ |------------|------------|-------------------|-------------|
148
+ | mAP50 | 87.47% | **95.75%** | +8.28% |
149
+ | mAP50-95 | 65.46% | **66.26%** | +0.81% |
150
+ | Precision | **97.23%** | 95.61% | -1.63% |
151
+ | Recall | 76.16% | **91.21%** | +15.05% |
152
+ | F1-score | 85.42% | **93.36%** | +7.94% |
153
+
154
+ ---
155
+
156
+ ## **Results**
157
+
158
+ After hyperparameter tuning of the YOLOv8s model, the best model achieved the following results on the test set:
159
+
160
+ - **Precision:** 94.74%
161
+ - **Recall:** 89.72%
162
+ - **mAP@50:** 94.50%
163
+ - **mAP@50-95:** 67.35%
164
+ - **Inference Time:**
165
+ - **ONNX Runtime (CPU):** 171.56 ms
166
+ - **TensorRT (GPU - T4):** 7.657 ms
167
+
168
+ ---
169
+
170
+ ## **How to Use**
171
+
172
+ The `YOLOv8s` model can be used via CLI or Python code using the [Ultralytics](https://github.com/ultralytics/ultralytics) library. Alternatively, it can be used directly with ONNX Runtime or TensorRT.
173
+
174
+ The final weights are available in the main directory of the repository:
175
+ - [`yolov8s.pt`](yolov8s.pt) (PyTorch format)
176
+ - [`yolov8s.onnx`](yolov8s.onnx) (ONNX format)
177
+ - [`yolov8s.engine`](yolov8s.engine) (TensorRT format)
178
+
179
+ ### Python Code
180
+
181
+ - Dependencies
182
+
183
+ ```bash
184
+ pip install ultralytics supervision huggingface_hub
185
+ ```
186
+
187
+ - Inference
188
+
189
+ ```python
190
+ import cv2
191
+ import supervision as sv
192
+
193
+ from huggingface_hub import hf_hub_download
194
+ from ultralytics import YOLO
195
+
196
+ model_path = hf_hub_download(
197
+ repo_id="tech4humans/yolov8s-signature-detector",
198
+ filename="yolov8s.pt"
199
+ )
200
+
201
+ model = YOLO(model_path)
202
+
203
+ image_path = "/path/to/your/image.jpg"
204
+ image = cv2.imread(image_path)
205
+
206
+ results = model(image_path)
207
+
208
+ detections = sv.Detections.from_ultralytics(results[0])
209
+
210
+ box_annotator = sv.BoxAnnotator()
211
+ annotated_image = box_annotator.annotate(scene=image, detections=detections)
212
+
213
+ cv2.imshow("Detections", annotated_image)
214
+ cv2.waitKey(0)
215
+ cv2.destroyAllWindows()
216
+ ```
217
+
218
+ Ensure the paths to the image and model files are correct.
219
+
220
+
221
+ ### CLI
222
+
223
+ - Dependencies
224
+
225
+ ```bash
226
+ pip install -U ultralytics "huggingface_hub[cli]"
227
+ ```
228
+
229
+ - Inference
230
+
231
+ ```bash
232
+ huggingface-cli download tech4humans/yolov8s-signature-detector yolov8s.pt
233
+ ```
234
+
235
+ ```bash
236
+ yolo predict model=yolov8s.pt source=caminho/para/imagem.jpg
237
+ ```
238
+
239
+ **Parameters**:
240
+ - `model`: Path to the model weights file.
241
+ - `source`: Path to the image or directory of images for detection.
242
+
243
+ ### ONNX Runtime
244
+
245
+ For optimized inference, you can find the inference code using [onnxruntime](https://onnxruntime.ai/docs/) and [OpenVINO Execution Provider](https://onnxruntime.ai/docs/execution-providers/OpenVINO-ExecutionProvider.html) in the [handler.py](handler.py) file and on the Hugging Face Space [here](https://huggingface.co/spaces/tech4humans/signature-detection).
246
+
247
+ ---
248
+
249
+ ## **Demo**
250
+
251
+ You can explore the model and test real-time inference in the Hugging Face Spaces demo, built with Gradio and ONNXRuntime.
252
+
253
+ [![Open in Spaces](https://huggingface.co/datasets/huggingface/badges/resolve/main/open-in-hf-spaces-md.svg)](https://huggingface.co/spaces/tech4humans/signature-detection)
254
+
255
+ ---
256
+
257
+ ## 🔗 **Inference with Triton Server**
258
+
259
+ If you want to deploy this signature detection model in a production environment, check out our inference server repository based on the NVIDIA Triton Inference Server.
260
+
261
+ <table>
262
+ <tr>
263
+ <td>
264
+ <a href="https://github.com/triton-inference-server/server"><img src="https://img.shields.io/badge/Triton-Inference%20Server-76B900?style=for-the-badge&labelColor=black&logo=nvidia" alt="Triton Badge" /></a>
265
+ </td>
266
+ <td>
267
+ <a href="https://github.com/tech4ai/t4ai-signature-detect-server"><img src="https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white" alt="GitHub Badge" /></a>
268
+ </td>
269
+ </tr>
270
+ </table>
271
+
272
+ ---
273
+
274
+ ## **Infrastructure**
275
+
276
+ ### Software
277
+
278
+ The model was trained and tuned using a Jupyter Notebook environment.
279
+
280
+ - **Operating System:** Ubuntu 22.04
281
+ - **Python:** 3.10.12
282
+ - **PyTorch:** 2.5.1+cu121
283
+ - **Ultralytics:** 8.3.58
284
+ - **Roboflow:** 1.1.50
285
+ - **Optuna:** 4.1.0
286
+ - **ONNX Runtime:** 1.20.1
287
+ - **TensorRT:** 10.7.0
288
+
289
+ ### Hardware
290
+
291
+ Training was performed on a Google Cloud Platform n1-standard-8 instance with the following specifications:
292
+
293
+ - **CPU:** 8 vCPUs
294
+ - **GPU:** NVIDIA Tesla T4
295
+
296
+ ---
297
+
298
+ ## **License**
299
+
300
+ ### Model Weights (Fine-Tuned Model) – **AGPL-3.0**
301
+ - **License:** GNU Affero General Public License v3.0 (AGPL-3.0)
302
+ - **Usage:** The fine-tuned model weights, derived from the YOLOv8 model by Ultralytics, are licensed under AGPL-3.0. This requires that any modifications or derivative works of these model weights also be distributed under AGPL-3.0, and if the model is used as part of a network service, the corresponding source must be made available.
303
+
304
+ ### Code, Training, Deployment, and Data – **Apache 2.0**
305
+ - **License:** Apache License 2.0
306
+ - **Usage:** All additional materials—including training scripts, deployment code, usage instructions, and associated data—are licensed under the Apache 2.0 license.
307
+
308
+ For more details, please refer to the full license texts:
309
+ - [GNU AGPL-3.0 License](https://www.gnu.org/licenses/agpl-3.0.html)
310
+ - [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0)
311
+
312
+ ---
313
+
314
+ ## **Contact and Information**
315
+
316
+ For further information, questions, or contributions, contact us at **iag@tech4h.com.br**.
317
+
318
+ <div align="center">
319
+ <p>
320
+ 📧 <b>Email:</b> <a href="mailto:iag@tech4h.com.br">iag@tech4h.com.br</a><br>
321
+ 🌐 <b>Website:</b> <a href="https://www.tech4.ai/">www.tech4.ai</a><br>
322
+ 💼 <b>LinkedIn:</b> <a href="https://www.linkedin.com/company/tech4humans-hyperautomation/">Tech4Humans</a>
323
+ </p>
324
+ </div>
325
+
326
+ ## **Author**
327
+
328
+ <div align="center">
329
+ <table>
330
+ <tr>
331
+ <td align="center" width="140">
332
+ <a href="https://huggingface.co/samuellimabraz">
333
+ <img src="https://avatars.githubusercontent.com/u/115582014?s=400&u=c149baf46c51fdee45ad5344cf1b360236d90d09&v=4" width="120" alt="Samuel Lima"/>
334
+ <h3>Samuel Lima</h3>
335
+ </a>
336
+ <p><i>AI Research Engineer</i></p>
337
+ <p>
338
+ <a href="https://huggingface.co/samuellimabraz">
339
+ <img src="https://img.shields.io/badge/🤗_HuggingFace-samuellimabraz-orange" alt="HuggingFace"/>
340
+ </a>
341
+ </p>
342
+ </td>
343
+ <td width="500">
344
+ <h4>Responsibilities in this Project</h4>
345
+ <ul>
346
+ <li>🔬 Model development and training</li>
347
+ <li>📊 Dataset analysis and processing</li>
348
+ <li>⚙️ Hyperparameter optimization and performance evaluation</li>
349
+ <li>📝 Technical documentation and model card</li>
350
+ </ul>
351
+ </td>
352
+ </tr>
353
+ </table>
354
+ </div>
355
+
356
+ ---
357
+
358
+ <div align="center">
359
+ <p>Developed with 💜 by <a href="https://www.tech4.ai/">Tech4Humans</a></p>
360
+ </div>