CSTDB数据集介绍
Dataset consists of 5998 traffic sign images of 58 categories. Each image is a zoomed view of single traffic sign. Annotations provide image properties (file_name, width, height) as well as traffic sign coordinates within image and category (e.g. 5 km/h speed limit)
- 每个对象一行
- 每一行是 class x_center y_center width height 格式。
方框坐标必须在 归一化 xywh 格式(从 0 到 1)。如果您的方框以像素为单位,则除以 x_center 和 width 图像宽度,以及 y_center 和 height 按图像高度计算。
类号以 0 为索引(从 0 开始)。
下载数据
wget https://nlpr.ia.ac.cn/pal/trafficdata/TSRD-Train%20Annotation.zip
wget https://nlpr.ia.ac.cn/pal/trafficdata/tsrd-train.zip
wget https://nlpr.ia.ac.cn/pal/trafficdata/TSRD-Test.zip
wget https://nlpr.ia.ac.cn/pal/trafficdata/TSRD-Test%20Annotation.zip
创建目录
import os
os.makedirs('CTSDB/train/images')
os.makedirs('CTSDB/train/labels')
os.makedirs('CTSDB/test/images')
os.makedirs('CTSDB/test/labels')
解压
!unzip -q 'TSRD-Test Annotation.zip' -d 'CTSDB/'
!unzip -q 'TSRD-Test.zip' -d 'CTSDB/test/images/'
!unzip -q 'TSRD-Train Annotation.zip' -d 'CTSDB/'
!unzip -q 'tsrd-train.zip' -d 'CTSDB/train/images/'
生成test labels
with open('CTSDB/TsignRecgTest1994Annotation.txt') as f:
data = f.readlines()
data = [d.strip().split(';')[:-1] for d in data]
data = [[d[0]]+[int(_d) for _d in d[1:]] for d in data]
print(len(data))
print(f'ncls : {len(set(d[-1] for d in data))}')
print(set(d[-1] for d in data))
print(data[10])
ndata = []
for d in data:
# w,h hx,hy,vx,vy, c
nm = d[0]
d = d[1:]
xc = (d[2]+d[4])/(2*d[0])
yc = (d[3]+d[5])/(2*d[1])
w = (d[4]-d[2])/d[0]
h = (d[5]-d[3])/d[1]
ndata.append([nm, d[-1], xc, yc, w, h])
print(ndata[0])
for d in ndata:
nm = d[0].rsplit('.')[0]+'.txt'
with open(f'CTSDB/test/labels/{nm}', 'w') as f:
f.write(' '.join(map(str, d[1:])))
生成train labels
with open('CTSDB/TsignRecgTrain4170Annotation.txt') as f:
data = f.readlines()
data = [d.strip().split(';')[:-1] for d in data]
data = [[d[0]]+[int(_d) for _d in d[1:]] for d in data]
print(len(data))
print(f'ncls : {len(set(d[-1] for d in data))}')
print(set(d[-1] for d in data))
print(data[10])
ndata = []
for d in data:
# w,h hx,hy,vx,vy, c
nm = d[0]
d = d[1:]
xc = (d[2]+d[4])/(2*d[0])
yc = (d[3]+d[5])/(2*d[1])
w = (d[4]-d[2])/d[0]
h = (d[5]-d[3])/d[1]
ndata.append([nm, d[-1], xc, yc, w, h])
print(ndata[0])
for d in ndata:
nm = d[0].rsplit('.')[0]+'.txt'
with open(f'CTSDB/train/labels/{nm}', 'w') as f:
f.write(' '.join(map(str, d[1:])))
生成data.yaml
train: train/images
val: valid/images
test: test/images
nc: 58
names: ['cls 0', 'cls 1', 'cls 2','cls 3',
'cls 4',
'cls 5',
'cls 6',
'cls 7',
'cls 8',
'cls 9',
'cls 10',
'cls 11',
'cls 12',
'cls 13',
'cls 14',
'cls 15',
'cls 16',
'cls 17',
'cls 18',
'cls 19',
'cls 20',
'cls 21',
'cls 22',
'cls 23',
'cls 24',
'cls 25',
'cls 26',
'cls 27',
'cls 28',
'cls 29',
'cls 30',
'cls 31',
'cls 32',
'cls 33',
'cls 34',
'cls 35',
'cls 36',
'cls 37',
'cls 38',
'cls 39',
'cls 40',
'cls 41',
'cls 42',
'cls 43',
'cls 44',
'cls 45',
'cls 46',
'cls 47',
'cls 48',
'cls 49',
'cls 50',
'cls 51',
'cls 52',
'cls 53',
'cls 54',
'cls 55',
'cls 56',
'cls 57']