littlebot
Published on 2025-04-14 / 0 Visits
0

【源码】基于Python的EfficientDet水下生物检测系统

项目简介

本项目是基于Python的水下生物检测系统,主要功能是把水下生物的自定义数据集从VOC格式转换为COCO格式,再利用EfficientDet模型开展水下生物(海参、海胆、扇贝、海星)的检测训练与测试。项目参考EfficientDet相关开源项目,提供了完整的数据集处理、模型训练和评估流程。

项目的主要特性和功能

  1. 数据转换:可将VOC格式的水下生物数据集按9:1比例划分为训练集和验证集,并转换成COCO格式,便于后续用EfficientDet模型训练。
  2. 模型训练:能从头开始训练EfficientDet - D2模型,也可用预训练模型训练,支持断点训练,还能冻结骨干网络只训练头部网络以加快训练速度。
  3. 模型测试与评估:提供测试新图像和评估模型的脚本,用COCO的mAP指标评估模型,且能在训练过程中进行调试可视化。

安装使用步骤

1. 数据准备

将数据存放在项目的dataset下,目录结构如下: .. └─underwater ├─Annotations # xml标注 └─JPEGImages # jpg原图

2. 划分训练集和验证集

将数据集按9:1的比例随机划分为训练集和验证集,划分后的数据结构如下: .. ├─train │ ├─Annotations │ └─JPEGImages └─val ├─Annotations └─JPEGImages

3. 将VOC转COCO

运行以下命令将划分好的训练集和验证集转换为COCO格式: bash python voc2coco.py train.txt./train/Annotations instances_train.json./train/JPEGImages python voc2coco.py val.txt./val/Annotations instances_val.json./val/JPEGImages 生成的json文件存放在dataset/underwater/annotations/目录下。

4. 修改EfficientDet的项目文件

  • 新建dataset文件夹,将训练和验证数据存放在dataset/underwater目录下。 dataset └─underwater # 项目数据集名称 ├─annotations # instances_train.json,instances_val.json ├─train # train jpgs └─val # val jpgs
  • 新建logs文件夹,用于存放训练过程中的TensorBoardX日志及模型。
  • 修改train.pyefficientdet_test.pycoco_eval.pyefficientdet/config.py等文件中的相关参数,如项目名称、类别列表、模型路径等。
  • 新建yml配置文件./projects/underwater.yml,配置训练参数。

5. 训练EfficientDet模型

  • 从头训练自己的数据集EfficientDet - D2: bash python train.py -c 2 --batch_size 16 --lr 1e4
  • 使用预训练的模型进行训练(推荐): bash python train.py -c 2 --batch_size 8 --lr 1e-5 --num_epochs 10 --load_weights /path/to/your/weights/efficientdet-d2.pth
  • 冻结骨干网络只训练头部网络: bash python train.py -c 2 --batch_size 8 --lr 1e-5 --num_epochs 10 --load_weights /path/to/your/weights/efficientdet-d2.pth --head_only True
  • 断点训练: bash python train.py -c 2 --batch_size 8 --lr 1e-5 --load_weights last --head_only True

6. 测试EfficientDet模型

  • 评估模型使用COCO的mAP: bash python coco_eval.py -p underwater -c 2 -w./logs/underwater/efficientdet-d2_122_38106.pth
  • 训练过程中的调试: bash python train.py -c 2 --batch_size 8 --lr 1e-5 --debug True
  • 推断新的图像: bash python efficientdet_test.py

下载地址

点击下载 【提取码: 4003】【解压密码: www.makuang.net】