-
Notifications
You must be signed in to change notification settings - Fork 8
/
make_npydata.py
executable file
·149 lines (111 loc) · 4.76 KB
/
make_npydata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import os
import numpy as np
if not os.path.exists('./npydata'):
os.makedirs('./npydata')
'''please set your dataset path'''
try:
shanghaiAtrain_path='/home/dkliang/projects/synchronous/ShanghaiTech/part_A_final/train_data/images/'
shanghaiAtest_path='/home/dkliang/projects/synchronous/ShanghaiTech/part_A_final/test_data/images/'
train_list = []
for filename in os.listdir(shanghaiAtrain_path):
if filename.split('.')[1] == 'jpg':
train_list.append(shanghaiAtrain_path+filename)
train_list.sort()
np.save('./npydata/ShanghaiA_train.npy', train_list)
test_list = []
for filename in os.listdir(shanghaiAtest_path):
if filename.split('.')[1] == 'jpg':
test_list.append(shanghaiAtest_path+filename)
test_list.sort()
np.save('./npydata/ShanghaiA_test.npy', test_list)
print("generate ShanghaiA image list successfully")
except:
print("The ShanghaiA dataset path is wrong. Please check you path.")
try:
shanghaiBtrain_path='/home/dkliang/projects/synchronous/ShanghaiTech/part_B_final/train_data/images/'
shanghaiBtest_path='/home/dkliang/projects/synchronous/ShanghaiTech/part_B_final/test_data/images/'
train_list = []
for filename in os.listdir(shanghaiBtrain_path):
if filename.split('.')[1] == 'jpg':
train_list.append(shanghaiBtrain_path+filename)
train_list.sort()
np.save('./npydata/ShanghaiB_train.npy', train_list)
test_list = []
for filename in os.listdir(shanghaiBtest_path):
if filename.split('.')[1] == 'jpg':
test_list.append(shanghaiBtest_path+filename)
test_list.sort()
np.save('./npydata/ShanghaiB_test.npy', test_list)
print("Generate ShanghaiB image list successfully")
except:
print("The ShanghaiB dataset path is wrong. Please check your path.")
try:
Qnrf_train_path='/home/dkliang/projects/synchronous/UCF-QNRF/train_data/images/'
Qnrf_test_path='/home/dkliang/projects/synchronous/UCF-QNRF/test_data/images/'
train_list = []
for filename in os.listdir(Qnrf_train_path):
if filename.split('.')[1] == 'jpg':
train_list.append(Qnrf_train_path+filename)
train_list.sort()
np.save('./npydata/qnrf_train.npy', train_list)
test_list = []
for filename in os.listdir(Qnrf_test_path):
if filename.split('.')[1] == 'jpg':
test_list.append(Qnrf_test_path+filename)
test_list.sort()
np.save('./npydata/qnrf_test.npy', test_list)
print("Generate QNRF image list successfully")
except:
print("The QNRF dataset path is wrong. Please check your path.")
try:
Jhu_train_path='/home/dkliang/projects/synchronous/jhu_crowd_v2.0/train/images/'
Jhu_val_path='/home/dkliang/projects/synchronous/jhu_crowd_v2.0/val/images/'
jhu_test_path='/home/dkliang/projects/synchronous/jhu_crowd_v2.0/test/images/'
train_list = []
for filename in os.listdir(Jhu_train_path):
if filename.split('.')[1] == 'jpg':
train_list.append(Jhu_train_path+filename)
train_list.sort()
np.save('./npydata/jhu_train.npy', train_list)
val_list = []
for filename in os.listdir(Jhu_val_path):
if filename.split('.')[1] == 'jpg':
val_list.append(Jhu_val_path+filename)
val_list.sort()
np.save('./npydata/jhu_val.npy', val_list)
test_list = []
for filename in os.listdir(jhu_test_path):
if filename.split('.')[1] == 'jpg':
test_list.append(jhu_test_path+filename)
test_list.sort()
np.save('./npydata/jhu_test.npy', test_list)
print("Generate JHU image list successfully")
except:
print("The JHU dataset path is wrong. Please check your path.")
try:
f = open("./data/NWPU_list/train.txt", "r")
train_list = f.readlines()
f = open("./data/NWPU_list/val.txt", "r")
val_list = f.readlines()
f = open("./data/NWPU_list/test.txt", "r")
test_list = f.readlines()
train_img_list = []
root = '/home/dkl/projects/synchronous/NWPU_localization/images_2048/'
for i in range(len(train_list)):
fname = train_list[i].split(' ')[0] + '.jpg'
train_img_list.append(root + fname)
np.save('./npydata/nwpu_train_2048.npy', train_img_list)
val_img_list = []
for i in range(len(val_list)):
fname = val_list[i].split(' ')[0] + '.jpg'
val_img_list.append(root + fname)
np.save('./npydata/nwpu_val_2048.npy', val_img_list)
test_img_list = []
root = root.replace('images','test_data')
for i in range(len(test_list)):
fname = test_list[i].split(' ')[0] + '.jpg'
fname = fname.split('\n')[0] + fname.split('\n')[1]
test_img_list.append(root + fname)
np.save('./npydata/nwpu_test_2048.npy', test_img_list)
except:
print("The NWPU dataset path is wrong. Please check your path.")