当前位置: 首页 > news >正文

郴州网站建设有限公司seo做的很好的网站

郴州网站建设有限公司,seo做的很好的网站,微信怎么链接wordpress,html网站开发 工具欢迎关注『youcans动手学模型』系列 本专栏内容和资源同步到 GitHub/youcans 【YOLO5 项目实战】#xff08;1#xff09;YOLO5 环境配置与测试 【YOLO5 项目实战】#xff08;2#xff09;使用自己的数据集训练目标检测模型 【YOLO5 项目实战】#xff08;3#xff09;P… 欢迎关注『youcans动手学模型』系列 本专栏内容和资源同步到 GitHub/youcans 【YOLO5 项目实战】1YOLO5 环境配置与测试 【YOLO5 项目实战】2使用自己的数据集训练目标检测模型 【YOLO5 项目实战】3PCB 缺陷检测 【YOLO5 项目实战】4红外目标检测 1. 红外目标检测数据集2. 构建 YOLO 检测数据集2.1 下载 CTIR 红外道路数据集2.2 数据集格式转换2.3 数据集配置文件 3. 训练红外目标检测模型3.1 下载 YOLOv5 预训练模型3.2 修改 YOLOv5 模型配置3.3 YOLOv5 模型训练3.4 模型训练结果 4. 模型推理4.1 修改推理程序 detect.py4.2 运行推理程序检测 红外图像 5. 报错处理 1. 红外目标检测数据集 1. FLIR 红外数据集 FLIR 红外数据集是一个免费的红外图像数据集包含来自FLIR红外相机的高质量图像包括多种类型的红外图像。 官网链接https://www.flir.com/oem/adas/adas-dataset-form/ 2. VEDAI 遥感目标检测数据集 包含9种类型的遥感地物目标。每种数据包含rgb、nir2种图像共4波段。 类别9类plane,boat,camping car,car,pick-up,tractor,truck,van,other 下载地址https://downloads.greyc.fr/vedai/ 3. SUCT 远红外行人检测数据集 数据集类型远红外行人检测数据集 数据集类别walk person、ride person、squat person、people、person?、people? Githubhttps://github.com/SCUT-CV/SCUT_FIR_Pedestrian_Dataset 4. 面向空地应用的红外时敏目标检测跟踪数据集 面向红外时敏目标检测跟踪应用以车辆为探测目标以地面场景为探测背景的图像序列数据集。 下载地址http://www.doi.org/10.11922/sciencedb.j00001.00331 5. CTIR 红外道路数据集 在中国道路上收集了46个视频。 标注的11938 张红外热图像包含 34078 辆汽车Car、31035 个行人Pedestrian/Ped、16524个骑自行车人Cyclist/Cyc、2404 辆公共汽车Bus和 1886 辆卡车Truck/Tru。 下载地址https://pan.baidu.com/s/1YvDR_GP_ThzWeE9tMuigSA 提取码x6l6 2. 构建 YOLO 检测数据集 2.1 下载 CTIR 红外道路数据集 CTIR 红外数据集标注的11938 张红外热图像包含5个类别 汽车Car、行人Pedestrian、自行车Cyclist、公共汽车Bus和 卡车Truck。 数据集下载地址https://pan.baidu.com/s/1YvDR_GP_ThzWeE9tMuigSA 提取码x6l6 Image71612390238711938TrainValTestTotalCar205056828674534078Pedestrian187116136618831035Cyclist98953359327016524Bus14554794702404Truck11323873671886 2.2 数据集格式转换 CTIR 红外数据集 包括 Annotations 和 Images 两个目录分别保存 标注文件和红外图像文件.jpeg。标注文件采用 .xml 格式。 将CTIR 红外数据集转换为 YOLOv5 训练所需的格式包括 3个步骤 将图片数据集随机划分为训练数据集验证数据集和测试数据集将 .xml 格式的标注文件转化为 .txt 格式的标注文件按照训练集、验证集和测试集整理文件夹。 采用以下程序实现这些步骤。 【例程1】将图片数据集随机划分为训练数据集验证数据集和测试数据集 运行该程序后在 “…//DatasetCTIR//ImageSets” 文件夹生成 test.txt, train.txt, trainval.txt, val.txt 文件分别保存各数据集所对应的图片序号。 import os import randomROOT ..//DatasetCTIR// # IR 数据集trainval_percent 0.9 train_percent 0.9 xmlfilepath ROOT Annotations # 标注数据集文件夹 txtsavepath ROOT ImageSets # 数据集索引文件夹 if not os.path.exists(txtsavepath):os.makedirs(txtsavepath) # 获取该路径下所有文件的名称存放在list中 total_xml os.listdir(xmlfilepath)num len(total_xml) list range(num) tv int(num * trainval_percent) tr int(tv * train_percent) trainval random.sample(list, tv) train random.sample(trainval, tr)ftrainval open(ROOT ImageSets/trainval.txt, w) # 训练集验证集图片名称 ftrain open(ROOT ImageSets/train.txt, w) # 训练集图片名称 ftest open(ROOT ImageSets/test.txt, w) # 测试机图片名称 fval open(ROOT ImageSets/val.txt, w) # 验证集图片名称for i in list:# 获取文件名称中.xml之前的序号name total_xml[i][:-4] \nif i in trainval:ftrainval.write(name)if i in train:ftrain.write(name)else:fval.write(name)else:ftest.write(name)ftrainval.close() ftrain.close() fval.close() ftest.close() 【例程2】解析 .xml 标注文件将其转化为YOLOv5 所需的 .txt 格式标注文件。 xml文件包含的边界框以及图片长宽大小等信息并进行归一化写入 txt文件 import xml.etree.ElementTree as ET # xml解析包 import os# 归一化 def convert(size, box): # size:(原图w,原图h) , box:(xmin,xmax,ymin,ymax)dw 1. / size[0] # 1/wdh 1. / size[1] # 1/hx (box[0] box[1]) / 2.0 # 物体在图中的中心点x坐标y (box[2] box[3]) / 2.0 # 物体在图中的中心点y坐标w box[1] - box[0] # 物体实际像素宽度h box[3] - box[2] # 物体实际像素高度x x * dw # 物体中心点x的坐标比(相当于 x/原图w)w w * dw # 物体宽度的宽度比(相当于 w/原图w)y y * dh # 物体中心点y的坐标比(相当于 y/原图h)h h * dh # 物体宽度的宽度比(相当于 h/原图h)return (x, y, w, h) # 返回 相对于原图的物体中心点的x坐标比,y坐标比,宽度比,高度比,取值范围[0-1]# 将对应文件名的 xml文件转化为 txt 格式的标注文件 def convert_annotation(root, image_id):每张图片文件对应一个xml文件转换为一个 txt标注文件txt 文件中每行表示一个标注: class x y w h# 对应的通过year 找到相应的文件夹并且打开相应image_id的xml文件其对应bund文件in_file open(root Annotations/%s.xml %(image_id), encodingutf-8)# 准备在对应的image_id 中写入对应的label分别为# object-class x y width heightout_file open(root Labels/%s.txt %(image_id), w, encodingutf-8)# 解析xml文件tree ET.parse(in_file)# 获得对应的键值对root tree.getroot()# 获得图片的尺寸大小size root.find(size)# 如果xml内的标记为空增加判断条件if size ! None:# 获得宽w int(size.find(width).text)# 获得高h int(size.find(height).text)# 遍历目标objfor obj in root.iter(object):# 获得difficultif obj.find(difficult):difficult int(obj.find(difficult).text)else:difficult 0# 获得类别 string 类型cls obj.find(name).text# 如果类别不是对应在我们预定好的class文件中或difficult1则跳过if cls not in classes or int(difficult) 1:continue# 通过类别名称找到idcls_id classes.index(cls)# 找到bndbox 对象xmlbox obj.find(bndbox)# 获取对应的bndbox的数组 [xmin,xmax,ymin,ymax]b (float(xmlbox.find(xmin).text), float(xmlbox.find(xmax).text), float(xmlbox.find(ymin).text),float(xmlbox.find(ymax).text))print(image_id, cls, b)# 带入进行归一化操作# w 宽, h 高 b bndbox的数组 [xmin,xmax,ymin,ymax]bb convert((w, h), b)# bb 对应的是归一化后的(x,y,w,h)# 生成 calss x y w h 在label文件中out_file.write(str(cls_id) .join([str(a) for a in bb]) \n)if __name__ __main__:sets [train, test, val]classes [Car, Pedestrian, Cyclist, Bus, Truck] # 修改为训练集类别ROOT ..//DatasetCTIR// # IR 数据集if not os.path.exists(ROOT labels/): # 如果不存在 labels文件夹os.makedirs(ROOT Labels/) # 则创建 labels文件夹# 遍历数据集中的所有图片文件for image_set in sets:对所有的文件数据集进行遍历1将所有图片文件都遍历一遍并且将其所有的全路径都写在对应的txt文件中去 方便定位2同时对所有的图片文件进行解析和转化将其对应的 bundingbox 以及类别的信息全部解析写到 label 文件中去最后再通过直接读取文件 就能找到对应的 label 信息# 读取 ImageSets 中的 train, test, val 等文件列表内容image_ids open(ROOT ImageSets/%s.txt %(image_set)).read().strip().split()# 打开对应的.txt 文件准备写入list_file open(ROOT %s.txt % (image_set), w)for image_id in image_ids:# 写入对应的image_id以及路径list_file.write(ROOT Images/%s.jpg\n % (image_id))# 解析xml文件的标注格式convert_annotation(rootROOT, image_idimage_id)# 关闭文件list_file.close() 【例程3】按照训练集、验证集和测试集整理文件夹。 将原始数据集划分为训练集、测试集和验证集并重新组织。 import argparse import glob from pathlib import Path import random import shutil import os from tqdm import tqdm from concurrent.futures import ThreadPoolExecutorNUM_THREADS min(8, max(1, os.cpu_count() - 1))def run(func, this_iter, descProcessing):with ThreadPoolExecutor(max_workersNUM_THREADS, thread_name_prefixMyThread) as executor:results list(tqdm(executor.map(func, this_iter), totallen(this_iter), descdesc))return resultsdef split_dataset_into_train_val_test(dataset_dir,save_dir,train_ratio0.8,val_ratio0.1,test_ratio0.1,im_suffixjpg ):if isinstance(dataset_dir, str):dataset_dir Path(dataset_dir)image_files []for suffix in im_suffix:image_files glob.glob(str(dataset_dir / Images / f*.{suffix}))total_images len(image_files)random.shuffle(image_files)train_split int(total_images * train_ratio)val_split int(total_images * val_ratio)# test_split int(total_images * test_ratio)if train_ratio val_ratio 1:train_images image_files[:train_split]val_images image_files[train_split:]test_images []else:train_images image_files[:train_split]val_images image_files[train_split : train_split val_split]test_images image_files[train_split val_split :]print(**25)print(,fTotal images: {total_images}\n,fTrain images: {len(train_images)}\n,fVal images: {len(val_images)}\n,fTest images: {len(test_images)})print(**25)split_paths [(train, train_images), (val, val_images), (test, test_images)]print(split_paths)for split_name, images in split_paths:split_dir Path(save_dir) / split_namefor dir_name in [images, labels]:if not (split_dir / dir_name).exists():(split_dir / dir_name).mkdir(exist_okTrue, parentsTrue)args_list [(image, dataset_dir, split_dir) for image in images]run(process_image, args_list, descfCreating {split_name} dataset)print(fCreated {split_name} dataset with {len(images)} images.)def process_image(args):image_file, dataset_dir, split_dir argsannotation_file dataset_dir / labels / f{Path(image_file).stem}.txtassert annotation_file.exists(), f{annotation_file} 不存在!if not has_objects(annotation_file):returnshutil.copy(image_file, split_dir / images / Path(image_file).name)shutil.copy(annotation_file, split_dir / labels / annotation_file.name)def has_objects(annotation_path):with open(annotation_path, r) as f:lines f.readlines()return len(lines) 0if __name__ __main__:ROOT ..//DatasetCTIR// # IR 数据集parser argparse.ArgumentParser()parser.add_argument(--data, defaultROOT) # 数据集Images路径parser.add_argument(--save, defaultROOT) # 保存路径parser.add_argument(--images_suffix, default[jpg, png, jpeg], helpimages suffix) # 图片后缀名opt parser.parse_args()split_dataset_into_train_val_test(dataset_diropt.data,save_diropt.save,train_ratio0.8,val_ratio0.1,im_suffixopt.images_suffix) 运行程序生成如下目录分别保存训练集、测试集和验证集的图像与标注。 2.3 数据集配置文件 YOLOv5 模型训练时要调用数据集配置文件 YAML 文件 .yaml。因此需要创建自己的数据集配置文件 dataCTIR.yaml内容如下 train: ../DataSetCTIR/train/images val: ../DataSetCTIR/val/images test: ../DataSetCTIR/test/images # option# number of classes nc: 5# Class names names: [Car, Pedestrian, Cyclist, Bus, Truck] 其中train 表示训练集图像文件夹的路径val 表示验证集图像文件夹的路径test 表示测试集图像文件夹的路径。nc:5 表示类别数为 5names 表示 3个类别的名称。 注意nc 是由数据集的标注内容决定的不能自行修改。 3. 训练红外目标检测模型 3.1 下载 YOLOv5 预训练模型 推荐从 YOLOv5 release下载 YOLOv5 预训练模型。 本文选择 YOLOv5s参数约 7.2M。下载完成后将下载的预训练模型文件 yolov5s.pt 放在 YOLOv5 项目路径。 3.2 修改 YOLOv5 模型配置 在 yolov5/models/ 目录下打开模型配置文件 yolov5s.yaml把文件中的类别数改为 5 另存为 /models/yolov5sCTIR.yaml。 # Ultralytics YOLOv5 , AGPL-3.0 license# Parameters nc: 5 # number of classes depth_multiple: 0.33 # model depth multiple width_multiple: 0.50 # layer channel multiple anchors:- [10, 13, 16, 30, 33, 23] # P3/8- [30, 61, 62, 45, 59, 119] # P4/16- [116, 90, 156, 198, 373, 326] # P5/32 ... 3.3 YOLOv5 模型训练 1. 训练程序查看帮助 从 PyCharm 命令行输入“ python train.py -h” 可以查看帮助也可以检查程序是否有错误。 输出如下 (torch) PS C:\Python\PythonProjects\YOLOv5_PCB python train2.py -h usage: train.py [-h] [--weights WEIGHTS] [--cfg CFG] [--data DATA] [--hyp HYP] [--epochs EPOCHS] [--batch-size BATCH_SIZE] [--imgsz IMGSZ] [--rect] [--resume [RESUME]] [--nosave] [--noval] [--noautoanchor] [--noplots][--evolve [EVOLVE]] [--evolve_population EVOLVE_POPULATION] [--resume_evolve RESUME_EVOLVE] [--bucket BUCKET] [--cache [CACHE]] [--image-weights] [--device DEVICE] [--multi-scale] [--single-cls][--optimizer {SGD,Adam,AdamW}] [--sync-bn] [--workers WORKERS] [--project PROJECT] [--name NAME] [--exist-ok] [--quad] [--cos-lr] [--label-smoothing LABEL_SMOOTHING] [--patience PATIENCE][--freeze FREEZE [FREEZE ...]] [--save-period SAVE_PERIOD] [--seed SEED] [--local_rank LOCAL_RANK] [--entity ENTITY] [--upload_dataset [UPLOAD_DATASET]] [--bbox_interval BBOX_INTERVAL][--artifact_alias ARTIFACT_ALIAS] [--ndjson-console] [--ndjson-file]optional arguments:-h, --help show this help message and exit--weights WEIGHTS initial weights path--cfg CFG model.yaml path--data DATA dataset.yaml path--hyp HYP hyperparameters path--epochs EPOCHS total training epochs--batch-size BATCH_SIZEtotal batch size for all GPUs, -1 for autobatch--device DEVICE cuda device, i.e. 0 or 0,1,2,3 or cpu ... 使用自己的数据集训练 YOLOv5 模型需要注意检查以下路径或参数值 weight预训练模型权重文件先选择下载的官方权重文件 yolov5s.pt。cfgyolov5s 模型配置文件选择修改的 models/yolov5sPCB.yaml。data选择自己编写的数据集配置文件 DataSetYoloPCB/data.yaml。hyp HYP超参数文件路径可以修改模型训练参数本文未涉及。epoch整个数据集遍历训练次数根据计算机性能和需要确定默认值100新手练习时可以设为 2。batch_size每批读入的样本数量根据计算机内存确定默认值8新手练习时可以设为 2。devicecuda 显卡设置默认值为 0 表示使用 CPU训练如有 GPU 显卡可以设为 1 或相应值。 2. 修改训练程序 train.py 对于新手通过命令行直接输入模型训练参数比较麻烦也可以直接对 YOLOv5 训练程序进行修改设置模型训练的参数。 在 train.py 中对 weightcfgdata 参数进行修改另存为 train2.py parser argparse.ArgumentParser()parser.add_argument(--weights, typestr, defaultROOT / yolov5s.pt, helpinitial weights path)parser.add_argument(--cfg, typestr, defaultROOT / models/yolov5sCTIR.yaml, helpmodel.yaml path)parser.add_argument(--data, typestr, defaultROOT / data/dataCTIR.yaml, helpdataset.yaml path)parser.add_argument(--hyp, typestr, defaultROOT / data/hyps/hyp.scratch-low.yaml, helphyperparameters path)parser.add_argument(--epochs, typeint, default5, helptotal training epochs)parser.add_argument(--batch-size, typeint, default4, helptotal batch size for all GPUs, -1 for autobatch)...3. 运行训练程序 train2.py 通过命令行就可以运行 YOLOv5 训练程序 train2.py 。 如果计算机性能资源不足可以设置较小的训练参数以便学习例如 python train2.py --weights yolov5s.pt --cfg models/yolov5sCTIR.yaml --data …/DataSetCTIR/dataCTIR.yaml --epoch 2 --batch-size 2 CPU 训练速度很慢我做一次 epoch 大约要十几分钟。 使用 GPU训练设置遍历次数 epoch50批次数 batch-size32。 python train2.py --weights yolov5s.pt --cfg models/yolov5sCTIR.yaml --data …/DataSetCTIR/dataCTIR.yaml --epoch 50 --batch-size 32 --img 640 --device 1 经过100 epochs的训练结果如下 (torch) PS C:\Python\PythonProjects\YOLOv5_FLIR python train2.py --weights yolov5s.pt --cfg models/yolov5sCTIR.yaml --data ../DataSetCTIR/dataCTIR.yaml --epoch 20 --batch-size 32 --img 640 --device 1 train2: weightsyolov5s.pt, cfgmodels/yolov5sCTIR.yaml, data../DataSetCTIR/dataCTIR.yaml, hypdata\hyps\hyp.scratch-low.yaml, epochs20, batch_size32, imgsz640, rectFalse, resumeFalse, nosaveFalse, novalFalse, noautoanchorFalse, noplotsFalse, evolveNone, evolve_populationdata\hyps, resume_evolveNone, bucket, cacheNone, image_weightsFalse, device1, multi_scaleFalse, single_clsFalse, optimizerSGD, sync_bnFalse, workers8, projectruns\train, nameexp, exist_okFalse, quadFalse, cos_lrFalse, label_smoothing0.0, patience100, freeze[0], save_period-1, seed0, local_rank-1, entityNone, upload_datasetFalse, bbox_interval-1, artifact_aliaslatest, ndjson_consoleFalse, ndjson_fileFalse github: skipping check (not a git repository), for updates see https://github.com/ultralytics/yolov5 YOLOv5 2024-7-29 Python-3.8.19 torch-2.3.1cu121 CUDA:1 (NVIDIA GeForce RTX 3060, 12288MiB)hyperparameters: lr00.01, lrf0.01, momentum0.937, weight_decay0.0005, warmup_epochs3.0, warmup_momentum0.8, warmup_bias_lr0.1, box0.05, cls0.5, cls_pw1.0, obj1.0, obj_pw1.0, iou_t0.2, anchor_t4.0, fl_gamma0.0, hsv_h0.015, hsv_s0.7, hsv_v0.4, degrees0.0, translate0.1, scale0.5, shear0.0, perspective0.0, flipud0.0, fliplr0.5, mosaic1.0, mixup0.0, copy_paste0.0 Comet: run pip install comet_ml to automatically track and visualize YOLOv5 runs in Comet TensorBoard: Start with tensorboard --logdir runs\train, view at http://localhost:6006/from n params module arguments0 -1 1 3520 models.common.Conv [3, 32, 6, 2, 2]1 -1 1 18560 models.common.Conv [32, 64, 3, 2]2 -1 1 18816 models.common.C3 [64, 64, 1]3 -1 1 73984 models.common.Conv [64, 128, 3, 2]4 -1 2 115712 models.common.C3 [128, 128, 2]5 -1 1 295424 models.common.Conv [128, 256, 3, 2]6 -1 3 625152 models.common.C3 [256, 256, 3]7 -1 1 1180672 models.common.Conv [256, 512, 3, 2]8 -1 1 1182720 models.common.C3 [512, 512, 1] 9 -1 1 656896 models.common.SPPF [512, 512, 5]10 -1 1 131584 models.common.Conv [512, 256, 1, 1]11 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, nearest]12 [-1, 6] 1 0 models.common.Concat [1]13 -1 1 361984 models.common.C3 [512, 256, 1, False]14 -1 1 33024 models.common.Conv [256, 128, 1, 1]15 -1 1 0 torch.nn.modules.upsampling.Upsample [None, 2, nearest]16 [-1, 4] 1 0 models.common.Concat [1]17 -1 1 90880 models.common.C3 [256, 128, 1, False]18 -1 1 147712 models.common.Conv [128, 128, 3, 2]19 [-1, 14] 1 0 models.common.Concat [1]20 -1 1 296448 models.common.C3 [256, 256, 1, False]21 -1 1 590336 models.common.Conv [256, 256, 3, 2] 22 [-1, 10] 1 0 models.common.Concat [1]23 -1 1 1182720 models.common.C3 [512, 512, 1, False]24 [17, 20, 23] 1 26970 models.yolo.Detect [5, [[10, 13, 16, 30, 33, 23], [30, 61, 62, 45, 59, 119], [116, 90, 156, 198, 373, 326]], [128, 256, 512]] YOLOv5sCTIR summary: 214 layers, 7033114 parameters, 7033114 gradients, 16.0 GFLOPsTransferred 342/349 items from yolov5s.pt AMP: checks failed , disabling Automatic Mixed Precision. See https://github.com/ultralytics/yolov5/issues/7908 optimizer: SGD(lr0.01) with parameter groups 57 weight(decay0.0), 60 weight(decay0.0005), 60 bias train: Scanning C:\Python\PythonProjects\DataSetCTIR\train\labels.cache... 9550 images, 0 backgrounds, 0 corrupt: 100%|██████████| 9550/9550 [00:00?, ?it/s] val: Scanning C:\Python\PythonProjects\DataSetCTIR\val\labels.cache... 1193 images, 0 backgrounds, 0 corrupt: 100%|██████████| 1193/1193 [00:00?, ?it/s]AutoAnchor: 5.26 anchors/target, 1.000 Best Possible Recall (BPR). Current anchors are a good fit to dataset Plotting labels to runs\train\exp2\labels.jpg... Image sizes 640 train, 640 val Using 8 dataloader workers Logging results to runs\train\exp2 Starting training for 20 epochs...Epoch GPU_mem box_loss obj_loss cls_loss Instances Size0/19 6.92G 0.06892 0.06228 0.02963 134 640: 100%|██████████| 299/299 [01:2300:00, 3.57it/s]Class Images Instances P R mAP50 mAP50-95: 100%|██████████| 19/19 [00:0700:00, 2.41it/s]all 1193 8624 0.373 0.655 0.498 0.276Epoch GPU_mem box_loss obj_loss cls_loss Instances Size1/19 7.8G 0.05093 0.05178 0.0162 213 640: 100%|██████████| 299/299 [01:1900:00, 3.78it/s]Class Images Instances P R mAP50 mAP50-95: 100%|██████████| 19/19 [00:0800:00, 2.35it/s]all 1193 8624 0.65 0.672 0.711 0.395...Epoch GPU_mem box_loss obj_loss cls_loss Instances Size49/49 7.8G 0.02582 0.03787 0.003294 178 640: 100%|██████████| 299/299 [01:2800:00, 3.37it/s]Class Images Instances P R mAP50 mAP50-95: 100%|██████████| 19/19 [00:0800:00, 2.34it/s]all 1193 8624 0.845 0.799 0.875 0.63350 epochs completed in 1.367 hours. Optimizer stripped from runs\train\exp3\weights\last.pt, 14.4MB Optimizer stripped from runs\train\exp3\weights\best.pt, 14.4MBValidating runs\train\exp2\weights\best.pt... Fusing layers... YOLOv5sCTIR summary: 157 layers, 7023610 parameters, 0 gradients, 15.8 GFLOPsClass Images Instances P R mAP50 mAP50-95: 100%|██████████| 19/19 [00:1000:00, 1.83it/s]all 1193 8624 0.847 0.822 0.883 0.634Car 1193 3393 0.903 0.892 0.951 0.736Pedestrian 1193 3180 0.861 0.804 0.895 0.564Cyclist 1193 1619 0.886 0.876 0.931 0.625Bus 1193 282 0.82 0.84 0.877 0.663Truck 1193 150 0.766 0.698 0.762 0.58Results saved to runs\train\exp3 其中Epoch 为遍历次数box_loss 为边界框损失值obj_loss为置信度损失值cls_loss 为分类损失值Instances 为实例个数矩形框个数Size 为输入图像大小。Class 为类别名称Images 为训练图像数量Instances 为实例个数P 为准确率R为召回率mAP50为IoU阈值0.5的平均精度均值maP50-95表示在不同IoU阈值0.5~0.95的平均精度均值。 训练好的模型保存在路径“runs/exp/weights”best.pt 是最好结果last.pt 是最后结果。 3.4 模型训练结果 经过 20 轮遍历训练训练过程及结果文件保存在目录 “runs”如下图所示 1损失函数下降曲线 YOLOv5 中定义的损失函数包括 边界框定位损失box_loss计算预测边界框与标注边界框之间的误差GIoU分类损失cls_loss计算预测类别与对应的标注类别是否正确动态特征损失dfl_loss计算回归预测框与目标框之间距离的损失函数 2置信度曲线 F1 置信曲线F1得分随着置信度阈值的变化。F1得分是精确度和召回率的调和平均值曲线的峰值表示给定置信度阈值下精确度和召回率的最佳平衡点。精确度置信曲线模型预测的精确度随着置信度阈值的变化。精确度是模型预测正确正例与预测为正例总数的比值。精确度召回曲线PR曲线模型的精确度与召回率之间的关系。理想情况下模型应在精确度和召回率之间保持良好的平衡。召回置信度曲线模型的召回率随置信度阈值的变化。召回率是模型正确预测的正例与实际正例总数的比值。 训练好的模型保存在路径“runs/exp/weights”best.pt 是最好结果last.pt 是最后结果。可以使用该文件进行模型推理检测红外目标。 4. 模型推理 4.1 修改推理程序 detect.py detect.py 程序使用PyTorch加载预训练的YOLOv5模型。程序解析从命令行传入的参数这些参数包括输入文件的路径可以是图像、视频或目录、预训练模型的路径、输出文件的路径、置信度阈值等。具体用法如下 detect.py 程序默认读取 data\images 路径的图片结果默认保存到 runs/detect 文件夹中。 我们根据项目的配置要对推理程序 detect.py 进行如下修改也可以直接通过命令行参数设置 def parse_opt():parser argparse.ArgumentParser()parser.add_argument(--weights, nargs, typestr, defaultROOT / weights/YOLOv5CTIR20.pt, helpmodel path or triton URL)parser.add_argument(--source, typestr, defaultROOT / data/images, helpfile/dir/URL/glob/screen/0(webcam))parser.add_argument(--data, typestr, defaultROOT / data/dataCTIR.yaml, help(optional) dataset.yaml path) ... 注意 YOLOv5CTIR20.pt 是前面训练的 CTIR 红外检测模型的权重文件 “runs/exp/weights/best.pt”已将其另存为 “weights/YOLOv5CTIR20.pt”。“data/images” 是保存 PCB 测试图片的路径也可以使用其它图片或路径。dataFLIR.yaml 是前面修改的数据集配置文件已另存为 “data/dataCTIR.yaml”。 4.2 运行推理程序检测 红外图像 打开并运行 YOLOv5 项目中的 detect.py 程序使用训练的 红外检测模型 “weights/YOLOv5CTIR20.pt” 进行 红外图像目标检测。 python detect.py 运行输出如下 (torch) PS C:\Python\PythonProjects\YOLOv5_FLIR python detect.py detect: weightsweights\YOLOv5CTIR20.pt, sourcedata\images, datadata\dataCTIR.yaml, imgsz[640, 640], conf_thres0.25, iou_thres0.45, max_det1000, device, view_imgFalse, save_txtFalse, save_csvFalse, save_confFalse, save_cropFalse, nosaveFalse, classesNone, agnostic_nmsFalse, augmentFalse, visualizeFalse, updateFalse, projectruns\detect, nameexp, exist_okFalse, line_thickness3, hide_labelsFalse, hide_confFalse, halfFalse, dnnFalse, vid_stride1 YOLOv5 2024-7-29 Python-3.8.19 torch-2.3.1cu121 CUDA:0 (NVIDIA GeForce RTX 3060, 12288MiB)Fusing layers... YOLOv5sCTIR summary: 157 layers, 7023610 parameters, 0 gradients, 15.8 GFLOPs image 1/3 C:\Python\PythonProjects\YOLOv5_FLIR\data\images\FLIR_09135.jpeg: 512x640 3 Cars, 3 Pedestrians, 66.0ms image 2/3 C:\Python\PythonProjects\YOLOv5_FLIR\data\images\FLIR_09138.jpeg: 512x640 3 Cars, 2 Pedestrians, 4.0ms image 3/3 C:\Python\PythonProjects\YOLOv5_FLIR\data\images\FLIR_09156.jpeg: 512x640 3 Cars, 2 Pedestrians, 4.0ms Speed: 0.7ms pre-process, 24.7ms inference, 1.3ms NMS per image at shape (1, 3, 640, 640) Results saved to runs\detect\exp3检测结果保存在 “runs\detect\exp3”结果如下。性能还是很好的。 5. 报错处理 1Pytorch没有下载成功 报错内容Module Not Found Error: No module named ‘torch’ 解决方法通过 Anaconda 或 miniconda 重新下载安装 Pytorch。 2PyYaml 版本错误 报错内容AttributeError: ‘yaml’ has no attribute ‘FullLoader’ 解决方法卸载高版本 PyYaml安装 PyYaml 5.3 版本 pip install pyyaml5.3 3Git 执行发生错误 报错内容ImportError: Bad git executable. 解决方法按照报错信息找到git下的cmd文件添加下方代码 import os os.environ[GIT_PYTHON_REFRESH] quiet4Numpy 版本问题 报错内容AttributeError: module ‘numpy’ has no attribute ‘float’. 解决方法不再使用 np.float 需要将其修改为 np.float64 。 报错内容AttributeError: module ‘numpy’ has no attribute ‘int’. 解决方法不再使用 np.in 需要将其修改为 np.int32 。 【本节完】 版权声明 欢迎关注『youcans动手学模型』系列 转发请注明原文链接 【YOLO5 项目实战】4红外目标检测 Copyright 2024 youcans, XUPT Crated2024-08-20
http://www.hkea.cn/news/14266794/

相关文章:

  • 电商网站建设的步骤嘉兴百度网站推广
  • 科技类网站源码抚州公司做网站
  • 做ppt图片用的网站有哪些问题可以访问任何网站的浏览器
  • 网络广告营销织梦网站怎样做seo
  • 网站建设都分几个阶段建立网站的优势
  • 网站违规词处罚做网站的论坛用wordpress
  • 成都网站改版php做的网站模板下载地址
  • 扬中市做网站云开发和普通开发区别
  • 智能云建站网站建设的流程分析
  • 住房和城乡建设部机关服务中心重庆优化网站排名
  • cdn如何做网站统计网站的目的及功能规划
  • 做网站怎么导入地图网站优化软件排名
  • 国外购物网站排行榜华为云速建站可以做英文网站
  • 深圳网站seo优化公司自媒体平台是什么意思
  • 买域名哪个网站好如何模板建站
  • 深圳高端设计网站dede网站qq类资源源码
  • 网站悬浮框代码新乡网站搜索引擎优化
  • 上海网站建设渠道南京市建设工程造价管理处网站
  • 金属东莞网站建设技术支持重庆营销网站建设公司
  • 网站的建设项目是什么用vs做html网站
  • 北京网站建设平台百度手机助手app下载官网
  • 做搜狗手机网站点击软百度快照手机版
  • 茶网站设计素材下载西安有关做网站的公司有哪些
  • php做的汽车销售网站网络营销的常用方法有哪些
  • 贵阳网站建设zu97制作网站公司选 择乐云seo
  • 企业网站建设公司电话成都搜索建站
  • 免备案域名是危险网站首页排名seo
  • 网站关键词百度指数手机软件下载网站源码
  • 汽车租赁网站建设雄安投资建设集团有限公司网站
  • 网站开发的研究思路设计感的网站