Skip to content

Lvisxwj/HDU-DeepLearning-Yolo-homework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

The Convergence Problem

The Game Ends, The Work Begins

The credits rolled on Alan Wake 2. For a moment, I sat in that holy silence after a story ends.

Then reality returned. Homework due tomorrow.

Stories have a way of getting under your skin. They reframe every equation as a metaphor, turn every problem into a reminder of what youโ€™re trying not to think about.

I opened the PDF. Partial differential equations stared back at me, incomprehensible as grief.

โˆ‚u/โˆ‚t = ฮฑโˆ‡ยฒu

The heat equation. How warmth dissipates through space and time. How things fade away.

Like her.

My computer vision code waitedโ€”teaching machines to detect edges, to find boundaries between light and dark, between whatโ€™s there and whatโ€™s not.

Between who I was with you and who I am without you.

Alan Wake wrote his way through darkness to return to Alice. I was just trying to survive until tomorrow, one equation at a time.

In the darkness, something whispered: โ€œItโ€™s not a lake. Itโ€™s an ocean.โ€

The homework would get done. The missing wouldnโ€™t.

That was my story now.

[END]

๐Ÿš— Vehicle Submersion Detection System

ๆฐด็งฏ่ฏ†ๅˆซๅ’Œ่ฝฆ่พ†ๆทนๆฒก้ƒจไฝๅˆคๅˆซ็ณป็ปŸ

A comprehensive system for detecting vehicles in flood images and analyzing their submersion levels using custom-trained YOLO models.

Python PyTorch Streamlit YOLO


๐Ÿ“‹ Overview

This system uses custom-trained YOLO models to:

  • Detect vehicle parts (body, window, wheel) in flood images
  • Segment water areas using semantic segmentation
  • Calculate submersion levels by analyzing part-water overlap
  • Generate statistics and color-coded visualizations

Built for academic research on flood disaster assessment and vehicle damage analysis.


โœจ Features

๐ŸŽฏ Part-Based Vehicle Detection

  • Detects vehicle components separately: body, window, wheel
  • Custom YOLO model trained on 100 epochs (exp23)
  • Confidence threshold: 10% (adjustable 1-100%)

๐ŸŒŠ Water Segmentation

  • Semantic segmentation for water area identification
  • Custom YOLO segmentation model
  • 60% opacity bright blue overlay for clear visualization

๐Ÿ“Š Submersion Analysis

  • Fully Submerged: โ‰ฅ70% of body/window underwater
  • Partially Submerged: Wheels underwater or 20-70% body coverage
  • Not Submerged: <20% water coverage
  • Per-part submersion ratio calculation

๐ŸŽจ Interactive Web Interface

  • Built with Streamlit for easy interaction
  • Multi-model selection (custom + official YOLO models)
  • Real-time processing with progress indicators
  • Three view modes: Detection Only, Segmentation Only, Combined
  • Split-screen comparison (original vs processed)

๐Ÿ“ฅ Export & Download

  • Download all results as ZIP archive
  • Individual downloads per image (detection, segmentation, combined, stats JSON)
  • Aggregate statistics across multiple images
  • CSV export support

๐Ÿš€ Quick Start

Prerequisites

# Conda environment with Python 3.8+
conda activate yolov11

# Required packages
pip install -r requirements.txt

Run the Application

# Method 1: Direct command
streamlit run app.py

# Method 2: Batch file (Windows)
run.bat

The web interface will open at http://localhost:8501


๐Ÿ“ Project Structure

Project3/
โ”œโ”€โ”€ README.md                   # This file
โ”œโ”€โ”€ GUIDE.md                    # Quick start guide
โ”œโ”€โ”€ run.bat                     # Application launcher
โ”œโ”€โ”€ requirements.txt            # Python dependencies
โ”‚
โ”œโ”€โ”€ Core Application
โ”‚   โ”œโ”€โ”€ app.py                  # Streamlit web interface
โ”‚   โ”œโ”€โ”€ detection.py            # Vehicle part detection module
โ”‚   โ”œโ”€โ”€ segmentation.py         # Water segmentation module
โ”‚   โ”œโ”€โ”€ utils.py                # Analysis and visualization
โ”‚   โ””โ”€โ”€ config.py               # Configuration and model paths
โ”‚
โ”œโ”€โ”€ models/                     # Trained YOLO models
โ”‚   โ”œโ”€โ”€ vehical/
โ”‚   โ”‚   โ”œโ”€โ”€ best_exp23.pt      # Best vehicle detection (12.37% max conf)
โ”‚   โ”‚   โ”œโ”€โ”€ last_exp23.pt      # Last epoch checkpoint
โ”‚   โ”‚   โ”œโ”€โ”€ best.pt            # Improved model (0.44% max conf)
โ”‚   โ”‚   โ””โ”€โ”€ last.pt
โ”‚   โ””โ”€โ”€ flood/
โ”‚       โ”œโ”€โ”€ best.pt            # Best water segmentation
โ”‚       โ””โ”€โ”€ last.pt            # Last epoch checkpoint
โ”‚
โ”œโ”€โ”€ demo_images/                # Sample flood images
โ”œโ”€โ”€ results/                    # Processing outputs
โ”œโ”€โ”€ uploads/                    # User uploaded images
โ”‚
โ”œโ”€โ”€ README/                     # Documentation
โ”‚   โ”œโ”€โ”€ README.md              # Complete documentation
โ”‚   โ”œโ”€โ”€ requirement.md         # Project requirements
โ”‚   โ”œโ”€โ”€ project_details.md     # Implementation details
โ”‚   โ”œโ”€โ”€ architecture.md        # System architecture
โ”‚   โ”œโ”€โ”€ CUSTOM_MODELS.md       # Custom model info
โ”‚   โ”œโ”€โ”€ CUSTOM_MODEL_CLASSES.md # Class definitions
โ”‚   โ””โ”€โ”€ SETUP_COMPLETE.md      # Setup guide
โ”‚
โ””โ”€โ”€ test/                       # Test scripts (19 files)
    โ”œโ”€โ”€ test_flood_now.bat/.py
    โ”œโ”€โ”€ test_exp23.bat/.py
    โ”œโ”€โ”€ test_custom.bat/.py
    โ””โ”€โ”€ ...

๐ŸŽฏ Usage Guide

1. Launch Application

streamlit run app.py

2. Configure Models (Sidebar)

  • Detection Model: Select vehicle detection model
    • Recommended: ๐ŸŽฏ Vehicle Custom (Exp23 Best)
  • Segmentation Model: Select water segmentation model
    • Recommended: ๐ŸŒŠ Flood Custom (Best)
  • Confidence Threshold: Adjust sensitivity (default: 0.10)

3. Process Images (Tab 1)

  1. Click "Browse files" to upload images
  2. Select one or multiple images (JPG, PNG, BMP)
  3. Click "๐Ÿš€ Process Images"
  4. View results with radio buttons:
    • Detection Only: Vehicle bounding boxes only
    • Segmentation Only: Water segmentation only
    • Combined: Both detection and segmentation

4. View Statistics (Tab 2)

  • Overall statistics across all images
  • Per-image breakdown table
  • Submersion level distribution chart

5. Download Results (Tab 3)

  • Download all results as ZIP
  • Or download individual results per image

๐Ÿงช Testing

Test scripts are located in the test/ directory:

# Test flood segmentation
cd test
test_flood_now.bat

# Test exp23 vehicle detection
test_exp23.bat

# Test all images in demo_images/
test_all.bat

# Quick single-image test
quick_test.bat

๐Ÿ”ง Configuration

Edit config.py to customize:

# Model paths
DETECTION_MODELS = {
    "๐ŸŽฏ Vehicle Custom (Exp23 Best)": "models/vehical/best_exp23.pt",
    # Add more models...
}

SEGMENTATION_MODELS = {
    "๐ŸŒŠ Flood Custom (Best)": "models/flood/best.pt",
    # Add more models...
}

# Custom class definitions
CUSTOM_VEHICLE_PARTS = {0: 'body', 1: 'window', 2: 'wheel'}
CUSTOM_WATER_CLASSES = {0: 'water'}

๐Ÿ“Š Technical Details

Models

Vehicle Detection Model (Exp23)

  • Architecture: YOLOv8/v11 object detection
  • Classes: body (0), window (1), wheel (2)
  • Training: 100 epochs on project1 dataset
  • Performance: 12.37% max confidence on test set
  • Input: Ground-level vehicle images

Water Segmentation Model

  • Architecture: YOLOv8/v11 semantic segmentation
  • Classes: water (0)
  • Training: Custom flood dataset
  • Output: Binary mask for water regions

Submersion Analysis Algorithm

# Whole vehicle submersion
if submersion_ratio >= 0.7:
    level = "fully_submerged"
elif submersion_ratio >= 0.2:
    level = "partially_submerged"
else:
    level = "not_submerged"

# Part-based submersion (custom model)
if part == 'wheel' and submersion_ratio >= 0.5:
    level = "partially_submerged"
elif part in ['body', 'window'] and submersion_ratio >= 0.7:
    level = "fully_submerged"

Visualization

  • Red: Fully Submerged (โ‰ฅ70%)
  • Orange: Partially Submerged (20-70%)
  • Green: Not Submerged (<20%)
  • Blue: Water Area (60% opacity overlay)

โš ๏ธ Important Notes

Model Limitations

The custom vehicle detection model was trained on ground-level clear vehicle photos, NOT aerial flood images. For optimal results:

โœ… Best: Use images from training dataset

  • Location: ๆœบๅ™จๅญฆไน ่ฏพ็จ‹ๅฎž่ทต\project1\dataset2\images\test\

โš ๏ธ Limited: New aerial flood images (cc*.jpg)

  • Detection may be poor due to angle/lighting differences
  • Consider retraining with flood-specific images

๐Ÿ”„ Alternative: Use official YOLO models (YOLOv11n) for general vehicles

Confidence Threshold

  • Default: 0.10 (10%)
  • Range: 0.01 to 1.0
  • Lower = more detections (more false positives)
  • Higher = fewer detections (higher precision)

๐Ÿ› Troubleshooting

No Detections?

  1. Lower confidence threshold (try 0.05)
  2. Use images from training dataset
  3. Check console output for model loading confirmation

Water Not Visible?

  1. Water overlay is 60% opacity with bright blue
  2. Check console for segmentation results
  3. Verify water exists in image

Results Disappear When Switching Views?

  • Fixed: Results now persist across view switches
  • Ensure you're in "Upload & Process" tab

๐Ÿ“š Documentation

Detailed documentation available in README/:


๐Ÿ› ๏ธ Technology Stack

  • Frontend: Streamlit 1.28+
  • Backend: Python 3.8+
  • Deep Learning: PyTorch 2.0+ with CUDA
  • Computer Vision: OpenCV 4.8+
  • Object Detection: Ultralytics YOLO (v8 & v11)
  • Data Processing: NumPy, Pandas
  • Image Handling: PIL/Pillow

๐Ÿ“ฆ Dependencies

streamlit>=1.28.0
ultralytics>=8.0.0
opencv-python>=4.8.0
torch>=2.0.0
torchvision>=0.15.0
numpy>=1.24.0
pandas>=2.0.0
Pillow>=10.0.0

Install all:

pip install -r requirements.txt

๐ŸŽ“ Academic Context

Project: Task 4 - Vehicle Submersion Detection System Course: Machine Learning Practice (ๆœบๅ™จๅญฆไน ่ฏพ็จ‹ๅฎž่ทต) Institution: [Your Institution] Due Date: October 28, 2025 Environment: Conda (yolov11), Python 3.x


๐Ÿ“ License

This project is for academic use. Please refer to your institution's policies for code sharing and reuse.


๐Ÿค Contributing

This is an academic project. For questions or issues:

  1. Check README/ documentation
  2. Review test/ scripts for examples
  3. Consult GUIDE.md for troubleshooting

๐Ÿ“ง Contact

For questions related to this project, please contact the development team.


๐Ÿ™ Acknowledgments

  • Ultralytics YOLO: Object detection framework
  • Streamlit: Web interface framework
  • OpenCV: Image processing library
  • PyTorch: Deep learning platform

๐Ÿ“Š Project Statistics

  • Lines of Code: ~2,000+
  • Python Files: 5 core modules
  • Test Scripts: 19 test files
  • Documentation: 7 markdown files
  • Models: 6 trained models (2 best + 4 checkpoints)

โญ Star this repository if you find it helpful!

๐Ÿš€ Get started: streamlit run app.py "# -yolo-promax"

About

dogshit

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published