Aradoledge/airport-crime-detection-AEI

GitHub: Aradoledge/airport-crime-detection-AEI

一款融合CNN-LSTM时空分析与YOLO目标检测的机场安防智能监控系统,实现实时异常行为识别与威胁告警。

Stars: 0 | Forks: 0

## 🎯 项目概述 本项目实现了一个专为机场安防环境设计的 **AI 驱动犯罪检测系统**。该系统利用 **深度学习技术**,结合 **卷积神经网络** 和 **长短期记忆网络 (LSTM)** 进行时空异常检测,并集成了 **YOLO (You Only Look Once)** 用于实时目标检测。 ### 核心功能: - **实时异常检测**:识别可疑行为(无人看管的行李、奔跑、徘徊) - **目标检测**:基于 YOLO 的人员、行李及潜在威胁检测 - **混合 CNN-LSTM 架构**:结合空间与时间分析 - **交互式仪表板**:基于 Streamlit 的监控界面 - **多源输入**:支持网络摄像头、视频文件和 CCTV 集成 ## 🏗️ 系统架构 ### 技术栈: - **后端**:Python 3.8+, TensorFlow 2.11+, PyTorch - **计算机视觉**:OpenCV, YOLOv8 - **深度学习**:CNN (VGG16/ResNet50) + LSTM - **仪表板**:Streamlit, Streamlit-WebRTC - **数据处理**:NumPy, Pandas, Albumentations ### 架构图: ``` ┌─────────────────────────────────────────────────────────────┐ │ Video Input Sources │ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │ │ Webcam │ │ CCTV │ │ Video │ │ Test │ │ │ │ │ │ Streams │ │ Files │ │ Videos │ │ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │ │ │ │ ▼ │ │ ┌─────────────────────────┐ │ │ │ Frame Preprocessing │ │ │ │ • Resize (224×224) │ │ │ │ • Normalization │ │ │ │ • Augmentation │ │ │ └─────────────────────────┘ │ │ │ │ │ ┌─────────────────────────┐ ┌───────────────────┐ │ │ │ YOLO Detection │ │ CNN-LSTM Model │ │ │ │ • Object Detection │ │ • Feature Extrac │ │ │ │ • Bounding Boxes │ │ • Temporal Analy │ │ │ │ • Threat Classification│ │ • Anomaly Score │ │ │ └─────────────────────────┘ └───────────────────┘ │ │ │ │ │ │ └─────────────────────┘ │ │ │ │ │ ┌─────────────────────┐ │ │ │ Decision Fusion │ │ │ │ • Alert Generation │ │ │ │ • Confidence Score │ │ │ └─────────────────────┘ │ │ │ │ │ ┌─────────────────────────────────────────┐ │ │ │ Output & Visualization │ │ │ │ • Annotated Video • Dashboard │ │ │ │ • Log Files • Real-time │ │ │ │ • Alert Notifications Alerts │ │ │ └─────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────┘ ``` ## ⚙️ 前置条件 ### 硬件要求: - **最低配置**:支持 AVX 的 CPU,8GB 内存,10GB 可用磁盘空间 - **推荐配置**:NVIDIA GPU (4GB+ 显存),16GB 内存,50GB SSD - **最佳配置**:NVIDIA RTX 3060+ (用于实时处理),32GB 内存 ### 软件要求: - **操作系统**:Windows 10/11, Ubuntu 20.04+, macOS 12+ - **Python**:3.8, 3.9 或 3.10 - **CUDA**:11.2+ (用于 GPU 加速) - **cuDNN**:8.1+ (用于 GPU 加速) ## 📥 安装指南 ### 针对 Windows 用户: #### 1. 安装 Python 和依赖项 ``` # 从 python.org 下载最新版本的 Python # 安装过程中,勾选 "Add Python to PATH" # 以管理员身份运行命令提示符 python --version # Should show Python 3.12 or a version above # 安装 Git (如果尚未安装) # 从 https://git-scm.com/download/win 下载 ``` #### 2. 克隆仓库 ``` # 打开 PowerShell 或命令提示符 cd C:\Users\YourName\Projects git clone https://github.com/Aradoledge/airport-crime-detection-AEI cd airport-crime-detection-AEI ``` #### 3. 创建虚拟环境 ``` # 创建虚拟环境 python -m venv myenv # 激活虚拟环境 .\myenv\Scripts\activate # 您的提示符应更改为显示 (myenv) ``` #### 4. 安装系统依赖 ``` # 安装 Visual C++ Build Tools (用于某些软件包) # 下载地址:https://visualstudio.microsoft.com/visual-cpp-build-tools/ # 安装 CMake (用于 dlib/face_recognition) # 下载地址:https://cmake.org/download/ ``` #### 5. 安装 Python 软件包 ``` # 升级 pip python -m pip install --upgrade pip # 安装依赖项 pip install -r requirements.txt # 如果您有支持 CUDA 的 GPU,请安装支持 GPU 的 TensorFlow pip install tensorflow[and-cuda] # 安装带 CUDA 的 PyTorch (访问 https://pytorch.org/get-started/locally/) pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 ``` ### 针对 Linux 用户: #### 1. 系统更新和依赖项 ``` # 更新系统 sudo apt update && sudo apt upgrade -y # 安装系统依赖项 sudo apt install -y python3.9 python3.9-venv python3-pip git cmake sudo apt install -y libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender-dev # 对于 GPU 支持 (NVIDIA) sudo apt install -y nvidia-cuda-toolkit nvidia-driver-525 ``` #### 2. 克隆与设置 ``` # 克隆仓库 cd ~/Projects git clone https://github.com/Aradoledge/airport-crime-detection-AEI cd airport-crime-detection-AEI # 创建虚拟环境 python3.9 -m venv myenv source myenv/bin/activate ``` #### 3. 安装 Python 软件包 ``` # 升级 pip pip install --upgrade pip # 安装依赖项 pip install -r requirements.txt # 安装带 CUDA 的 PyTorch pip3 install torch torchvision torchaudio ``` ### 针对 macOS 用户: ``` # 如果尚未安装,请安装 Homebrew /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # 安装 Python 和依赖项 brew install python@3.9 git cmake brew install libomp # 克隆并设置 git clone https://github.com/Aradoledge/airport-crime-detection-AEI cd airport-crime-detection-AEI python3.9 -m venv myenv source myenv/bin/activate pip install -r requirements.txt ``` ## 📊 数据集准备 ### 方案 1:使用真实 UCF-Crime 数据集(推荐) #### 1. 下载 UCF-Crime 数据集 ``` # 从以下地址下载:https://www.dropbox.com/scl/fo/2aczdnx37hxvcfdo4rq4q/AOjRokSTaiKxXmgUyqdcI6k?rlkey=5bg7mxxbq46t7aujfch46dlvz&e=3&dl=0 # 解压到正确的目录 mkdir -p data/raw/ucf_crime # 将下载的视频复制到:data/raw/ucf_crime/ ``` #### 2. 准备数据集结构 ``` # 预期结构: data/raw/ucf_crime/ ├── Normal/ │ └── Normal_Videos_xxx.mp4 └── Anomaly/ ├── Abuse/ │ └── Abusexxx_x264.mp4 ├── Arrest/ │ └── Arrestxxx_x264.mp4 └── ... (other anomaly categories) ``` #### 3. 提取帧 ``` # 解压样本数据集 (用于测试) python main.py extract --sample --sample_size 20 # 解压完整数据集 (需要时间) python main.py extract ``` ### 方案 2:生成模拟数据集(用于测试) ``` # 生成合成数据集 python main.py generate-fake --num_normal 10 --num_anomaly 10 # 从 fake 数据集中提取帧 python main.py extract --fake ``` ### 数据集统计信息 ``` # 检查数据集统计信息 python main.py stats # 预期输出: # 正常帧:XXXX # 异常帧:XXXX # 总帧数:XXXX ``` ## 🚀 模型训练 ### 1. 配置设置 编辑 `config/settings.py` 以调整参数: ``` # 训练参数 SEQUENCE_LENGTH = 20 # Number of frames per sequence IMG_HEIGHT = 224 # Image height IMG_WIDTH = 224 # Image width BATCH_SIZE = 8 # Batch size (adjust based on GPU memory) NUM_EPOCHS = 50 # Number of training epochs LEARNING_RATE = 0.001 # Learning rate # 模型架构 CNN_BACKBONE = "vgg16" # Options: "vgg16", "resnet50", "inception_v3" LSTM_UNITS = 128 # Number of LSTM units DROPOUT_RATE = 0.5 # Dropout rate ``` ### 2. 启动训练流程 ``` # 基础训练 python main.py train --epochs 20 --batch_size 8 # 带监控的高级训练 python src/train.py --epochs 50 --batch_size 16 --sequence_length 25 # 使用特定 backbone 进行训练 # 编辑 config/settings.py 以更改 CNN_BACKBONE ``` ### 3. 监控训练进度 ``` # TensorBoard 监控 tensorboard --logdir logs/ # 访问地址:http://localhost:6006 # 监控训练日志 tail -f training.log ``` ### 4. 训练输出 ``` # 训练好的模型保存在: models/trained/ ├── airport_anomaly_detector_best.h5 # Best model ├── airport_anomaly_detector_final.h5 # Final model └── checkpoint/ # Checkpoints # 训练日志位于: logs/ └── airport_anomaly_detector_YYYYMMDD_HHMMSS/ ├── train/ # Training metrics └── validation/ # Validation metrics ``` ### 5. 训练性能优化 ``` # 用于 GPU 训练验证 python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))" # 如果检测到 GPU,TensorFlow 将自动使用它 # 用于混合精度训练 (更快,更省内存): # 添加到 config/settings.py: # tf.keras.mixed_precision.set_global_policy('mixed_float16') ``` ## 🧪 测试与评估 ### 1. 模型评估 ``` # 评估训练好的模型 python evaluate.py # 预期输出包括: # - Accuracy, Precision, Recall, F1-Score # - Confusion Matrix # - ROC Curve ``` ### 2. 实时检测测试 #### 使用网络摄像头: ``` python main.py detect --source webcam # 按 'q' 退出,按 'p' 暂停 ``` #### 使用视频文件: ``` python main.py detect --source "data/raw/ucf_crime/Normal/Normal_Videos_015_x264.mp4" # 带输出录制 python main.py detect --source "input_video.mp4" --output "output_detection.avi" ```