-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit_train_test.py
55 lines (49 loc) · 1.63 KB
/
split_train_test.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
import ipdb
import os
import glob
join = os.path.join
st = ipdb.set_trace
glob_true = True
import socket
ip = socket.gethostname()
if "Alien" in ip:
root_location = "/media/mihir/dataset/"
elif 'ip' in ip:
root_location = "/projects/"
elif 'compute' in ip:
root_location = "/home/mprabhud/dataset"
data_mod = 'rotMA500'
# folder_name = 'vqa_2_3_obj'
folder_name = 'vqa_2_3_obj_multi_azimuth'
split_percent = 0.25
split_percent_c = 1 - split_percent
name_split = f"{split_percent}_{split_percent_c}"
if glob_true:
location = f"{root_location}/vqa/{folder_name}/npy/{data_mod}/*"
files = glob.glob(location)
files = ['/'.join(i.split('/')[-2:]) +"\n" for i in files]
num = int(len(files)*split_percent)
txt_file_train_1 = f"{root_location}/vqa/{folder_name}/npy/{data_mod}_{name_split}t.txt"
txt_file_train_2 = f"{root_location}/vqa/{folder_name}/npy/{data_mod}_{name_split}v.txt"
train_data_1 = files[:num]
train_data_2 = files[num:]
else:
data_mod = "bb_tv"
new_mod_1 = data_mod +"_a"
new_mod_2 = data_mod +"_b"
root_location = "/projects/katefgroup/datasets/"
txt_file_train = f"{root_location}/carla/npys/{data_mod}t.txt"
txt_file_train_1 = f"{root_location}/carla/npys/{new_mod_1}t.txt"
txt_file_train_2 = f"{root_location}/carla/npys/{new_mod_2}t.txt"
train_data = open(txt_file_train,"r").readlines()
num = int(len(train_data)*split_percent)
train_data_1 = train_data[:num]
train_data_2 = train_data[num:]
with open(txt_file_train_1, 'w') as f:
for item in train_data_1:
if "*" not in item:
f.write("%s" % item)
with open(txt_file_train_2, 'w') as f:
for item in train_data_2:
if "*" not in item:
f.write("%s" % item)