PI-Det
是面向无人机航拍图像的物体检测,基于PyTorch_YOLOv4
的基础上进行改进,并结合增量学习方法,可通过使用新类别物体的数据进行训练,并保持一定的对旧类别物体的检测能力,避免神经网络发生灾难性遗忘,技术文档见无人机航拍图像物体检测
可通过下面这一行命令安装依赖(建议使用Ubuntu18.04)
pip install -r requirements.txt
并安装mish-cuda
git clone https://github.com/thomasbrandon/mish-cuda
cd mish-cuda
cp external/CUDAApplyUtils.cuh csrc # cuda >= 11.0
python setup.py build install
本程序最好在Conda环境下运行,Conda的运行环境安装见InstallConda
训练前需要将图像和标注分别放在 images
和labels
文件夹下,并将训练集所有图像路径写入train.txt
文本中,验证集所有图像路径写入val.txt
文本中,测试集所有图像路径写入test.txt
文本中,然后对coco.yaml
文件进行更改,将其中的文件路径进行替换,例如:
train: ../your_path/train.txt
val: ../your_path/val.txt
test: ../your_path/test.txt
# number of classes
nc: 3
# class names
names: ['person', 'bicycle', 'car']
数据标注格式与YOLOv4一致,即<object-class> <x_center> <y_center> <width> <height>
,分别代表物体类别,中心点坐标(x,y),边界框的宽和高(w,h),<x_center> <y_center> <width> <height>
均为归一化后的坐标,例如:
2 0.44091796875 0.1953125 0.2685546875 0.021484375
1 0.55029296875 0.173828125 0.0517578125 0.0234375
1 0.5517578125 0.5478515625 0.046875 0.02734375
示例数据集和预训练权重可在百度网盘下载:
链接: https://pan.baidu.com/s/1YZIckwLbVOVpSMuyt3ljwg 密码: inl0
训练前需要对cfg文件进行修改,将其中每个[yolo]
层中的classes
修改为所使用的类别数,并将前一个卷积层的filters
改为(classes+5)x3
,例如:
[convolutional]
filters=255
[yolo]
classes=80
如果使用多GPU进行训练,可将--device 0
改为--device 0,1,2,3
;如果不想每训练完一个epoch就进行验证,可在命令中加上--notest
python train.py --device 0 --batch-size 16 --img 512 512 --data data/your_yaml --cfg cfg/your_cfg --weights weights/pretrained_weight --name your_name --epochs 100
如果要通过增量学习新类别物体,可使用以下命令运行train_incremental.py
python train_incremental.py --device 0 --batch-size 16 --img 512 512 --data data/your_yaml --cfg cfg/new_model_cfg --weights weights/your_weights --name your_name --epochs 100 --notest --incremental --old_mod cfg/old_model_cfg
python test.py --img 512 --conf 0.001 --batch 16 --device 0 --data data/your_yaml --cfg cfg/your_cfg --weights/your_weights --name data/data.names
可使用上面的命令进行测试,需要在--name
后输入含有类别名称的文件data.names
,例如:
person
bicycle
car
可使用以下命令对图像或视频进行检测,需要在--weights
后输入训练好的权重文件,在--source
输入需要检测的图像或视频,检测结果保存在/inference/output/
下
python detect.py --img-size 512 --weights weights/your_weights --device 0 --cfg cfg/yolov4-new.cfg --names data/dota.names --source detect_image or video
部分检测结果如下:
Learning without Forgetting:https://arxiv.org/abs/1606.09282
Class-Balanced Loss Based on Effective Number of Samples:https://arxiv.org/abs/1901.05555
PyTorch_YOLOv4:https://github.com/WongKinYiu/PyTorch_YOLOv4 (PI-Det基于该代码进行改进)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。