无人机模型评估工具

Hannnk b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago
scripts b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago
src b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago
tests b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago
.gitignore b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago
README.md b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago
README_NEW.md b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago
inference.py b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago
requirements.txt b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago
run.py b55235a45e feat: 实现UAV检测系统重构版本v2.0 1 month ago

README.md

UAV检测系统 - 重构版本 v2.0

基于ONNX的无人机检测系统,采用模块化设计,提供高效的目标检测和结果分析功能。

🚀 项目特点

  • 模块化设计: 将功能拆分为独立的模块,便于维护和扩展
  • 配置管理: 统一的配置系统,支持灵活的参数调整
  • 高性能: 支持GPU加速推理,优化的图像处理流程
  • 完整报告: 自动生成CSV和Excel格式的检测报告
  • 易于使用: 提供命令行和编程接口

📁 项目结构

ModelEvaluator/
├── src/                     # 源代码目录
│   ├── config/              # 配置模块
│   │   └── config.py        # 配置类定义
│   ├── core/                # 核心模块
│   │   ├── detector.py      # 主检测器
│   │   ├── image_processor.py # 图像处理
│   │   ├── model_inference.py # 模型推理
│   │   └── post_processor.py  # 后处理
│   ├── utils/               # 工具模块
│   │   ├── file_manager.py  # 文件管理
│   │   └── report_generator.py # 报告生成
│   └── main.py              # 主入口
├── tests/                   # 测试代码
│   └── test_refactored.py   # 重构测试
├── data/                    # 数据目录
│   ├── models/              # 模型文件
│   └── samples/             # 样本数据
├── docs/                    # 文档目录
├── examples/                # 示例代码
├── scripts/                 # 脚本目录
├── output/                  # 输出目录
├── logs/                    # 日志目录
├── run.py                   # 项目启动入口
├── requirements.txt         # 依赖列表
└── README.md               # 项目说明

🛠️ 安装和配置

环境要求

  • Python 3.8+
  • CUDA 11.0+ (可选,用于GPU加速)

安装依赖

pip install -r requirements.txt

模型文件

将ONNX模型文件放置在 data/models/ 目录下。

🚀 使用方法

命令行使用

基本用法

# 检测单张图片
python run.py --input image.jpg

# 批量检测目录中的图片
python run.py --input /path/to/images

# 使用GUI选择输入目录
python run.py --gui

# 自定义参数
python run.py --input /path/to/images --threshold 0.6 --output custom_output

完整参数说明

python run.py --help

主要参数:

  • --input: 输入图像路径或目录
  • --output: 输出目录路径
  • --model: ONNX模型文件路径
  • --threshold: 检测置信度阈值 (默认: 0.5)
  • --iou-threshold: NMS IoU阈值 (默认: 0.4)
  • --max-bbox-ratio: 检测框最大面积比例阈值 (默认: 0.5)
  • --save-empty: 是否保存未检测到目标的图片
  • --gui: 启用图形界面选择输入目录
  • --verbose: 显示详细信息

编程接口使用

import sys
import os
sys.path.insert(0, 'src')

from config.config import AppConfig, ModelConfig, DetectionConfig, OutputConfig
from core.detector import UAVDetector

# 创建配置
model_config = ModelConfig(
    model_path='data/models/your_model.onnx',
    input_size=(640, 640),
    confidence_threshold=0.5
)

detection_config = DetectionConfig(
    confidence_threshold=0.5,
    iou_threshold=0.4,
    max_bbox_ratio=0.5
)

output_config = OutputConfig(
    base_output_dir='output',
    add_timestamp=True,
    save_empty_images=False
)

app_config = AppConfig(
    model=model_config,
    detection=detection_config,
    output=output_config
)

# 初始化检测器
detector = UAVDetector(config=app_config, input_dir='path/to/images')

# 处理单张图片
result = detector.process_image('image.jpg')

# 批量处理
detector.process_batch(['image1.jpg', 'image2.jpg'])

# 生成报告
detector.generate_reports()

# 获取统计信息
stats = detector.get_statistics()
print(f"处理图片数: {stats['total_images']}")
print(f"检测到目标数: {stats['total_detections']}")

📊 输出结果

目录结构

output/
├── imgs/                    # 检测结果图片
│   ├── image1_detected.jpg
│   └── image2_detected.jpg
├── targets/                 # 检测目标ROI
│   ├── image1_target_1.jpg
│   └── image1_target_2.jpg
├── detection_report.csv     # CSV格式报告
└── detection_report.xlsx    # Excel格式报告

报告内容

  • CSV报告: 包含每个检测框的详细信息
  • Excel报告: 包含模型信息、检测统计和详细结果
  • 检测图片: 标注了检测框的原图
  • 目标ROI: 提取的检测目标区域

🧪 测试

运行测试脚本验证系统功能:

python tests/test_refactored.py

🔧 配置说明

ModelConfig (模型配置)

  • model_path: ONNX模型文件路径
  • input_size: 模型输入尺寸 (width, height)
  • mean: 图像归一化均值
  • std: 图像归一化标准差
  • use_cuda: 是否使用CUDA加速

DetectionConfig (检测配置)

  • confidence_threshold: 置信度阈值
  • iou_threshold: NMS IoU阈值
  • max_bbox_ratio: 检测框最大面积比例

OutputConfig (输出配置)

  • base_output_dir: 基础输出目录
  • add_timestamp: 是否添加时间戳
  • save_empty_images: 是否保存空检测图片

🆕 版本更新

v2.0 (当前版本)

  • ✅ 完全重构代码架构
  • ✅ 模块化设计,提高可维护性
  • ✅ 统一配置管理系统
  • ✅ 改进的错误处理机制
  • ✅ 标准化的项目结构
  • ✅ 向后兼容性支持
  • ✅ 完善的测试覆盖

v1.0 (原版本)

  • 基础的UAV检测功能
  • 单文件架构
  • 基本的报告生成

注意: 这是重构版本,相比原版本具有更好的代码结构和可维护性。建议使用新的 run.py 入口文件启动应用程序。