本文主要是介绍【特训营第三期】无人机高空红外检测,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
★★★ 本文源自AlStudio社区精品项目,【点击此处】查看更多精品内容 >>>
1. 项目介绍
数据集包含从43470帧中提取的2898幅红外热图像,这些图像由无人机从不同场景(学校、停车场、道路、操场等)捕捉到,涵盖范围广泛,包括物体(人、自行车、汽车、其他车辆)、飞行高度数据(60至130米)、相机透视数据(30至90度)和日光强度(白天和晚上),该次任务主要是自行调整数据集格式,并将给定数据集按7:3的比例划分为训练集和验证集,选择合适的模型,并且在划分的验证集下面评估的map达到0.8以上
2. 环境准备
Clone 代码库和安装 requirements.txt,环境需要在一个 Python>=3.7.0 下的环境,且需要安装 PaddlePaddle>=2.3.2。将代码clone到work目录下去,我们选择的是PaddleDetection,PaddleDetection相关介绍可以参考:https://github.com/PaddlePaddle/PaddleDetection, 进行clone PaddleDetection代码,我这里已经下载好了,直接解压就行,按照要求进行准备环境
#!cd work && git clone https://github.com/PaddlePaddle/PaddleDetection.git # clone
# !cd work && unzip PaddleDetection.zip
# 如果需要进行持久化安装, 需要使用持久化路径, 如下方代码示例:
# !mkdir /home/aistudio/external-libraries
!cd work/PaddleDetection-release-2.6 && pip install -r requirements.txt
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: numpy<1.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (1.19.5)
Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (4.64.1)
Collecting typeguardDownloading https://pypi.tuna.tsinghua.edu.cn/packages/7b/e8/45557d50fb6ab2d503a9b64320aa1a848ae1d5529bc659a9936e50daf856/typeguard-3.0.1-py3-none-any.whl (30 kB)
Requirement already satisfied: visualdl>=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 4)) (2.4.0)
Collecting opencv-python<=4.6.0Downloading https://pypi.tuna.tsinghua.edu.cn/packages/67/50/665a503167396ad347957bea0bd8d5c08c865030b2d1565ff06eba613780/opencv_python-4.5.5.64-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (60.5 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m60.5/60.5 MB[0m [31m2.0 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25hRequirement already satisfied: PyYAML in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 6)) (5.1.2)
Requirement already satisfied: shapely in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (2.0.0)
Requirement already satisfied: scipy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 8)) (1.6.3)
Requirement already satisfied: terminaltables in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 9)) (3.1.10)
Requirement already satisfied: Cython in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 10)) (0.29)
Collecting pycocotoolsDownloading https://pypi.tuna.tsinghua.edu.cn/packages/ef/c6/90220be3b39fbc4cbd203775ca47dd8dc97fae06fbd2b500637395621b7c/pycocotools-2.0.6.tar.gz (24 kB)Installing build dependencies ... [?25ldone
[?25h Getting requirements to build wheel ... [?25ldone
[?25h Preparing metadata (pyproject.toml) ... [?25ldone
[?25hRequirement already satisfied: setuptools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 12)) (56.2.0)
Collecting lapDownloading https://pypi.tuna.tsinghua.edu.cn/packages/bf/64/d9fb6a75b15e783952b2fec6970f033462e67db32dc43dfbb404c14e91c2/lap-0.4.0.tar.gz (1.5 MB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m1.5/1.5 MB[0m [31m1.4 MB/s[0m eta [36m0:00:00[0m00:01[0m00:01[0m
[?25h Preparing metadata (setup.py) ... [?25ldone
[?25hCollecting motmetricsDownloading https://pypi.tuna.tsinghua.edu.cn/packages/2f/d9/7b77e1e2db80b6f8133065ffbccdaa3c911df5f95a7af30829fcaa10a3d7/motmetrics-1.4.0-py3-none-any.whl (161 kB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m161.5/161.5 kB[0m [31m1.7 MB/s[0m eta [36m0:00:00[0ma [36m0:00:01[0m
[?25hRequirement already satisfied: sklearn==0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 17)) (0.0)
Collecting pyclipperDownloading https://pypi.tuna.tsinghua.edu.cn/packages/21/b9/f8bd7bb8b04906ac2f93518ae22040c99db9dfc9faf2a29d444c6469b6a3/pyclipper-1.3.0.post4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (604 kB)
[2K [90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[0m [32m604.2/604.2 kB[0m [31m1.1 MB/s[0m eta [36m0:00:00[0ma [36m0:00:01[0m
[?25hRequirement already satisfied: scikit-learn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from sklearn==0.0->-r requirements.txt (line 17)) (0.24.2)
Collecting typing-extensions>=4.4.0Downloading https://pypi.tuna.tsinghua.edu.cn/packages/31/25/5abcd82372d3d4a3932e1fa8c3dbf9efac10cc7c0d16e78467460571b404/typing_extensions-4.5.0-py3-none-any.whl (27 kB)
Requirement already satisfied: importlib-metadata>=3.6 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from typeguard->-r requirements.txt (line 3)) (4.2.0)
Requirement already satisfied: requests in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 4)) (2.24.0)
Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 4)) (0.8.53)
Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 4)) (2.2.3)
Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 4)) (1.0.0)
Requirement already satisfied: Pillow>=7.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 4)) (8.2.0)
Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 4)) (1.1.1)
Requirement already satisfied: protobuf>=3.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 4)) (3.20.0)
Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 4)) (1.1.5)
Requirement already satisfied: six>=1.14.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl>=2.2.0->-r requirements.txt (line 4)) (1.16.0)
Collecting xmltodict>=0.12.0Downloading https://pypi.tuna.tsinghua.edu.cn/packages/94/db/fd0326e331726f07ff7f40675cd86aa804bfd2e5016c727fa761c934990e/xmltodict-0.13.0-py2.py3-none-any.whl (10.0 kB)
Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 4)) (0.16.0)
Requirement already satisfied: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 4)) (8.0.4)
Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 4)) (3.0.0)
Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 4)) (1.1.0)
Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.2.0->-r requirements.txt (line 4)) (2.8.0)
Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl>=2.2.0->-r requirements.txt (line 4)) (2019.3)
Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata>=3.6->typeguard->-r requirements.txt (line 3)) (3.8.1)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 4)) (3.0.9)
Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 4)) (1.1.0)
Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 4)) (2.8.2)
Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl>=2.2.0->-r requirements.txt (line 4)) (0.10.0)
Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.2.0->-r requirements.txt (line 4)) (3.9.9)
Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl>=2.2.0->-r requirements.txt (line 4)) (0.18.0)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 4)) (2019.9.11)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 4)) (1.25.11)
Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 4)) (2.8)
Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests->visualdl>=2.2.0->-r requirements.txt (line 4)) (3.0.4)
Requirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn==0.0->-r requirements.txt (line 17)) (2.1.0)
Requirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn==0.0->-r requirements.txt (line 17)) (0.14.1)
Requirement already satisfied: MarkupSafe>=2.0.0rc2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl>=2.2.0->-r requirements.txt (line 4)) (2.0.1)
Building wheels for collected packages: pycocotools, lapBuilding wheel for pycocotools (pyproject.toml) ... [?25ldone
[?25h Created wheel for pycocotools: filename=pycocotools-2.0.6-cp37-cp37m-linux_x86_64.whl size=275122 sha256=eabe5690b267eaaa5d1922f61f11feda71210995782667a0e58fe38a65d7614bStored in directory: /home/aistudio/.cache/pip/wheels/f8/94/70/046149e666bd5812b7de6b87a28dcef238f7162f4108e0b3d8Building wheel for lap (setup.py) ... [?25ldone
[?25h Created wheel for lap: filename=lap-0.4.0-cp37-cp37m-linux_x86_64.whl size=1593873 sha256=6a60a92df414102efcf89f0d1a318c555f45e009f6876daaaf50887e8fc33a0cStored in directory: /home/aistudio/.cache/pip/wheels/5c/d0/d2/e331d17a999666b1e2eb99743cfa1742629f9d26c55c657001
Successfully built pycocotools lap
Installing collected packages: pyclipper, lap, xmltodict, typing-extensions, opencv-python, typeguard, pycocotools, motmetricsAttempting uninstall: typing-extensionsFound existing installation: typing_extensions 4.3.0Uninstalling typing_extensions-4.3.0:Successfully uninstalled typing_extensions-4.3.0Attempting uninstall: opencv-pythonFound existing installation: opencv-python 4.6.0.66Uninstalling opencv-python-4.6.0.66:
[31mERROR: Could not install packages due to an OSError: [Errno 13] 权限不够: '__init__.py'
Consider using the `--user` option or check the permissions.
[0m[31m
[0m
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m A new release of pip available: [0m[31;49m22.1.2[0m[39;49m -> [0m[32;49m23.0.1[0m
[1m[[0m[34;49mnotice[0m[1;39;49m][0m[39;49m To update, run: [0m[32;49mpip install --upgrade pip[0m
3. 数据准备
3.1 分析数据
数据挂载的目录为/home/aistudio/data/data191179/HIT-UAV.zip,将挂载的数据集解压到work/datasets/到目录下去
!mkdir work/datasets
!unzip -d work/datasets/ /home/aistudio/data/data191179/HIT-UAV.zip
数据集部分图片展示如下:
解压后的数据集路径为/home/aistudio/work/datasets/hit-uav,观察数据集,发现数据集已经划分为了test,train,val三个部分,图片数量为571, 2008, 287,不满足7:3比例的训练集和验证集,所以我们需要调整这个数据集,来达到我们任务的需求,先将所有的数据融合在一起,执行以下代码:
!mv /home/aistudio/work/datasets/hit-uav/images/test/* /home/aistudio/work/datasets/hit-uav/images/val/
!mv /home/aistudio/work/datasets/hit-uav/labels/test/* /home/aistudio/work/datasets/hit-uav/labels/val/!mv /home/aistudio/work/datasets/hit-uav/images/val/* /home/aistudio/work/datasets/hit-uav/images/train/
!mv /home/aistudio/work/datasets/hit-uav/labels/val/* /home/aistudio/work/datasets/hit-uav/labels/train/
同时观察数据格式是yolo格式,不满足paddleDetection需要的voc或者coco的数据格式,这里需要做一个数据格式转换,转换脚本可以参考adjustData.py:
from xml.dom.minidom import Document
import os
import cv2# def makexml(txtPath, xmlPath, picPath): # txt所在文件夹路径,xml文件保存路径,图片所在文件夹路径
def makexml(picPath, txtPath, xmlPath): # txt所在文件夹路径,xml文件保存路径,图片所在文件夹路径"""此函数用于将yolo格式txt标注文件转换为voc格式xml标注文件在自己的标注图片文件夹下建三个子文件夹,分别命名为picture、txt、xml"""dic = {'0': "Person",'1': "Car", # 创建字典用来对类型进行转换'2': "Bicycle", # 此处的字典要与自己的classes.txt文件中的类对应,且顺序要一致'3': "OtherVehicle",'4': "DontCare"}files = os.listdir(txtPath)for i, name in enumerate(files):xmlBuilder = Document()annotation = xmlBuilder.createElement("annotation") # 创建annotation标签xmlBuilder.appendChild(annotation)txtFile = open(txtPath + name)txtList = txtFile.readlines()img = cv2.imread(picPath + name[0:-4] + ".jpg")Pheight, Pwidth, Pdepth = img.shapefolder = xmlBuilder.createElement("folder") # folder标签foldercontent = xmlBuilder.createTextNode("driving_annotation_dataset")folder.appendChild(foldercontent)annotation.appendChild(folder) # folder标签结束filename = xmlBuilder.createElement("filename") # filename标签filenamecontent = xmlBuilder.createTextNode(name[0:-4] + ".jpg")filename.appendChild(filenamecontent)annotation.appendChild(filename) # filename标签结束size = xmlBuilder.createElement("size") # size标签width = xmlBuilder.createElement("width") # size子标签widthwidthcontent = xmlBuilder.createTextNode(str(Pwidth))width.appendChild(widthcontent)size.appendChild(width) # size子标签width结束height = xmlBuilder.createElement("height") # size子标签heightheightcontent = xmlBuilder.createTextNode(str(Pheight))height.appendChild(heightcontent)size.appendChild(height) # size子标签height结束depth = xmlBuilder.createElement("depth") # size子标签depthdepthcontent = xmlBuilder.createTextNode(str(Pdepth))depth.appendChild(depthcontent)size.appendChild(depth) # size子标签depth结束annotation.appendChild(size) # size标签结束for j in txtList:oneline = j.strip().split(" ")object = xmlBuilder.createElement("object") # object 标签picname = xmlBuilder.createElement("name") # name标签namecontent = xmlBuilder.createTextNode(dic[oneline[0]])picname.appendChild(namecontent)object.appendChild(picname) # name标签结束pose = xmlBuilder.createElement("pose") # pose标签posecontent = xmlBuilder.createTextNode("Unspecified")pose.appendChild(posecontent)object.appendChild(pose) # pose标签结束truncated = xmlBuilder.createElement("truncated") # truncated标签truncatedContent = xmlBuilder.createTextNode("0")truncated.appendChild(truncatedContent)object.appendChild(truncated) # truncated标签结束difficult = xmlBuilder.createElement("difficult") # difficult标签difficultcontent = xmlBuilder.createTextNode("0")difficult.appendChild(difficultcontent)object.appendChild(difficult) # difficult标签结束bndbox = xmlBuilder.createElement("bndbox") # bndbox标签xmin = xmlBuilder.createElement("xmin") # xmin标签mathData = int(((float(oneline[1])) * Pwidth + 1) - (float(oneline[3])) * 0.5 * Pwidth)xminContent = xmlBuilder.createTextNode(str(mathData))xmin.appendChild(xminContent)bndbox.appendChild(xmin) # xmin标签结束ymin = xmlBuilder.createElement("ymin") # ymin标签mathData = int(((float(oneline[2])) * Pheight + 1) - (float(oneline[4])) * 0.5 * Pheight)yminContent = xmlBuilder.createTextNode(str(mathData))ymin.appendChild(yminContent)bndbox.appendChild(ymin) # ymin标签结束xmax = xmlBuilder.createElement("xmax") # xmax标签mathData = int(((float(oneline[1])) * Pwidth + 1) + (float(oneline[3])) * 0.5 * Pwidth)xmaxContent = xmlBuilder.createTextNode(str(mathData))xmax.appendChild(xmaxContent)bndbox.appendChild(xmax) # xmax标签结束ymax = xmlBuilder.createElement("ymax") # ymax标签mathData = int(((float(oneline[2])) * Pheight + 1) + (float(oneline[4])) * 0.5 * Pheight)ymaxContent = xmlBuilder.createTextNode(str(mathData))ymax.appendChild(ymaxContent)bndbox.appendChild(ymax) # ymax标签结束object.appendChild(bndbox) # bndbox标签结束annotation.appendChild(object) # object标签结束f = open(xmlPath + name[0:-4] + ".xml", 'w')xmlBuilder.writexml(f, indent='\t', newl='\n', addindent='\t', encoding='utf-8')f.close()if __name__ == "__main__":picPath = "/home/aistudio/work/datasets/hit-uav/images/train/"txtPath = "/home/aistudio/work/datasets/hit-uav/labels/train/"xmlPath = "/home/aistudio/work/datasets/hit-uav/labels/Annotations/"if not os.path.exists(xmlPath):os.mkdir(xmlPath)makexml(picPath, txtPath, xmlPath)
3.2 整理数据
将数据转换完成后,我们按照训练集和测试集7:3的比例进行分割图片和标签,并按照voc的目录结构整理数据集,voc数据集目录如下:
dataset/xxx/
├── annotations
│ ├── xxx1.xml
│ ├── xxx2.xml
│ ├── xxx3.xml
│ | ...
├── images
│ ├── xxx1.jpg
│ ├── xxx2.jpg
│ ├── xxx3.jpg
│ | ...
├── label_list.txt (必须提供,且文件名称必须是label_list.txt )
├── train.txt (训练数据集文件列表, ./images/xxx1.jpg ./annotations/xxx1.xml)
└── valid.txt (测试数据集文件列表)
!cd /home/aistudio/work/datasets/hit-uav/images && rm -r test val && mv train/* ./ && rm -r train !cd /home/aistudio/work/datasets/hit-uav/labels && rm -r test val train && mv Annotations/* ./ && rm -r Annotations
使用脚本将数据集划分,参考脚本SplitData.py,制作train.txt与valid.txt:
import os
import random
imgs_path = r"/home/aistudio/work/datasets/hit-uav/images" #所有数据图片
xmls_path = r"/home/aistudio/work/datasets/hit-uav/labels" #所有xml
save_path = r"/home/aistudio/work/datasets/hit-uav"def write_File(txt_path, imgsList):with open(txt_path, "w") as F:for img_name in imgsList:xml_name = img_name.split(".")[0] + ".xml"img_path = os.path.join(imgs_path, img_name)xml_path = os.path.join(xmls_path, xml_name)F.write(f"{img_path} {xml_path}\n")imgsList = os.listdir(imgs_path)
dataLen = len(imgsList)
rate = 0.7
trainNum = int(dataLen * rate)trainList = random.sample(imgsList,trainNum)
for name in trainList:imgsList.remove(name)
valList = imgsListtrain_txt_path = os.path.join(save_path, "train.txt")
val_txt_path = os.path.join(save_path, "valid.txt")write_File(train_txt_path, trainList)
write_File(val_txt_path, valList)
接着制作label_list.txt,label_list.txt主要是放标签的类别,这里参考dataset.yaml文件,直接写一个label_list.txt的文件即可,放在/home/aistudio/work/datasets/hit-uav目录下,至此,所有的txt都已经准备好了
!cp /home/aistudio/work/label_list.txt /home/aistudio/work/datasets/hit-uav/
4. 训练
4.1 选取模型
大致观察了一下数据集的内容,发现这个任务是一个比较简单目标检测的任务,我这里选用的是PP-YOLOE来进行训练
4.2 修改配置文件
对应的配置文件路径为configs/ppyoloe/voc/ppyoloe_plus_crn_s_30e_voc.yml,可以打开发现使用的voc配置文件路径为configs/datasets/voc.yml,将其中的数据集路径和类别改为自己数据集:
metric: VOC
map_type: 11point
num_classes: 5TrainDataset:name: VOCDataSetdataset_dir: /home/aistudio/work/datasets/hit-uavanno_path: train.txtlabel_list: label_list.txtdata_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']EvalDataset:name: VOCDataSetdataset_dir: /home/aistudio/work/datasets/hit-uavanno_path: valid.txtlabel_list: label_list.txtdata_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']TestDataset:name: ImageFolderanno_path: /home/aistudio/work/datasets/hit-uav/label_list.txt
4.3开始训练
训练命令参考如下:
!pip install pycocotools
!cd /home/aistudio/work/PaddleDetection-release-2.6 && python -m paddle.distributed.launch tools/train.py -c configs/ppyoloe/voc/ppyoloe_plus_crn_s_30e_voc.yml --eval
[03/27 17:46:39] ppdet.engine INFO: Epoch: [99] [ 0/250] learning_rate: 0.000000 loss: 1.478661 loss_cls: 0.675399 loss_iou: 0.190062 loss_dfl: 0.650721 loss_l1: 0.242178 eta: 0:01:30 batch_cost: 0.3718 data_cost: 0.0218 ips: 21.5151 images/s
[03/27 17:47:28] ppdet.engine INFO: Epoch: [99] [100/250] learning_rate: 0.000000 loss: 1.461851 loss_cls: 0.679879 loss_iou: 0.182444 loss_dfl: 0.655111 loss_l1: 0.234927 eta: 0:00:54 batch_cost: 0.3825 data_cost: 0.0017 ips: 20.9153 images/s
[03/27 17:48:15] ppdet.engine INFO: Epoch: [99] [200/250] learning_rate: 0.000000 loss: 1.503901 loss_cls: 0.688840 loss_iou: 0.193698 loss_dfl: 0.650233 loss_l1: 0.251345 eta: 0:00:18 batch_cost: 0.3548 data_cost: 0.0011 ips: 22.5503 images/s
[03/27 17:48:38] ppdet.utils.checkpoint INFO: Save checkpoint: output/ppyoloe_plus_crn_s_30e_voc
[03/27 17:48:38] ppdet.engine INFO: Eval iter: 0
[03/27 17:48:55] ppdet.engine INFO: Eval iter: 100
[03/27 17:49:10] ppdet.engine INFO: Eval iter: 200
[03/27 17:49:12] ppdet.metrics.metrics INFO: Accumulating evaluatation results...
[03/27 17:49:14] ppdet.metrics.metrics INFO: mAP(0.50, 11point) = 76.57%
[03/27 17:49:14] ppdet.engine INFO: Total sample number: 860, average FPS: 25.12995198704822
[03/27 17:49:14] ppdet.engine INFO: Best test bbox ap is 0.766.
LAUNCH INFO 2023-03-27 17:49:18,173 Pod completed
LAUNCH INFO 2023-03-27 17:49:18,174 Exit code 0
4.4 开始评估
这里选用训练时综合表现最好的模型进行评估
# !pip install pycocotools
!cd /home/aistudio/work/PaddleDetection-release-2.6 && python tools/eval.py -c configs/ppyoloe/voc/ppyoloe_plus_crn_s_30e_voc.yml -o weights=output/ppyoloe_plus_crn_s_30e_voc/best_model.pdparams
评估结果如下:
W0327 22:50:30.666767 800 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.2
W0327 22:50:30.671360 800 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.
[03/27 22:50:33] ppdet.utils.checkpoint INFO: Finish loading model weights: output/ppyoloe_plus_crn_s_30e_voc/best_model.pdparams
[03/27 22:50:35] ppdet.engine INFO: Eval iter: 0
[03/27 22:50:46] ppdet.engine INFO: Eval iter: 100
[03/27 22:50:58] ppdet.engine INFO: Eval iter: 200
[03/27 22:50:59] ppdet.metrics.metrics INFO: Accumulating evaluatation results...
[03/27 22:51:01] ppdet.metrics.metrics INFO: mAP(0.50, 11point) = 76.60%
[03/27 22:51:01] ppdet.engine INFO: Total sample number: 860, average FPS: 32.777653149867966
4.5 开始预测
训练完成后,在/home/aistudio/work/PaddleDetection-release-2.6/output/ppyoloe_plus_crn_s_30e_voc路径下保存了训练之后的权重文件,我们使用表现最好的模型进行预测,预测命令参考如下:
# inference single image
!cd /home/aistudio/work/PaddleDetection-release-2.6 && CUDA_VISIBLE_DEVICES=0 python tools/infer.py -c configs/ppyoloe/voc/ppyoloe_plus_crn_s_30e_voc.yml -o weights=/home/aistudio/work/PaddleDetection-release-2.6/output/ppyoloe_plus_crn_s_30e_voc/best_model.pdparams --infer_img=/home/aistudio/work/datasets/hit-uav/images/0_100_80_0_08238.jpg
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/__init__.py:107: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop workingfrom collections import MutableMapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/rcsetup.py:20: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop workingfrom collections import Iterable, Mapping
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/matplotlib/colors.py:53: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop workingfrom collections import Sized
Warning: Unable to use MOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics
Warning: Unable to use MCMOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetrics
Warning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstly
W0316 19:06:54.391429 28048 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.2
W0316 19:06:54.396050 28048 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.
[03/16 19:06:56] ppdet.utils.checkpoint INFO: Finish loading model weights: /home/aistudio/work/PaddleDetection-release-2.6/output/ppyoloe_plus_crn_s_30e_voc/best_model.pdparams
100%|█████████████████████████████████████████████| 1/1 [00:01<00:00, 1.30s/it]
[03/16 19:06:57] ppdet.engine INFO: Detection bbox results save in output/0_100_80_0_08238.jpg
t]
[03/16 19:06:57] ppdet.engine INFO: Detection bbox results save in output/0_100_80_0_08238.jpg
预测结果如下:
5. 感谢
感谢胡雷导师在这个过程中的指导
导师:胡雷
学员:丶蝶恋花 - 杨苈钰
请点击此处查看本环境基本用法.
Please click here for more detailed instructions.
此文章为转载
原文链接
这篇关于【特训营第三期】无人机高空红外检测的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!