-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
73 lines (60 loc) · 2.13 KB
/
config.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
import socket
import copy
from shutil import copytree
import os
import time
dset_root = {}
dset_root['cub'] = '/scratch1/tsungyulin/dataset/cub'
dset_root['cars'] = '/scratch1/tsungyulin/dataset/cars'
dset_root['aircrafts'] = '/scratch1/tsungyulin/dataset/fgvc-aircraft-2013b'
dset_root['inat'] = '/scratch1/tsungyulin/dataset/inat_2018_448'
dset_root['mit_indoor'] = '/scratch1/tsungyulin/dataset/mit_indoor'
test_code = False
if 'node' in socket.gethostname() or test_code:
nfs_dset = copy.deepcopy(dset_root)
if test_code:
local_path = os.path.join(os.getenv("HOME"), 'my_local_test')
else:
local_path = '/local/image_datasets'
if not os.path.isdir(local_path):
os.makedirs(local_path)
for x in dset_root.items():
folder_name = os.path.basename(x[1])
dset_root[x[0]] = os.path.join(local_path, folder_name)
def wait_dataset_copy_finish(dataset):
flag_file = os.path.join(dset_root[dataset] + '_flag',
'flag_ready.txt')
while True:
with open(flag_file, 'r') as f:
status = f.readline()
if status == 'True':
break
time.sleep(600)
def setup_dataset(dataset):
my_tmp = os.path.join(os.getenv("HOME"), 'tmp')
if not os.path.isdir(my_tmp):
os.makedirs(my_tmp)
os.environ["TMPDIR"] = my_tmp
if 'node' in socket.gethostname():
if not os.path.isdir(dset_root[dataset]):
if os.path.isdir(os.path.join(dset_root[dataset] + '_flag')):
wait_dataset_copy_finish(dataset)
else:
gypsum_copy_data_to_local(dataset)
else:
wait_dataset_copy_finish(dataset)
def gypsum_copy_data_to_local(dataset):
flag_file = os.path.join(dset_root[dataset] + '_flag', 'flag_ready.txt')
os.makedirs(dset_root[dataset] + '_flag')
with open(flag_file, 'w') as f:
f.write('False')
if test_code:
import pdb
pdb.set_trace()
pass
copytree(nfs_dset[dataset], dset_root[dataset])
if test_code:
pdb.set_trace()
pass
with open(flag_file, 'w') as f:
f.write('True')