Instructions to use star092304/traffic-sign-detection-vietnam-yolo with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use star092304/traffic-sign-detection-vietnam-yolo with ultralytics:
# Couldn't find a valid YOLO version tag. # Replace XX with the correct version. from ultralytics import YOLOvXX model = YOLOvXX.from_pretrained("star092304/traffic-sign-detection-vietnam-yolo") source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - Notebooks
- Google Colab
- Kaggle
Upload 14 files
Browse files- README.md +79 -18
- evalution/benchmark.json +9 -0
- evalution/confusion_matrix.png +3 -0
- evalution/metrics.json +7 -0
- evalution/per_class_metrics_test.csv +83 -0
- evalution/per_class_pr.png +3 -0
- evalution/summary.json +17 -0
- inference/infer_for_colab.ipynb +0 -0
- inference/infer_local.py +129 -0
- inference/random_predictions.png +3 -0
- inference/val_tp_fp_fn.png +3 -0
- training/results.png +3 -0
- training/traffic-sign-yolo11s.ipynb +0 -0
- training/training_curves.png +3 -0
README.md
CHANGED
|
@@ -8,36 +8,97 @@ tags:
|
|
| 8 |
- yolo11s
|
| 9 |
library_name: ultralytics
|
| 10 |
license: apache-2.0
|
|
|
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
-
# 🚦 Traffic Sign Detection — Vietnam
|
| 14 |
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
| Metric | Value |
|
| 20 |
|--------|-------|
|
| 21 |
-
|
|
| 22 |
-
|
|
| 23 |
-
|
|
| 24 |
-
|
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
```python
|
| 30 |
from ultralytics import YOLO
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
results[0].show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
```
|
| 35 |
|
| 36 |
-
##
|
| 37 |
-
82 traffic sign categories for Vietnam road conditions.
|
| 38 |
|
| 39 |
-
|
| 40 |
-
-
|
| 41 |
-
-
|
| 42 |
-
-
|
| 43 |
-
-
|
|
|
|
| 8 |
- yolo11s
|
| 9 |
library_name: ultralytics
|
| 10 |
license: apache-2.0
|
| 11 |
+
datasets:
|
| 12 |
+
- traffic-sign-detection-vietnam
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# 🚦 Traffic Sign Detection — Vietnam (YOLO11s)
|
| 16 |
|
| 17 |
+
[](https://github.com/ultralytics/ultralytics)
|
| 18 |
+
[](https://huggingface.co/datasets/star092304/Traffic-sign-detection-VietNam)
|
| 19 |
|
| 20 |
+
YOLO11s model trained on the Vietnam Traffic Sign Detection dataset.
|
| 21 |
+
|
| 22 |
+
| Property | Value |
|
| 23 |
+
|----------|-------|
|
| 24 |
+
| Model | YOLO11s |
|
| 25 |
+
| Classes | 82 Vietnamese traffic signs |
|
| 26 |
+
| Image size | 640×640 |
|
| 27 |
+
| Framework | Ultralytics |
|
| 28 |
+
| Dataset Source | [Hugging Face](https://huggingface.co/datasets/star092304/Traffic-sign-detection-VietNam) |
|
| 29 |
+
|
| 30 |
+
## Evaluation Results
|
| 31 |
+
|
| 32 |
+
Below is the summary of the evaluation results from `evalution/summary.json`:
|
| 33 |
|
| 34 |
| Metric | Value |
|
| 35 |
|--------|-------|
|
| 36 |
+
| **Model** | `yolo11s.pt` |
|
| 37 |
+
| **Epochs Trained** | 50 |
|
| 38 |
+
| **Number of Classes** | 82 |
|
| 39 |
+
| **Device** | GPU |
|
| 40 |
+
| **Precision** | 96.42% (`0.9642`) |
|
| 41 |
+
| **Recall** | 96.15% (`0.9615`) |
|
| 42 |
+
| **mAP50** | 98.06% (`0.9806`) |
|
| 43 |
+
| **mAP75** | 93.37% (`0.9337`) |
|
| 44 |
+
| **mAP50-95** | 83.57% (`0.8357`) |
|
| 45 |
+
| **FPS** | 61.5 |
|
| 46 |
+
| **Mean Latency** | 16.25 ms |
|
| 47 |
+
| **p50 Latency** | 15.03 ms |
|
| 48 |
+
| **p95 Latency** | 22.59 ms |
|
| 49 |
+
| **Min Latency** | 13.44 ms |
|
| 50 |
+
| **Max Latency** | 23.24 ms |
|
| 51 |
+
|
| 52 |
+
## Visualizations
|
| 53 |
+
|
| 54 |
+
### Training Curves
|
| 55 |
+

|
| 56 |
+
|
| 57 |
+
### Results
|
| 58 |
+

|
| 59 |
+
|
| 60 |
+
### Random Predictions (Inference)
|
| 61 |
+

|
| 62 |
|
| 63 |
+
## Files
|
| 64 |
+
|
| 65 |
+
| File | Description |
|
| 66 |
+
|------|-------------|
|
| 67 |
+
| `best.pt` | PyTorch weights (main model) |
|
| 68 |
+
| `best.onnx` | ONNX export (CPU/edge deploy) |
|
| 69 |
+
| `data.yaml` | Dataset config with class names |
|
| 70 |
+
| `config.json` | Training hyperparameters |
|
| 71 |
+
| `metrics.json` | Test-set evaluation results |
|
| 72 |
+
| `benchmark.json` | FPS / latency results |
|
| 73 |
+
| `summary.json` | All metrics combined |
|
| 74 |
+
|
| 75 |
+
## Quick Start
|
| 76 |
|
| 77 |
```python
|
| 78 |
from ultralytics import YOLO
|
| 79 |
+
|
| 80 |
+
# PyTorch
|
| 81 |
+
model = YOLO("best.pt")
|
| 82 |
+
results = model("image.jpg", conf=0.25)
|
| 83 |
results[0].show()
|
| 84 |
+
|
| 85 |
+
# ONNX (faster on CPU)
|
| 86 |
+
model_onnx = YOLO("best.onnx")
|
| 87 |
+
results = model_onnx("image.jpg")
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
## CLI Inference
|
| 91 |
+
|
| 92 |
+
```bash
|
| 93 |
+
python infer.py --source image.jpg
|
| 94 |
+
python infer.py --source video.mp4 --save
|
| 95 |
+
python infer.py --source 0 --show # webcam
|
| 96 |
```
|
| 97 |
|
| 98 |
+
## Training Details
|
|
|
|
| 99 |
|
| 100 |
+
- **Base model**: yolo11s.pt (pretrained COCO)
|
| 101 |
+
- **Early stopping**: patience=20
|
| 102 |
+
- **Dataset cache**: enabled (faster I/O)
|
| 103 |
+
- **Seed**: 42 (reproducible)
|
| 104 |
+
- **Optimizer**: auto (AdamW)
|
evalution/benchmark.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"mean_latency_ms": 16.25,
|
| 3 |
+
"p50_latency_ms": 15.03,
|
| 4 |
+
"p95_latency_ms": 22.59,
|
| 5 |
+
"min_latency_ms": 13.44,
|
| 6 |
+
"max_latency_ms": 23.24,
|
| 7 |
+
"fps": 61.5,
|
| 8 |
+
"device": "GPU"
|
| 9 |
+
}
|
evalution/confusion_matrix.png
ADDED
|
Git LFS Details
|
evalution/metrics.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"mAP50": 0.9805747962455071,
|
| 3 |
+
"mAP50_95": 0.8356933876101033,
|
| 4 |
+
"mAP75": 0.9337388412187322,
|
| 5 |
+
"precision": 0.964222944759273,
|
| 6 |
+
"recall": 0.9614566153284894
|
| 7 |
+
}
|
evalution/per_class_metrics_test.csv
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class,precision,recall,ap50
|
| 2 |
+
Low Clearance,0.9900201157335413,1.0,0.995
|
| 3 |
+
No Trucks and Bus,1.0,0.9850546469510434,0.995
|
| 4 |
+
No Left Turn,0.9865452139078744,1.0,0.995
|
| 5 |
+
No Horns,0.9576904085232468,1.0,0.995
|
| 6 |
+
Danger,0.9879077354665579,1.0,0.995
|
| 7 |
+
No Cars,0.9850916160496327,1.0,0.995
|
| 8 |
+
Double curve first to right,0.9859768977459309,1.0,0.995
|
| 9 |
+
No Moto,0.9507722372175216,1.0,0.995
|
| 10 |
+
Road with Surveillance Camera,0.8743140903719894,1.0,0.995
|
| 11 |
+
Obstacle on the Road,1.0,0.905884424847886,0.995
|
| 12 |
+
Lane Allocation,0.9908375001914379,1.0,0.995
|
| 13 |
+
Sharp Right Turn,0.9193752700402034,1.0,0.995
|
| 14 |
+
Intersection with a Minor Road,1.0,0.9916006767002455,0.995
|
| 15 |
+
Intersection with Equal Roads,0.9978528486386194,1.0,0.995
|
| 16 |
+
Intersection with a Priority Road,0.9712350750376608,1.0,0.995
|
| 17 |
+
No Straight and Right Turn,0.9638621972390922,1.0,0.995
|
| 18 |
+
Traffic light ahead,0.8869606369280012,1.0,0.995
|
| 19 |
+
No U-Turn and No Left Turn,0.9789871401989048,1.0,0.995
|
| 20 |
+
End of 50km/h speed limit,0.9802774078441459,1.0,0.995
|
| 21 |
+
sparsely populated area,0.9729635140617088,1.0,0.995
|
| 22 |
+
Slippery Road,0.955235716202147,1.0,0.995
|
| 23 |
+
Uneven road,0.9092611371922793,1.0,0.995
|
| 24 |
+
Steep ascent,0.9794949177980316,1.0,0.995
|
| 25 |
+
No left turn for cars,0.9837367908670516,1.0,0.995
|
| 26 |
+
No Parking on Even Days,0.9637730802776739,1.0,0.995
|
| 27 |
+
No Left or Right Turn,0.9883674415684336,1.0,0.995
|
| 28 |
+
Pedestrian Lane,0.947527671534424,1.0,0.995
|
| 29 |
+
No Motobike Left Turn,0.953364060077053,1.0,0.995
|
| 30 |
+
No bus,0.9527315374075699,1.0,0.995
|
| 31 |
+
No Overtaking,0.9679110133888323,1.0,0.995
|
| 32 |
+
Children Crossing,0.988352038941514,1.0,0.995
|
| 33 |
+
Narrow road both sides,0.946315305789602,1.0,0.995
|
| 34 |
+
Narrow Road Right Side,0.9829978478935989,1.0,0.995
|
| 35 |
+
Narrow Road Left Side,0.9607601156068228,1.0,0.995
|
| 36 |
+
Keep left,0.985278824607956,1.0,0.995
|
| 37 |
+
End of all prohibition,0.9740146516172447,1.0,0.995
|
| 38 |
+
No U-Turn for Cars,0.8858557525212286,1.0,0.995
|
| 39 |
+
Level Crossing with Barriers,1.0,0.9313327581927153,0.995
|
| 40 |
+
No U-Turn and Left Turn for Cars,0.9302647395645418,1.0,0.995
|
| 41 |
+
Narrow bridge,0.9758132364033345,1.0,0.995
|
| 42 |
+
Stop,0.9725653895150188,1.0,0.995
|
| 43 |
+
U-Turn Area,0.9944662320261956,1.0,0.995
|
| 44 |
+
Speed limit 100km/h,0.9745238351976454,1.0,0.995
|
| 45 |
+
Speed limit 110km/h,0.9741028723376567,1.0,0.995
|
| 46 |
+
Speed limit 120km/h,0.9205756957498799,1.0,0.995
|
| 47 |
+
Speed limit 90km/h,1.0,0.8172760587020905,0.995
|
| 48 |
+
Roundabout,0.9880233147700539,1.0,0.995
|
| 49 |
+
Turn Right,0.9395931640615742,1.0,0.995
|
| 50 |
+
Turn Left,0.983730793325145,1.0,0.995
|
| 51 |
+
Road Work Ahead,0.9496755252994297,1.0,0.995
|
| 52 |
+
Hospital,0.9807015621273367,1.0,0.995
|
| 53 |
+
Parking,0.9535981311686142,1.0,0.995
|
| 54 |
+
No Parking on Odd Days,0.976600523189776,1.0,0.995
|
| 55 |
+
No Stopping & No Parking,0.9919736228102467,0.9868421052631579,0.9948051948051947
|
| 56 |
+
No Two or Three-wheeled Vehicles,1.0,0.9726513082883271,0.9942000000000001
|
| 57 |
+
Speed limit 80km/h,0.9488388275467288,1.0,0.9940243902439024
|
| 58 |
+
No Right Turn,0.9700964150830149,0.9411764705882353,0.9930065359477124
|
| 59 |
+
No Trucks,0.9742164412587491,0.9615384615384616,0.9918838288003374
|
| 60 |
+
Height Limit,0.9731698070359129,0.9642857142857143,0.9904545454545456
|
| 61 |
+
Accident area,0.933089420398414,1.0,0.9892105263157894
|
| 62 |
+
Speed limit 10km/h,0.9477264927429047,0.9,0.985909090909091
|
| 63 |
+
Pedestrian Crossing,1.0,0.9450610873861024,0.985
|
| 64 |
+
No Parking,0.9899759476073186,0.978494623655914,0.9846842105263157
|
| 65 |
+
Slow Down,0.969269324416295,0.9841269841269841,0.9837301587301587
|
| 66 |
+
Speed limit 40km/h,1.0,0.8845621142739079,0.9819442967362624
|
| 67 |
+
Sharp Left Turn,0.9411159594628086,0.9259259259259259,0.9817369727047145
|
| 68 |
+
Speed limit 20km/h,1.0,0.8741236122229261,0.9811538461538463
|
| 69 |
+
Speed limit 60km/h,0.9708657751325349,0.9387480064919294,0.9811391248697522
|
| 70 |
+
Speed limit 70km/h,0.9340237201000852,0.8332760484717904,0.9784173669467788
|
| 71 |
+
Dual carriageway,0.9491643245781851,0.983286491563703,0.9770000000000001
|
| 72 |
+
No Entry,0.9833202557287564,0.8544015257941685,0.965110483403822
|
| 73 |
+
No U-Turn,0.9638881708382964,0.967741935483871,0.965
|
| 74 |
+
Bus Stop,0.9635511195931211,0.9444516575857006,0.9535714285714283
|
| 75 |
+
Turn Right Only,0.9698898062735045,0.7936507936507936,0.9416035081665655
|
| 76 |
+
One way street,0.9286031948005872,0.92,0.9414367816091955
|
| 77 |
+
Green Light,0.9375582592006058,0.7766495726426715,0.924665723373578
|
| 78 |
+
Speed Bump,0.9733887965476249,0.8666666666666667,0.916578947368421
|
| 79 |
+
Speed limit 30km/h,0.9330278899269068,0.9166666666666666,0.915
|
| 80 |
+
Residential area,0.9703748843314238,0.9166666666666666,0.915
|
| 81 |
+
No U-Turn and No Right Turn,0.9085002818929591,0.9090909090909091,0.905
|
| 82 |
+
Speed limit 50km/h,1.0,0.6954774938108672,0.8478196930946291
|
| 83 |
+
Red Light,0.820769909729665,0.5727310494000819,0.7130466373995354
|
evalution/per_class_pr.png
ADDED
|
Git LFS Details
|
evalution/summary.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"mAP50": 0.9805747962455071,
|
| 3 |
+
"mAP50_95": 0.8356933876101033,
|
| 4 |
+
"mAP75": 0.9337388412187322,
|
| 5 |
+
"precision": 0.964222944759273,
|
| 6 |
+
"recall": 0.9614566153284894,
|
| 7 |
+
"mean_latency_ms": 16.25,
|
| 8 |
+
"p50_latency_ms": 15.03,
|
| 9 |
+
"p95_latency_ms": 22.59,
|
| 10 |
+
"min_latency_ms": 13.44,
|
| 11 |
+
"max_latency_ms": 23.24,
|
| 12 |
+
"fps": 61.5,
|
| 13 |
+
"device": "GPU",
|
| 14 |
+
"num_classes": 82,
|
| 15 |
+
"model": "yolo11s.pt",
|
| 16 |
+
"epochs_trained": 50
|
| 17 |
+
}
|
inference/infer_for_colab.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
inference/infer_local.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Traffic Sign Detection — Inference CLI (Local & Hugging Face integrated)
|
| 3 |
+
Usage:
|
| 4 |
+
python infer.py --source image.jpg
|
| 5 |
+
python infer.py --source test.mp4 --save
|
| 6 |
+
python infer.py --source 0 # webcam
|
| 7 |
+
python infer.py --source images/ --save
|
| 8 |
+
|
| 9 |
+
# Custom local weights path:
|
| 10 |
+
python infer.py --source image.jpg --weights outputs/best.pt
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import argparse
|
| 14 |
+
import time
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
import torch
|
| 18 |
+
import numpy as np
|
| 19 |
+
from ultralytics import YOLO
|
| 20 |
+
from huggingface_hub import hf_hub_download
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def parse_args():
|
| 24 |
+
p = argparse.ArgumentParser(description="Traffic Sign Inference CLI")
|
| 25 |
+
p.add_argument(
|
| 26 |
+
"--source", required=True, help="Image/video path, folder, or 0 for webcam"
|
| 27 |
+
)
|
| 28 |
+
p.add_argument(
|
| 29 |
+
"--weights",
|
| 30 |
+
default="best.pt",
|
| 31 |
+
help="Path to model weights (.pt or .onnx) or filename on Hugging Face repo",
|
| 32 |
+
)
|
| 33 |
+
p.add_argument("--conf", type=float, default=0.25, help="Confidence threshold")
|
| 34 |
+
p.add_argument("--iou", type=float, default=0.45, help="IoU threshold for NMS")
|
| 35 |
+
p.add_argument("--imgsz", type=int, default=640, help="Inference image size")
|
| 36 |
+
p.add_argument("--save", action="store_true", help="Save output images/video")
|
| 37 |
+
p.add_argument(
|
| 38 |
+
"--show", action="store_true", help="Display results inside an OpenCV window"
|
| 39 |
+
)
|
| 40 |
+
p.add_argument(
|
| 41 |
+
"--out_dir", default="outputs/infer", help="Output directory for saved results"
|
| 42 |
+
)
|
| 43 |
+
return p.parse_args()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def main():
|
| 47 |
+
args = parse_args()
|
| 48 |
+
|
| 49 |
+
# 1. Check weights path. If not found locally, download from Hugging Face repository
|
| 50 |
+
weights_path = Path(args.weights)
|
| 51 |
+
if not weights_path.exists():
|
| 52 |
+
repo_id = "star092304/traffic-sign-detection-vietnam-yolo"
|
| 53 |
+
filename = weights_path.name # Expecting 'best.pt' or specific weight filename
|
| 54 |
+
print(f"Local weights '{args.weights}' not found.")
|
| 55 |
+
print(f"Downloading from Hugging Face repository: {repo_id}...")
|
| 56 |
+
try:
|
| 57 |
+
downloaded_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 58 |
+
args.weights = downloaded_path
|
| 59 |
+
print(f"Successfully downloaded weights to local cache: {downloaded_path}")
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print(f"Error downloading from Hugging Face: {e}")
|
| 62 |
+
print(
|
| 63 |
+
"Please ensure your internet connection or provide a valid local path to --weights."
|
| 64 |
+
)
|
| 65 |
+
return
|
| 66 |
+
|
| 67 |
+
# 2. Load the YOLO model
|
| 68 |
+
print(f"Loading model: {args.weights}")
|
| 69 |
+
model = YOLO(args.weights)
|
| 70 |
+
|
| 71 |
+
# 3. Model GPU Warm-up (highly recommended for local inference speed benchmarks)
|
| 72 |
+
if torch.cuda.is_available():
|
| 73 |
+
dummy = np.zeros((args.imgsz, args.imgsz, 3), dtype="uint8")
|
| 74 |
+
model(dummy, verbose=False)
|
| 75 |
+
print("GPU Warm-up complete.")
|
| 76 |
+
|
| 77 |
+
# 4. Handle webcam source input mapping (convert '0' string to int 0)
|
| 78 |
+
source_input = args.source
|
| 79 |
+
if source_input.isdigit():
|
| 80 |
+
source_input = int(source_input)
|
| 81 |
+
|
| 82 |
+
# 5. Run inference pipeline
|
| 83 |
+
print(f"Running inference on: {args.source}")
|
| 84 |
+
t0 = time.perf_counter()
|
| 85 |
+
|
| 86 |
+
results = model.predict(
|
| 87 |
+
source=source_input,
|
| 88 |
+
conf=args.conf,
|
| 89 |
+
iou=args.iou,
|
| 90 |
+
imgsz=args.imgsz,
|
| 91 |
+
save=args.save,
|
| 92 |
+
show=args.show,
|
| 93 |
+
project=args.out_dir,
|
| 94 |
+
name="run",
|
| 95 |
+
exist_ok=True,
|
| 96 |
+
verbose=True,
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
elapsed = time.perf_counter() - t0
|
| 100 |
+
|
| 101 |
+
# Calculate performance metrics
|
| 102 |
+
# In case of webcam or video stream, results length corresponds to the total processed frames
|
| 103 |
+
n = len(results) if isinstance(results, list) else 1
|
| 104 |
+
fps = n / elapsed if elapsed > 0 else 0
|
| 105 |
+
|
| 106 |
+
print(f"\n{'='*40}")
|
| 107 |
+
print(f"Processed : {n} frame(s)")
|
| 108 |
+
print(f"Time : {elapsed:.2f}s")
|
| 109 |
+
print(f"FPS : {fps:.1f}")
|
| 110 |
+
if args.save:
|
| 111 |
+
print(f"Saved to : {args.out_dir}/run/")
|
| 112 |
+
|
| 113 |
+
# 6. Print detections for a single frame evaluation
|
| 114 |
+
if n == 1 and hasattr(results[0], "boxes"):
|
| 115 |
+
boxes = results[0].boxes
|
| 116 |
+
if boxes is not None and len(boxes) > 0:
|
| 117 |
+
names = model.names
|
| 118 |
+
print(f"\nDetections ({len(boxes)}):")
|
| 119 |
+
for box in boxes:
|
| 120 |
+
cls = int(box.cls.item())
|
| 121 |
+
conf = float(box.conf.item())
|
| 122 |
+
xyxy = box.xyxy[0].cpu().numpy().astype(int)
|
| 123 |
+
print(f" [{conf:.2f}] {names[cls]:35s} box={xyxy}")
|
| 124 |
+
else:
|
| 125 |
+
print("\nNo detections found.")
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
if __name__ == "__main__":
|
| 129 |
+
main()
|
inference/random_predictions.png
ADDED
|
Git LFS Details
|
inference/val_tp_fp_fn.png
ADDED
|
Git LFS Details
|
training/results.png
ADDED
|
Git LFS Details
|
training/traffic-sign-yolo11s.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
training/training_curves.png
ADDED
|
Git LFS Details
|