Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
  • Loading branch information
wang-10086 committed Feb 20, 2023
2 parents 7f4f788 + 635682d commit 10d7db0
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
13 changes: 8 additions & 5 deletions Datasets_Processing/SuperfluousFilesSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) # 该文件夹下所有的文件(包括文件夹)
Expand All @@ -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('----------------------------------------')
6 changes: 3 additions & 3 deletions Datasets_Processing/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) # 原来的文件路径
Expand All @@ -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('重命名完成')
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ python mainwindow.py
本项目包含图片检测、视频检测和摄像头实时检测三个功能模块,下面为项目演示视频:
[道路信号机视频自动识别与仿真系统演示视频](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)
->Update:对铁路信号机进行检测的演示视频:[铁路信号机视频检测演示视频](http://wang-typora.oss-cn-beijing.aliyuncs.com/img/presentation(train)_23_02_20.mp4)

## Datasets

Expand Down
1 change: 1 addition & 0 deletions mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ def run(self):
time_log.append(t3 - t0)

print(f'平均每帧用时({sum(time_log) / len(time_log):.3f}s)')

root.mainloop()

except FileNotFoundError:
Expand Down
18 changes: 18 additions & 0 deletions models/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# YOLOv5 common modules

import math
import warnings
from copy import copy
from pathlib import Path

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions utils/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 10d7db0

Please sign in to comment.