-
Notifications
You must be signed in to change notification settings - Fork 1
/
train_val_splitter.py
78 lines (75 loc) · 3 KB
/
train_val_splitter.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
import config
import csv
import random
import linecache
from os import path
num_classes = config.numClass
print("-------Splitting files in train.csv------")
with open(config.TUBerlin + 'train.csv', 'w', newline='\n', encoding='utf-8') as file:
for i in range(0, 8000):
idxs = random.sample(range(num_classes * 80), 1)
idxs.append(idxs[0] + 80)
lines = [linecache.getline(config.TUBerlin + "filelist.txt", i) for i in idxs]
image1 = lines[0]
image2 = lines[1]
x = image1.split('/')
y = image2.split('/')
if x[0] == y[0]:
label = 1
else:
label = 0
writer = csv.writer(file)
if path.exists("./TUBerlin/" + image1.replace('\n', '')) and path.exists(
"./TUBerlin/" + image2.replace('\n', '')):
writer.writerow([image1.replace('\n', ''), image2.replace('\n', ''), label])
for i in range(0, 8000):
idxs = random.sample(range(num_classes * 80), 1)
idxs.append(idxs[0] + 1)
lines = [linecache.getline(config.TUBerlin + "filelist.txt", i) for i in idxs]
image1 = lines[0]
image2 = lines[1]
x = image1.split('/')
y = image2.split('/')
if x[0] == y[0]:
label = 1
else:
label = 0
writer = csv.writer(file)
if path.exists("./TUBerlin/" + image1.replace('\n', '')) and path.exists(
"./TUBerlin/" + image2.replace('\n', '')):
writer.writerow([image1.replace('\n', ''), image2.replace('\n', ''), label])
print("-------Splitting files in val.csv------")
with open(config.TUBerlin + 'val.csv', 'w', newline='\n', encoding='utf-8') as file:
for i in range(0, 100):
idxs = random.sample(range(num_classes * 80), 1)
idxs.append(idxs[0] + 80)
lines = [linecache.getline(config.TUBerlin + "filelist.txt", i) for i in idxs]
image1 = lines[0]
image2 = lines[1]
x = image1.split('/')
y = image2.split('/')
if x[0] == y[0]:
label = 1
else:
label = 0
writer = csv.writer(file)
if path.exists("./TUBerlin/" + image1.replace('\n', '')) and path.exists(
"./TUBerlin/" + image2.replace('\n', '')):
writer.writerow([image1.replace('\n', ''), image2.replace('\n', ''), label])
for i in range(0, 100):
idxs = random.sample(range(num_classes * 80), 1)
idxs.append(idxs[0] + 1)
lines = [linecache.getline(config.TUBerlin + "filelist.txt", i) for i in idxs]
image1 = lines[0]
image2 = lines[1]
x = image1.split('/')
y = image2.split('/')
if x[0] == y[0]:
label = 1
else:
label = 0
writer = csv.writer(file)
if path.exists("./TUBerlin/" + image1.replace('\n', '')) and path.exists(
"./TUBerlin/" + image2.replace('\n', '')):
writer.writerow([image1.replace('\n', ''), image2.replace('\n', ''), label])
print("-------Finished!------")