-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
78 lines (62 loc) · 2.22 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
73
74
75
76
77
78
from pathlib import Path
import torch
from sacred import Ingredient
from sacred.utils import apply_backspaces_and_linefeeds
from torch.backends import cudnn
ROOT = Path(__file__).parent
global_ingredient = Ingredient("g", save_git_info=False) # global
device_ingredient = Ingredient("d", save_git_info=False) # device
@global_ingredient.config
def global_arguments():
""" Global Arguments """
model_dir = "model_dir" # str/null, Directory to save model parameters, graph, etc
fileStorage = False # bool, fileStorage observer
mongodb = True # bool, MongoDB observer
mongo_port = 7000 # int, MongoDB port
@global_ingredient.config_hook
def global_hook(config, command_name, logger):
g = config["g"]
model_dir = g["model_dir"]
if not model_dir:
model_dir = "model_dir"
model_dir = ROOT / model_dir
if not model_dir.exists():
model_dir.mkdir(exist_ok=True, parents=True)
g["model_dir"] = str(model_dir)
if g["mongodb"]:
g["fileStorage"] = False
else:
g["fileStorage"] = True
return g
@device_ingredient.config
def device_arguments():
""" Device Arguments """
enable_gpu = True # Use gpu or not
num_threads = 1 #
cudnn = {
"enabled": True,
"benchmark": True, # Set True for better performance when the input size is fixed.
}
@device_ingredient.config_hook
def device_hook(config, command_name, logger):
d = config["d"]
if d["enable_gpu"]:
cudnn.enabled = d["cudnn"]["enabled"]
cudnn.benchmark = d["cudnn"]["benchmark"]
torch.set_num_threads(d["num_threads"])
else:
d["cudnn"]["enabled"] = False
d["cudnn"]["benchmark"] = False
d["num_threads"] = 0
return d
def experiments_setup(ex):
# Track outputs
ex.captured_out_filter = apply_backspaces_and_linefeeds
# Track more source file
ex.add_source_file("utils/timer.py")
ex.add_source_file("core/losses.py")
ex.add_source_file("core/metrics.py")
# Add dependencies
ex.add_package_dependency("opencv", "3.4.2")
ex.add_package_dependency("cudatoolkit", "10.1.243")
ex.add_package_dependency("cudnn", "7.6.5")