-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit.py
More file actions
59 lines (47 loc) · 1.41 KB
/
split.py
File metadata and controls
59 lines (47 loc) · 1.41 KB
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
import math
import os
from os import path
import csv
from random import shuffle
data = []
with open(path.join("", "", "celebrityFacesReps.txt")) as f:
with open("celebrityFacesGT.txt") as f2:
reader = csv.reader(f)
for row in reader:
# rep
row_d = []
for item in row:
row_d .append(float(item))
#gt
gt = []
line = f2.readline()
values = line.split(",")
for value in values:
gt.append(float(value))
row_d.append(gt)
data.append(row_d)
print(data[0])
shuffle(data)
# split data
train = data[:math.floor(2*len(data)/3)]
test = data[math.floor(2*len(data)/3):]
x_train = [x[:128] for x in train]
y_train = [y[128] for y in train]
x_test = [x[:128] for x in test]
y_test = [y[128] for y in test]
with open("celebrityFacesRepsTrainShuffled.txt", 'w') as f:
writer = csv.writer(f)
for rep in x_train:
writer.writerow(rep)
with open("celebrityFacesGTTrainShuffled.txt", 'w') as f:
writer = csv.writer(f)
for rep in y_train:
writer.writerow(rep)
with open("celebrityFacesRepTestShuffled.txt", 'w') as f:
writer = csv.writer(f)
for rep in x_test:
writer.writerow(rep)
with open("celebrityFacesGTTestShuffled.txt", 'w') as f:
writer = csv.writer(f)
for rep in y_test:
writer.writerow(rep)