时间:2025-07-25 作者:游乐小编
该项目对2898幅红外热图像进行目标检测,先调整数据集格式,将原test、train、val数据融合后按7:3划分为训练集和验证集,转换为VOC格式。选用PP-YOLOE模型,修改配置文件后训练,评估得mAP为76.60%,未达0.8以上,最后用最佳模型进行了预测。
数据集包含从43470帧中提取的2898幅红外热图像,这些图像由无人机从不同场景(学校、停车场、道路、操场等)捕捉到,涵盖范围广泛,包括物体(人、自行车、汽车、其他车辆)、飞行高度数据(60至130米)、相机透视数据(30至90度)和日光强度(白天和晚上),该次任务主要是自行调整数据集格式,并将给定数据集按7:3的比例划分为训练集和验证集,选择合适的模型,并且在划分的验证集下面评估的map达到0.8以上
Clone 代码库和安装 requirements.txt,环境需要在一个 Python>=3.7.0 下的环境,且需要安装 PaddlePaddle>=2.3.2。将代码clone到work目录下去,我们选择的是PaddleDetection,PaddleDetection相关介绍可以参考:https://github.com/PaddlePaddle/PaddleDetection, 进行clone PaddleDetection代码,我这里已经下载好了,直接解压就行,按照要求进行准备环境
In [1]#!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/simpleRequirement 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 typeguard Downloading 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.0 Downloading 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) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.5/60.5 MB 2.0 MB/s eta 0:00:0000:0100:01Requirement 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 pycocotools Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ef/c6/90220be3b39fbc4cbd203775ca47dd8dc97fae06fbd2b500637395621b7c/pycocotools-2.0.6.tar.gz (24 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Preparing metadata (pyproject.toml) ... doneRequirement 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 lap Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bf/64/d9fb6a75b15e783952b2fec6970f033462e67db32dc43dfbb404c14e91c2/lap-0.4.0.tar.gz (1.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 1.4 MB/s eta 0:00:0000:0100:01 Preparing metadata (setup.py) ... doneCollecting motmetrics Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2f/d9/7b77e1e2db80b6f8133065ffbccdaa3c911df5f95a7af30829fcaa10a3d7/motmetrics-1.4.0-py3-none-any.whl (161 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 161.5/161.5 kB 1.7 MB/s eta 0:00:00a 0:00:01Requirement 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 pyclipper Downloading 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) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 604.2/604.2 kB 1.1 MB/s eta 0:00:00a 0:00:01Requirement 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.0 Downloading 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.0 Downloading 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, lap Building wheel for pycocotools (pyproject.toml) ... done Created wheel for pycocotools: filename=pycocotools-2.0.6-cp37-cp37m-linux_x86_64.whl size=275122 sha256=eabe5690b267eaaa5d1922f61f11feda71210995782667a0e58fe38a65d7614b Stored in directory: /home/aistudio/.cache/pip/wheels/f8/94/70/046149e666bd5812b7de6b87a28dcef238f7162f4108e0b3d8 Building wheel for lap (setup.py) ... done Created wheel for lap: filename=lap-0.4.0-cp37-cp37m-linux_x86_64.whl size=1593873 sha256=6a60a92df414102efcf89f0d1a318c555f45e009f6876daaaf50887e8fc33a0c Stored in directory: /home/aistudio/.cache/pip/wheels/5c/d0/d2/e331d17a999666b1e2eb99743cfa1742629f9d26c55c657001Successfully built pycocotools lapInstalling collected packages: pyclipper, lap, xmltodict, typing-extensions, opencv-python, typeguard, pycocotools, motmetrics Attempting uninstall: typing-extensions Found existing installation: typing_extensions 4.3.0 Uninstalling typing_extensions-4.3.0: Successfully uninstalled typing_extensions-4.3.0 Attempting uninstall: opencv-python Found existing installation: opencv-python 4.6.0.66 Uninstalling opencv-python-4.6.0.66:ERROR: Could not install packages due to an OSError: [Errno 13] 权限不够: '__init__.py'Consider using the `--user` option or check the permissions.[notice] A new release of pip available: 22.1.2 -> 23.0.1[notice] To update, run: pip install --upgrade pip登录后复制
数据挂载的目录为/home/aistudio/data/data191179/HIT-UAV.zip,将挂载的数据集解压到work/datasets/到目录下去
In [ ]!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比例的训练集和验证集,所以我们需要调整这个数据集,来达到我们任务的需求,先将所有的数据融合在一起,执行以下代码:
In [10]!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:
In [11]from xml.dom.minidom import Documentimport osimport 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.shape folder = 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子标签width widthcontent = xmlBuilder.createTextNode(str(Pwidth)) width.appendChild(widthcontent) size.appendChild(width) # size子标签width结束 height = xmlBuilder.createElement("height") # size子标签height heightcontent = xmlBuilder.createTextNode(str(Pheight)) height.appendChild(heightcontent) size.appendChild(height) # size子标签height结束 depth = xmlBuilder.createElement("depth") # size子标签depth depthcontent = 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)登录后复制
将数据转换完成后,我们按照训练集和测试集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 (测试数据集文件列表)登录后复制 In [12]
!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:
In [13]import osimport randomimgs_path = r"/home/aistudio/work/datasets/hit-uav/images" #所有数据图片xmls_path = r"/home/aistudio/work/datasets/hit-uav/labels" #所有xmlsave_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.7trainNum = 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都已经准备好了
In [ ]!cp /home/aistudio/work/label_list.txt /home/aistudio/work/datasets/hit-uav/登录后复制
大致观察了一下数据集的内容,发现这个任务是一个比较简单目标检测的任务,我这里选用的是PP-YOLOE来进行训练
对应的配置文件路径为configs/ppyoloe/voc/ppyoloe_plus_crn_s_30e_voc.yml,可以打开发现使用的voc配置文件路径为configs/datasets/voc.yml,将其中的数据集路径和类别改为自己数据集:
metric: VOCmap_type: 11pointnum_classes: 5TrainDataset: name: VOCDataSet dataset_dir: /home/aistudio/work/datasets/hit-uav anno_path: train.txt label_list: label_list.txt data_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']EvalDataset: name: VOCDataSet dataset_dir: /home/aistudio/work/datasets/hit-uav anno_path: valid.txt label_list: label_list.txt data_fields: ['image', 'gt_bbox', 'gt_class', 'difficult']TestDataset: name: ImageFolder anno_path: /home/aistudio/work/datasets/hit-uav/label_list.txt登录后复制
训练命令参考如下:
In [ ]!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 2024-03-27 17:49:18,173 Pod completedLAUNCH INFO 2024-03-27 17:49:18,174 Exit code 0登录后复制
这里选用训练时综合表现最好的模型进行评估
In [ ]# !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.2W0327 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登录后复制
训练完成后,在/home/aistudio/work/PaddleDetection-release-2.6/output/ppyoloe_plus_crn_s_30e_voc路径下保存了训练之后的权重文件,我们使用表现最好的模型进行预测,预测命令参考如下:
In [19]# 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 working from 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 working from 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 working from collections import SizedWarning: Unable to use MOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetricsWarning: Unable to use MCMOT metric, please install motmetrics, for example: `pip install motmetrics`, see https://github.com/longcw/py-motmetricsWarning: import ppdet from source directory without installing, run 'python setup.py install' to install ppdet firstlyW0316 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.2W0316 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.pdparams100%|█████████████████████████████████████████████| 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登录后复制
预测结果如下:
2021-11-05 11:52
手游攻略2021-11-19 18:38
手游攻略2021-10-31 23:18
手游攻略2022-06-03 14:46
游戏资讯2025-06-28 12:37
单机攻略