From 635682df898b8233682ea64aa662d98e7fb16ead Mon Sep 17 00:00:00 2001 From: 17262 <1726284569@qq.com> Date: Mon, 20 Feb 2023 13:19:41 +0800 Subject: [PATCH] last change --- Datasets_Processing/SuperfluousFilesSearch.py | 13 ++++++++----- Datasets_Processing/rename.py | 6 +++--- README.md | 4 +++- mainwindow.py | 3 ++- models/common.py | 18 ++++++++++++++++++ utils/datasets.py | 2 ++ 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/Datasets_Processing/SuperfluousFilesSearch.py b/Datasets_Processing/SuperfluousFilesSearch.py index e913a3b..1695f39 100644 --- a/Datasets_Processing/SuperfluousFilesSearch.py +++ b/Datasets_Processing/SuperfluousFilesSearch.py @@ -5,8 +5,8 @@ import os -path1 = "D:/python_project/object_detection/yolov5-u/signal/images/train2017/" # path1为存储图片的文件夹JPEGImages -path2 = "D:/python_project/object_detection/yolov5-u/signal/labels/train2017/" # path2为存储标签文件的文件夹Annotations +path1 = "C:/Users/17262/Desktop/datasets/images/" # path1为存储图片的文件夹JPEGImages +path2 = "C:/Users/17262/Desktop/datasets/labels/" # path2为存储标签文件的文件夹Annotations filelist1 = os.listdir(path1) # 该文件夹下所有的文件(包括文件夹) filelist2 = os.listdir(path2) # 该文件夹下所有的文件(包括文件夹) @@ -24,12 +24,15 @@ if count == 0: Illegalfiles.append(filename1) -## 输出结果 +## 输出结果,并删除没有对应标签文件的多余图片 print('----------------------------------------') if len(Illegalfiles) != 0: - print('以下图片不存在与之对应的标签文件:') + print('以下%d张图片不存在与之对应的标签文件:'%(len(Illegalfiles))) for Illegalfile in Illegalfiles: - print(Illegalfile) + # print(Illegalfile) + os.remove(path1+Illegalfile+'.jpg') + print('Image %s.jpg has been removed.'%(Illegalfile)) + print("%d images has been removed."%(len(Illegalfiles))) else: print('所有图片均存在与之对应的标签文件') print('----------------------------------------') \ No newline at end of file diff --git a/Datasets_Processing/rename.py b/Datasets_Processing/rename.py index 77b29bb..ba96952 100644 --- a/Datasets_Processing/rename.py +++ b/Datasets_Processing/rename.py @@ -4,10 +4,10 @@ import os -path = "D:/python_project/object_detection/yolov5-u/signal/images/train2017/" # 存储图片的文件夹路径 +path = "C:/Users/17262/Desktop/datasets/red&green/" # 存储图片的文件夹路径 filelist = os.listdir(path) # 该文件夹下所有的文件(包括文件夹) -count = 1 # 确定重命名后起始图片名 +count = 10496 # 确定重命名后起始图片名 for file in filelist: # 遍历所有文件 Olddir = os.path.join(path , file) # 原来的文件路径 @@ -16,7 +16,7 @@ filename = os.path.splitext(file)[0] # 文件名 filetype = os.path.splitext(file)[1] # 文件扩展名 - Newdir = os.path.join(path,str(count).zfill(4)+filetype) # 用字符串函数zfill,以0补全所需位数,zfill()中的'6'表示图片名称为6位数字 + Newdir = os.path.join(path,str(count).zfill(5)+filetype) # 用字符串函数zfill,以0补全所需位数,zfill()中的'6'表示图片名称为6位数字 os.rename(Olddir,Newdir) # 重命名 count+=1 print('重命名完成') diff --git a/README.md b/README.md index d09fcd1..ff76b47 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,9 @@ python mainwindow.py > 注意:如果您的GPU算力有限,我们建议在使用本程序时不要使用其他程序占用GPU(如使用obs stdio进行录屏),否则会由于算力不足造成程序崩溃 本项目包含图片检测、视频检测和摄像头实时检测三个功能模块,下面为项目演示视频: -[铁路信号机视频自动识别与仿真系统演示视频](http://wang-typora.oss-cn-beijing.aliyuncs.com/img/铁路信号机视频自动识别仿真系统演示视频(终).mp4) +[道路信号机视频自动识别与仿真系统演示视频](http://wang-typora.oss-cn-beijing.aliyuncs.com/img/铁路信号机视频自动识别仿真系统演示视频(终).mp4) + +->Update:对铁路信号机进行检测的演示视频:[铁路信号机视频检测演示视频](http://wang-typora.oss-cn-beijing.aliyuncs.com/img/presentation(train)_23_02_20.mp4) ## Datasets diff --git a/mainwindow.py b/mainwindow.py index 87b962a..f7a6174 100644 --- a/mainwindow.py +++ b/mainwindow.py @@ -54,7 +54,7 @@ def __init__(self, parent=None): # 全局变量初始化 quit_flag = 0 pause_flag = 0 - weights = 'signal.pt' + weights = 'train_signal.pt' device_id = '0' camera_id = '0' play_speed = 1 @@ -584,6 +584,7 @@ def run(self): time_log.append(t3 - t0) print(f'平均每帧用时({sum(time_log) / len(time_log):.3f}s)') + root.mainloop() except FileNotFoundError: diff --git a/models/common.py b/models/common.py index d1f449e..dea3ed9 100644 --- a/models/common.py +++ b/models/common.py @@ -1,6 +1,7 @@ # YOLOv5 common modules import math +import warnings from copy import copy from pathlib import Path @@ -176,6 +177,23 @@ def forward(self, x): return self.cv2(torch.cat([x] + [m(x) for m in self.m], 1)) +class SPPF(nn.Module): + # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher + def __init__(self, c1, c2, k=5): # equivalent to SPP(k=(5, 9, 13)) + super().__init__() + c_ = c1 // 2 # hidden channels + self.cv1 = Conv(c1, c_, 1, 1) + self.cv2 = Conv(c_ * 4, c2, 1, 1) + self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2) + + def forward(self, x): + x = self.cv1(x) + with warnings.catch_warnings(): + warnings.simplefilter('ignore') # suppress torch 1.9.0 max_pool2d() warning + y1 = self.m(x) + y2 = self.m(y1) + return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1)) + class Focus(nn.Module): # Focus wh information into c-space def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True): # ch_in, ch_out, kernel, stride, padding, groups diff --git a/utils/datasets.py b/utils/datasets.py index 7b90f97..7da0285 100644 --- a/utils/datasets.py +++ b/utils/datasets.py @@ -545,11 +545,13 @@ def __getitem__(self, index): if mosaic: # Load mosaic img, labels = load_mosaic(self, index) + # img, labels = load_mosaic9(self, index) shapes = None # MixUp https://arxiv.org/pdf/1710.09412.pdf if random.random() < hyp['mixup']: img2, labels2 = load_mosaic(self, random.randint(0, self.n - 1)) + # img2, labels2 = load_mosaic9(self, random.randint(0, self.n - 1)) r = np.random.beta(8.0, 8.0) # mixup ratio, alpha=beta=8.0 img = (img * r + img2 * (1 - r)).astype(np.uint8) labels = np.concatenate((labels, labels2), 0)