# Quick Start Guide - Testing the Model This guide will help you quickly test the Highway Vehicle Detection model on new data. ## Prerequisites 1. **Install Python dependencies:** ```bash pip install -r requirements.txt ``` 2. **Download/clone the repository** from Hugging Face: ```bash git clone https://huggingface.co/bichuche0705/highway-vehicle-detection-code cd highway-vehicle-detection-code ``` Or download manually from: https://huggingface.co/bichuche0705/highway-vehicle-detection-code ## Model Files Location The trained models are located at: - **Best model (recommended)**: `training_runs/yolov8m_stage2_improved/weights/best.pt` - **Alternative location**: `models/yolov8m_stage2_improved_best.pt` - **Stage 1 model**: `training_runs/yolov8m_stage1_smart/weights/best.pt` ## Method 1: Simple Test Script (Recommended for Quick Testing) Use the `test_model.py` script for easy testing: ### Test on an Image: ```bash python test_model.py your_image.jpg ``` The script will: - Automatically find the model - Detect vehicles in the image - Save the result as `your_image_result.jpg` ### Test on a Video: ```bash python test_model.py your_video.mp4 --video ``` With custom output: ```bash python test_model.py your_video.mp4 --video --output output_video.mp4 ``` ## Method 2: Using example_usage.py ```python from example_usage import detect_vehicles, process_video # For images detect_vehicles("test_image.jpg", model_path="models/yolov8m_stage2_improved_best.pt") # For videos process_video("test_video.mp4", output_path="output.mp4") ``` ## Method 3: Using main.py (Full Application) The `main.py` script provides advanced features like vehicle counting and tracking: ```bash # Basic usage (auto-detects first .mp4 in directory) python main.py --model training_runs/yolov8m_stage2_improved/weights/best.pt # With specific video python main.py --model training_runs/yolov8m_stage2_improved/weights/best.pt --video your_video.mp4 # Save output video python main.py --model training_runs/yolov8m_stage2_improved/weights/best.pt --video input.mp4 --output output.mp4 ``` **Important**: You need to specify the `--model` path because the default path in `main.py` might not match the repository structure. ## Method 4: Direct Python Code ```python from ultralytics import YOLO # Load model model = YOLO('training_runs/yolov8m_stage2_improved/weights/best.pt') # Test on image results = model('your_image.jpg') results[0].show() # Display results results[0].save('output.jpg') # Save results # Test on video results = model('your_video.mp4', save=True) # Output saved to: runs/detect/predict/ ``` ## Detected Vehicle Classes The model detects 8 vehicle types: 1. **auto** - Three-wheelers 2. **bus** - Public transport vehicles 3. **car** - Passenger cars 4. **lcv** - Light Commercial Vehicles 5. **motorcycle** - Two-wheelers 6. **multiaxle** - Multi-axle heavy vehicles 7. **tractor** - Agricultural/construction vehicles 8. **truck** - Heavy vehicles ## Troubleshooting ### Model Not Found Error If you get "Model file not found": 1. Make sure you've downloaded/cloned the repository completely 2. Check that the model file exists at one of these paths: - `training_runs/yolov8m_stage2_improved/weights/best.pt` - `models/yolov8m_stage2_improved_best.pt` ### Import Errors If you get import errors: ```bash pip install ultralytics opencv-python numpy torch torchvision ``` Or install all requirements: ```bash pip install -r requirements.txt ``` ### CUDA/GPU Issues If you have CUDA available, PyTorch will use it automatically. For CPU-only: - The model will run but will be slower - No additional setup needed ## Example Output When running the model, you should see: - Bounding boxes around detected vehicles - Class labels (auto, bus, car, etc.) - Confidence scores - Output saved to files ## Need Help? Check the repository README.md for more detailed documentation, or review the code comments in: - `main.py` - Full application with counting - `example_usage.py` - Simple examples - `test_model.py` - Quick test script