# Car_Identify **Repository Path**: fitz_gitee/Car_Identify ## Basic Information - **Project Name**: Car_Identify - **Description**: 学习通过YOLO5模型用深度学习训练车辆检测的功能,包括车辆类别和出现位置。 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-01 - **Last Updated**: 2025-10-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 车辆检测训练 & 推理示例 该脚本基于 YOLOv5 Backbone,实现了一个完整的 车辆(单类别)检测 训练 / 评估 / 测试流程。 脚本内容涵盖: 数据集封装(VehicleDataset) 数据增强(水平翻转、尺度变换、颜色归一化等) 模型构建与预训练权重加载(build_and_configure_model) 训练(train_model) 验证 & 指标计算(evaluate_model / ap_per_class) 测试(test_model) 检测结果可视化(plot_detections) ## 函数简介 **VehicleDataset** 按索引返回 (image, target),其中 target 为符合 PyTorch Detection API 的字典格式。 **RandomHorizontalFlip** 50% 概率水平翻转,自动同步 bbox。 **load_and_preprocess_data** 划分 7:2:1 的 train / val / test,并返回对应 DataLoader。 **build_and_configure_model** 加载 yolov5s.pt 预训练权重,并重新定义 nc=1(单类别车辆)。 **train_model** 采用 SGD + utils.loss.ComputeLoss 计算 YOLOv5 多任务损失。 **evaluate_model / test_model** 使用 ap_per_class 统计各项检测指标。 **plot_detections** 绿色框:GT;红色框:预测(带置信度)。 ## 自定义要点 **多类别任务** - 在 build_and_configure_model 调整 nc 并在数据标注里对不同类别使用不同 class_id。 - 同时需要修改 class_names 列表。 **参数微调** - 学习率、batch size、超参 hyp 等均可直接在脚本中修改。 - 若显存不足,可调小 batch_size,或使用 --half(即 fp16=True)加速推理。 **数据增广** - 目前仅实现水平翻转,可在 transforms 内增添更多 torchvision.transforms 或自定义逻辑。 本项目仅做学习用。