Educational computer vision notebook exploring real-time object detection for Hi-Lo blackjack counting practice. Demonstrates PyTorch + YOLOv8 training, OpenCV inference pipelines, and CUDA-accelerated ML fundamentals.
📓 Open card-detection.ipynb to get started
- mAP@0.5: 99.5% on validation set
- Inference: 30+ FPS on RTX 4070
- Dataset: 21,203 training images, 52 classes (13 ranks × 4 suits)
- Model: YOLOv8n (3.2M params, 6MB)
card-detection.ipynb - Comprehensive notebook covering:
- Dataset Exploration - YOLO annotation format, class distribution, bbox analysis
- ML Fundamentals - Loss functions (CIoU + BCE + DFL), training loop concepts
- Model Training - YOLOv8n fine-tuning with data augmentation
- Inference Pipeline - Manual NMS implementation, OpenCV visualization
- Hi-Lo Counting - Blackjack counting strategy with state management
- PyTorch 2.5.1+ (CUDA 12.1)
- YOLOv8 (Ultralytics)
- OpenCV 4.8+
- matplotlib, seaborn (visualization)
- NumPy, pandas (data analysis)
pip install ultralytics opencv-python torch matplotlib seaborn pandas
jupyter notebook card-detection.ipynbRequirements: Python 3.10+, CUDA 11.7+ (for GPU acceleration)
card-detection/
├── card-detection.ipynb # Main educational notebook
├── datasets/
│ ├── train/ # 21,203 training images
│ ├── valid/ # 2,020 validation images
│ └── data.yaml # Dataset config (52 classes)
└── backend/runs/card_detection/
└── weights/best.pt # Fine-tuned model weights
- YOLO annotation format (normalized bounding boxes)
- Class distribution analysis and balancing
- Bbox aspect ratio and area statistics
- Data augmentation (mosaic, mixup, HSV jitter)
- Transfer learning from COCO pretrained weights
- Multi-component loss function:
7.5×CIoU + 0.5×BCE + 1.5×DFL - AdamW optimizer with learning rate scheduling
- Training metrics visualization and interpretation
- Manual NMS (Non-Maximum Suppression) implementation
- Confidence threshold tuning (0.5-0.7 recommended)
- OpenCV visualization pipeline
- Real-time performance optimization
- Blackjack counting strategy implementation
- State management (running count, seen cards)
- Duplicate detection prevention
| Card Range | Value | Strategy |
|---|---|---|
| 2-6 | +1 | Favors player |
| 7-9 | 0 | Neutral |
| 10-A | -1 | Favors dealer |
Metrics (after 5 epochs):
- Precision: 99.36%
- Recall: 99.51%
- mAP@0.5: 99.5%
- mAP@0.5:0.95: 70.77%
Inference Speed (RTX 4070):
- 30ms/frame (33 FPS)
- ~2GB GPU memory
Roboflow Playing Cards Dataset
- 21,203 training images
- 2,020 validation images
- 52 classes (13 ranks × 4 suits)
- Well-balanced: ~400 instances per class
- YOLOv8 Documentation
- OpenCV Python Tutorials
- Object Detection Metrics Explained
- Hi-Lo Card Counting Strategy
- Ultralytics - YOLOv8 framework
- Roboflow - Playing Cards dataset
- OpenCV Community
Educational project for hands-on computer vision learning MIT License