A comprehensive vehicle detection, tracking, and traffic analysis system that implements two different approaches:
- DETR (DEtection TRansformer) based implementation
- Faster R-CNN based implementation
- RF-DETR with ConvNext Backbone
First and Second implementations use DeepSORT for object tracking and provide similar functionality with different underlying detection architectures.
⚠️ Note: RF-DETR training was not completed due to hardware limitations. The model takes significantly longer to train compared to DETR and Faster R-CNN, especially when relying on Apple's MPS backend (MacBook M1/M2 GPU support).
When training on an M1 Mac, PyTorch often falls back to CPU for unsupported operations, leading to extremely slow performance. One such warning observed during training:
"UserWarning: The operator 'aten::grid_sampler_2d_backward' is not currently supported on the MPS backend and will fall back to run on the CPU. This may have performance implications. (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/aten/src/ATen/mps/MPSFallback.mm:14.)"
- Real-time vehicle detection using DETR, Faster R-CNN, or RF-DETR.
- Multi-object tracking with DeepSORT
- Vehicle counting and classification
- Traffic analysis and statistics
- Visualization of detection and tracking results
- Support for video and image processing
- Traffic flow analysis and reporting
- Python 3.8+
- PyTorch >= 2.0.0
- OpenCV >= 4.8.0
- Other dependencies listed in respective
requirements.txtfiles
- Clone the repository:
git clone [your-repository-url]
cd Vehicle_countingv2-
Download DeepSORT:
- Clone the DeepSORT repository:
git clone https://github.com/ZQPei/deep_sort_pytorch.git
- Copy the
deep_sort_pytorchfolder into bothDETR_vehicle_countingandfasterRcnn_deepsortdirectories - Download the DeepSORT weights from here
- Place the downloaded weights in both:
DETR_vehicle_counting/deep_sort_pytorch/deep/checkpoint/fasterRcnn_deepsort/deep_sort_pytorch/deep/checkpoint/
-
Download Model Weights:
-
Install dependencies for DETR implementation:
pip install -r DETR_vehicle_counting/requirements.txt- Install dependencies for Faster R-CNN implementation:
pip install -r fasterRcnn_deepsort/requirements.txt- Run vehicle detection and tracking:
python DETR_vehicle_counting/track1.py --source [video_path]- Analyze traffic data:
python DETR_vehicle_counting/analyze_traffic.py --input [results_path]- Visualize predictions:
python DETR_vehicle_counting/visualize_preds.py --input [predictions_path]- Run vehicle detection and tracking:
python fasterRcnn_deepsort/track.py --source [video_path]To train the DETR model on your own dataset:
- Prepare your dataset in COCO format
- Configure training parameters in
train.py - Run training:
python DETR_vehicle_counting/train.pyThe Faster R-CNN implementation uses a pre-trained model. If you want to fine-tune it:
- Prepare your dataset in the required format
- Configure training parameters in the respective script
- Run training with your custom dataset
- DeepSORT parameters can be adjusted in the
deepsort_configdirectory of each implementation - Model parameters can be modified in the respective script files
- Visualization settings can be customized in the visualization scripts
Both implementations generate:
- Real-time vehicle detection and tracking visualizations
- Traffic analysis reports
- Vehicle counting statistics
- JSON files containing detailed tracking data
Sample outputs and results can be found in the Outputs Folder
- DETR Implementation: Better for modern architectures and transformer-based approaches
- Faster R-CNN Implementation: Better for traditional CNN-based approaches and potentially faster inference
- DETR: Facebook Research
- DeepSORT: Original Implementation
- DeepSORT PyTorch Implementation: ZQPei's Implementation
- Faster R-CNN: Original Paper