-
Notifications
You must be signed in to change notification settings - Fork 5
/
assets.py
65 lines (45 loc) · 1.83 KB
/
assets.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
import os
import shutil
class AssetManager:
def __init__(self, base_dir):
self.__base_dir = base_dir
self.__cache_dir = os.path.join(self.__base_dir, 'cache')
if not os.path.exists(self.__cache_dir):
os.mkdir(self.__cache_dir)
self.__preprocess_dir = os.path.join(self.__cache_dir, 'preprocess')
if not os.path.exists(self.__preprocess_dir):
os.mkdir(self.__preprocess_dir)
self.__models_dir = os.path.join(self.__cache_dir, 'models')
if not os.path.exists(self.__models_dir):
os.mkdir(self.__models_dir)
self.__tensorboard_dir = os.path.join(self.__cache_dir, 'tensorboard')
if not os.path.exists(self.__tensorboard_dir):
os.mkdir(self.__tensorboard_dir)
self.__eval_dir = os.path.join(self.__base_dir, 'eval')
if not os.path.exists(self.__eval_dir):
os.mkdir(self.__eval_dir)
def get_preprocess_file_path(self, data_name):
return os.path.join(self.__preprocess_dir, data_name + '.npz')
def get_model_dir(self, model_name):
return os.path.join(self.__models_dir, model_name)
def recreate_model_dir(self, model_name):
model_dir = self.get_model_dir(model_name)
self.__recreate_dir(model_dir)
return model_dir
def get_tensorboard_dir(self, data_name, model_name):
return os.path.join(self.__tensorboard_dir, data_name, model_name)
def recreate_tensorboard_dir(self, data_name, model_name):
tensorboard_dir = self.get_tensorboard_dir(data_name, model_name)
self.__recreate_dir(tensorboard_dir)
return tensorboard_dir
def get_eval_dir(self, data_name, model_name):
return os.path.join(self.__eval_dir, data_name, model_name)
def recreate_eval_dir(self, data_name, model_name):
eval_dir = self.get_eval_dir(data_name, model_name)
self.__recreate_dir(eval_dir)
return eval_dir
@staticmethod
def __recreate_dir(path):
if os.path.exists(path):
shutil.rmtree(path)
os.makedirs(path)