Views
No views yet
ai project practical/
│
├── app.py # ✅ NEW — Gradio UI for Hugging Face deployment
├── requirements.txt # ✅ NEW — All Python dependencies
├── README.md # ✅ NEW — This file
│
├── train.py # Train the YOLOv8 model
├── test.py # 🔧 FIXED — Test on a single image
├── webcam.py # 🔧 IMPROVED — Live webcam detection
│
├── yolov8n.pt # Base YOLOv8 nano weights (for training)
├── output.mp4 # Output video from testvideo.py
│
├── Data/
│ ├── data.yaml # Dataset config (classes, paths)
│ ├── indianroadbike.mp4 # Sample input video
│ ├── testvideo.py # 🔧 FIXED — Run detection on a video file
│ ├── train/images/ # Training images
│ ├── valid/images/ # Validation images
│ └── test/images/ # Test images (a.jpeg, aa.jpeg, ...)
│
└── runs/detect/train-2/
└── weights/
├── best.pt # ✅ Best trained model weights
└── last.pt # Last epoch weights| Class Name | Meaning |
|---|---|
driver_with_helmet | ✅ Driver wearing helmet |
passenger_with_helmet | ✅ Passenger wearing helmet |
driver_without_helmet | ❌ Driver NOT wearing helmet |
passenger_without_helmet | ❌ Passenger NOT wearing helmet |
driver | Rider (helmet status unknown) |
passenger | Pillion (helmet status unknown) |
bike | The bike itself |
test.py — Critical Logic Bug Fixed1# OLD (WRONG) — used low confidence as a "no helmet" signal
2if "helmet" in label.lower():
3 if conf < 0.40:
4 no_helmet = True # ❌ This is NOT how you detect "no helmet"
5 else:
6 helmet = Truedriver_without_helmet and passenger_without_helmet.
Using low confidence to decide "no helmet" is completely incorrect — confidence just tells you
how sure the model is about what it sees, not what it sees.1# NEW (CORRECT) — check the class name directly
2if "without_helmet" in label.lower():
3 no_helmet = True
4elif "helmet" in label.lower():
5 helmet = TrueMODEL_PATH, IMAGE_PATH, CONF_THRESHOLD constants at top (easier to change)conf=CONF_THRESHOLD to model call (filters weak detections at source)no_helmet now takes priority over helmet in final output (safety first)webcam.py — Minor ImprovementsMODEL_PATH constant instead of hardcoded string0.25 → 0.35 (reduces false positives)show_conf=True (displays confidence score on screen)stream=True (memory-efficient for continuous live frames)Data/testvideo.py — Path & Robustness FixesMODEL_PATH, VIDEO_PATH, OUTPUT_PATH, CONF_THRESHOLD constantscap.get(3) / cap.get(4) → proper constants CAP_PROP_FRAME_WIDTH / CAP_PROP_FRAME_HEIGHTfps or 25 fallback (some cameras/files return 0 FPS — this prevents a crash)os.path.exists() check — raises a clear error if video file is missingverbose=False to model call — stops spammy per-frame console outputData/ folderapp.py — NEW File for Hugging Face✅ HELMET or ❌ NO HELMET87.3%)requirements.txt — NEW Fileultralytics>=8.0.0
torch>=2.0.0
torchvision>=0.15.0
opencv-python-headless>=4.8.0
Pillow>=10.0.0
numpy>=1.24.0
gradio>=4.0.0opencv-python-headless (no display/GUI required — works on servers).1# From project root
2python test.pypython webcam.py1# From project root (not from inside Data/)
2python Data/testvideo.py1python app.py
2# Opens at http://127.0.0.1:7860runs/detect/train-2/weights/best.pt → copy to → best.pt (project root)app.pybest.ptrequirements.txt| Setting | Value |
|---|---|
| Base model | YOLOv8n (nano) |
| Epochs | 20 |
| Image size | 416×416 |
| Batch size | 16 |
| Device | CPU |
| Optimizer | Auto |
| Dataset classes | 7 |
train.py lives)runs/detect/train-2/weights/best.ptbest.pt to the project roottestvideo.py is inside Data/ but still uses paths relative to the project root