| title | KnightSight EdgeVision ANPR |
|---|---|
| emoji | π |
| colorFrom | blue |
| colorTo | green |
| sdk | streamlit |
| sdk_version | 1.32.0 |
| app_file | app.py |
| pinned | false |
| license | mit |
Automatic Number Plate Recognition Β· Edge-Optimized Β· Real-Time Inference
- Overview
- Live Demo
- Key Features
- Pipeline Architecture
- Model Performance
- Tech Stack
- Project Structure
- Getting Started
- Usage
- Training
- ONNX Export
- Creating Submissions
- Deployment
- Configuration
- Technical Deep Dive
- Future Roadmap
- Contributing
- License
- Acknowledgements
KnightSight EdgeVision is a high-accuracy, edge-optimized Automatic Number Plate Recognition (ANPR) system built for the KnightSight EdgeVision Challenge. It implements a two-stage detection pipeline β first detecting vehicles in a scene, then localizing license plates within each vehicle ROI, and finally performing OCR to extract the plate text.
The system achieves 99.49% mAP@50 with a lightweight 2.6M parameter model, making it suitable for real-time edge deployment while maintaining near-perfect detection accuracy.
Try it live on Hugging Face Spaces:
π https://huggingface.co/spaces/Gyaanendra/deepsight-sapiens
Upload any vehicle image or video and get instant plate detection + OCR results.
| Feature | Description |
|---|---|
| π Two-Stage Detection | Vehicle detection (COCO YOLOv11n) β Plate detection (custom fine-tuned YOLOv11n) |
| π€ Dual OCR Engines | Fast-Plate-OCR (~5ms) + GPT-4o-mini via OpenRouter as a fallback |
| π Night Vision | CLAHE contrast enhancement in LAB colorspace for low-light scenarios |
| β‘ ONNX Optimized | Export to ONNX for cross-platform edge inference (~6ms per frame) |
| π¬ Video Inference | Frame-by-frame video processing with configurable sample rate |
| π₯ GPU Acceleration | Automatic CUDA detection with seamless CPU fallback |
| π Smart Fallback | If no vehicle is detected, runs plate detection on the full frame |
| π Real-Time Metrics | Live inference time, vehicle count, and plate count displayed in-dashboard |
Input Image / Video Frame
β
βΌ
βββββββββββββββββββββββββββ
β Vehicle Detector β YOLOv11n (COCO pre-trained)
β conf β₯ 0.30 β Classes: car, motorcycle, bus, truck
ββββββββββββ¬βββββββββββββββ
β vehicle crops (ROIs)
βΌ
βββββββββββββββββββββββββββ
β Plate Detector β Custom fine-tuned YOLOv11n
β conf β₯ 0.40 β (ONNX or PyTorch selectable)
ββββββββββββ¬βββββββββββββββ
β plate bounding boxes
βΌ
βββββββββββββββββββββββββββ
β Preprocessing β Crop + Padding (Β±15px)
β + CLAHE (optional) β Bilateral filter denoising
β + 4Γ Lanczos Upscale β Enhances small plate readability
ββββββββββββ¬βββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββ
β OCR Engine β Fast-Plate-OCR (~5ms, default)
β β GPT-4o-mini (fallback via API)
ββββββββββββ¬βββββββββββββββ
β
βΌ
Plate Text + Confidence Score
π Fallback: If no vehicles detected β plate detector runs on full frame
π Submission fallback: 90Β° rotation if no plates found in original orientation
Why two-stage?
- Reduces false positives (shop signs, road boards that resemble plates)
- Improves plate detector accuracy by providing focused, smaller ROIs
- Reduces effective detection area by ~60β80% β faster inference per frame
| Metric | Value |
|---|---|
| mAP@50 | 99.49% |
| mAP@50-95 | 72.91% |
| Precision | 99.90% |
| Recall | 99.45% |
| F1 Score | 99.67% |
| Val Box Loss | 1.333 |
| Val Cls Loss | 0.707 |
| Model | Params | mAP@50 | mAP@50-95 |
|---|---|---|---|
| YOLOv8n COCO general | β | ~37% | ~18% |
| Typical LP detector (academic) | β | 92β96% | 55β65% |
| YOLOv8m fine-tuned LP | 25M | ~97% | ~68% |
| KnightSight (ours) | 2.6M | 99.49% | 72.91% |
Our 2.6M parameter nano model outperforms a 25M parameter medium model on both metrics.
| Property | Value |
|---|---|
| Architecture | YOLOv11n (anchor-free, single-class) |
| Parameters | ~2.6M |
| Model Size | 5.3 MB (PT) / 10.5 MB (ONNX) |
| Input Resolution | 480 Γ 480 px |
| Training | 20 epochs Β· batch=32 Β· RTX 4060 |
| Optimizer | AdamW + cosine LR decay |
| Inference Speed | ~8ms (PT) / ~6ms (ONNX) on RTX 4060 |
| Component | Technology |
|---|---|
| Detection | Ultralytics YOLOv11 |
| OCR (Primary) | Fast-Plate-OCR (cct-s-v2-global-model) |
| OCR (Fallback) | GPT-4o-mini via OpenRouter API |
| Framework | PyTorch + ONNX Runtime |
| Image Processing | OpenCV (CLAHE, bilateral filter, Lanczos upscale) |
| Frontend | Streamlit |
| GPU Support | CUDA (auto-detected) |
| Environment | python-dotenv for API key management |
deepsight/
βββ app.py # π― Streamlit inference dashboard (main entry point)
βββ create_submission.py # π¦ Generate competition submission JSONs
βββ visualize_predictions.py # π Visualize model predictions on test images
β
βββ models/ # π§ Model weights
β βββ best.pt # Fine-tuned plate detector (PyTorch)
β βββ best.onnx # Fine-tuned plate detector (ONNX export)
β βββ best_lprnet.pth # LPRNet weights (experimental)
β βββ yolo11n.pt # Vehicle detector (COCO pre-trained)
β βββ yolo26n.pt # YOLOv26n weights (experimental)
β
βββ configs/
β βββ knight_sight.yaml # π Dataset & training configuration
β
βββ scripts/
β βββ export_onnx.py # π Export PyTorch β ONNX
β βββ aug.py # πΌοΈ Data augmentation utilities
β βββ plot_results.py # π Plot training metrics
β βββ inspect_fast_plate_api.py # π Fast-Plate-OCR API inspector
β
βββ notebooks/
β βββ train.ipynb # ποΈ Model training notebook
β βββ aug.ipynb # πΌοΈ Augmentation research notebook
β βββ deepsightchallenge-dataset-checkout.ipynb # π Dataset exploration
β
βββ src/ # π§© Source modules
β βββ License_Plate_Recognition/
β βββ object_detection/
β βββ semantic_segmentation/
β
βββ tests/
β βββ test_box.py # β
Bounding box unit tests
β βββ test_inference_ocr.py # β
OCR inference tests
β
βββ docs/
β βββ visualizations/
β β βββ training_metrics.png # π Training curves visualization
β βββ KnightSight_EdgeVision_Challenge_FINAL.pdf # π Challenge documentation
β
βββ runs/detect/ # π Training outputs, metrics, and weights
βββ explain.md # π Full technical report (loss functions, architecture, etc.)
β
βββ requirements.txt # π¦ Python dependencies
βββ packages.txt # π¦ System-level apt packages (for HF Spaces)
βββ .env # π API keys (not committed)
βββ .gitignore # π« Git ignore rules
βββ .gitattributes # π Git LFS tracking (*.pt, *.onnx, *.pth, etc.)
βββ run.bat # π₯οΈ Windows launch script
βββ run_plot.bat # π Windows plot metrics script
- Python 3.9+
- CUDA 11.8+ (optional, for GPU acceleration)
- Git LFS (required β model weights are tracked via LFS)
git lfs install
git clone https://github.com/Gyaanendra/deepsight-sapiens.git
cd deepsight-sapiens# Using conda
conda create -n knightsight python=3.11 -y
conda activate knightsight
# Or using venv
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windowspip install -r requirements.txtFor GPU support, install the CUDA-compatible PyTorch build:
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu121
Create a .env file in the project root for the GPT-4o-mini OCR fallback:
OPENROUTER_API_KEY=sk-or-v1-your-key-hereThe app works fully without this β Fast-Plate-OCR is the default OCR engine. The OpenRouter key only enables the GPT-4o-mini fallback option in the sidebar.
streamlit run app.pyOr on Windows, double-click run.bat.
- Open the dashboard at
http://localhost:8501 - Select your preferred Plate Model Engine (ONNX or PyTorch) in the sidebar
- Choose an OCR Engine (Fast-Plate-OCR or Fallback Model)
- Adjust the Plate Confidence threshold (default: 0.40)
- Toggle Night Vision (CLAHE) for low-light images
- Upload an image via the π· Image Inference tab
- View annotated results with detected plates and OCR text
- Switch to the π¬ Video Inference tab
- Upload a video file (MP4, AVI, MOV, MKV)
- Set the frame sampling rate (process every N frames)
- Click
βΆοΈ Run Video Inference - Watch live annotated frames with real-time metrics
- Review all detected plates in the expandable summary panel
| Control | Description | Default |
|---|---|---|
| Plate Model Engine | ONNX (faster) or PyTorch (original) | ONNX |
| OCR Engine | Fast-Plate-OCR or GPT-4o-mini Fallback | Fast-Plate-OCR |
| Plate Confidence | Detection threshold (0.10 β 1.00) | 0.40 |
| Night Vision | CLAHE contrast enhancement | Off |
- Classes: 1 (
license_plate) - Split: Scene-based (no data leakage between train/val)
- Format: YOLO
.txtlabels (normalizedx_center y_center width height)
model: yolo11n.pt # nano β 2.6M params, COCO pre-trained
epochs: 20
batch: 32
imgsz: 480 # input resolution
optimizer: auto # AdamW auto-selected
lr0: 0.01 # initial LR
lrf: 0.01 # final LR = lr0 Γ lrf
warmup_epochs: 3.0 # cosine warmup
amp: true # mixed precision FP16| Augmentation | Value | Purpose |
|---|---|---|
| HSV Hue/Sat/Val | 0.015 / 0.7 / 0.4 | Lighting & weather variation |
| Horizontal Flip | 50% | Doubles effective dataset |
| Translate | 0.1 | Off-center plates |
| Scale | 0.5 | Distance variation |
| Mosaic | 1.0 | Partial plate learning |
| Random Erasing | 0.4 | Occlusion simulation |
| RandAugment | auto | Photometric diversity |
| Close Mosaic | Last 10 epochs | Stabilize fine-tuning |
L_total = 10.0 Γ L_box(CIoU) + 1.0 Γ L_cls(BCE) + 1.5 Γ L_dfl
- Box Loss (CIoU) β Weighted 10Γ because precise plate localization is critical for OCR
- Classification Loss (BCE) β Single-class plate vs. background
- Distribution Focal Loss β Allows uncertainty-aware boundary predictions
# Open the training notebook
jupyter notebook notebooks/train.ipynbOr train via CLI:
yolo detect train \
model=yolo11n.pt \
data=configs/knight_sight.yaml \
epochs=20 \
batch=32 \
imgsz=480 \
device=0Export the trained model to ONNX for optimized cross-platform inference:
python scripts/export_onnx.pyOr directly:
from ultralytics import YOLO
model = YOLO("models/best.pt")
model.export(format="onnx", simplify=True)| Aspect | PyTorch (.pt) | ONNX (.onnx) |
|---|---|---|
| File Size | 5.3 MB | 10.5 MB |
| Inference Speed | ~8ms | ~6ms |
| Portability | Python only | C++, Java, mobile, browser |
| Further Optimization | CUDA | TensorRT, OpenVINO, CoreML |
Generate competition submission files:
python create_submission.pyThis produces the Sapines_II/ folder containing:
predictions.jsonβ Plate bounding boxes for each test imageefficiency.jsonβ FLOPs, latency, and model sizeefficiency_per_image_ms.jsonβ Per-image inference latency
The submission script uses a 3-tier detection strategy:
- Vehicle detection β plate detection in crop
- Fallback: plate detection on full image
- Fallback: 90Β° rotation + plate detection
# 1. Install the Hugging Face CLI
pip install huggingface_hub[cli]
# 2. Login to Hugging Face
huggingface-cli login
# 3. Create the Space (only first time)
huggingface-cli repo create deepsight-sapiens --type space --space-sdk streamlit
# 4. Add the HF remote
git remote add hf https://huggingface.co/spaces/Gyaanendra/deepsight-sapiens
# 5. Push to Hugging Face (triggers auto-deploy)
git push hf mainNote: Hugging Face uses
packages.txtfor system-level apt dependencies andrequirements.txtfor Python packages. Both are already configured in this repo.
Environment Variables: Set your
OPENROUTER_API_KEYin the Space settings β Repository Secrets if you want the GPT-4o fallback to work on HF Spaces.
# 1. Initialize Git LFS (if not already done)
git lfs install
# 2. Add the GitHub remote (first time only)
git remote add origin https://github.com/Gyaanendra/deepsight-sapiens.git
# 3. Stage all changes
git add .
# 4. Commit
git commit -m "feat: complete ANPR pipeline with dual OCR + ONNX support"
# 5. Push to GitHub
git push -u origin mainImportant: This repo uses Git LFS for large files (
.pt,.onnx,.pth,.ipynb,.jpg,.png,.zip). Make sure Git LFS is installed before pushing.
# Push to both GitHub and HF Spaces in one go
git add .
git commit -m "update: latest changes"
git push origin main
git push hf main| Variable | Required | Description |
|---|---|---|
OPENROUTER_API_KEY |
No | API key for GPT-4o-mini OCR fallback via OpenRouter |
| Constant | Path | Description |
|---|---|---|
PT_PATH |
models/best.pt |
Fine-tuned plate detector (PyTorch) |
ONNX_PATH |
models/best.onnx |
Fine-tuned plate detector (ONNX) |
VMODEL |
models/yolo11n.pt |
Vehicle detector (COCO pre-trained) |
The vehicle detector filters for COCO classes [2, 3, 5, 7]:
2β Car3β Motorcycle5β Bus7β Truck
For a comprehensive technical report covering:
- YOLOv11 architecture (backbone, neck, head)
- Anchor-free detection mechanism
- Loss functions (CIoU, BCE, DFL) β with mathematical formulations
- Training curves analysis (epoch-by-epoch)
- Learning rate schedule (warmup + cosine decay)
- IoU, mAP, Precision, Recall β explained in depth
- ONNX export & edge optimization strategies
π See explain.md β the full technical report.
| Feature | Status | Details |
|---|---|---|
| Multi-plate per vehicle | β Done | Supported in current pipeline |
| ONNX inference | β Done | Selectable from sidebar |
| GPU acceleration | β Done | Auto CUDA detection |
| Video inference | β Done | With configurable sample rate |
| Night vision (CLAHE) | β Done | Toggle in sidebar |
| GPT-4o OCR fallback | β Done | Via OpenRouter API |
| Live webcam stream | π² Planned | cv2.VideoCapture(0) integration |
| Plate tracking (ByteTrack) | π² Planned | Cross-frame plate tracking |
| Database logging | π² Planned | SQLite with timestamps |
| Alert system | π² Planned | Blocklist/whitelist plate lookup |
| TensorRT FP16 | π² Planned | 2β3Γ faster on NVIDIA Jetson |
| OpenVINO INT8 | π² Planned | Optimized for Intel edge CPUs |
Contributions are welcome! Here's how to get started:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
git clone https://github.com/Gyaanendra/deepsight-sapiens.git
cd deepsight-sapiens
pip install -r requirements.txt
python -m pytest tests/ # run tests
streamlit run app.py # launch dashboard