-
Notifications
You must be signed in to change notification settings - Fork 82
/
hook_utils.py
37 lines (30 loc) · 1.12 KB
/
hook_utils.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
# Standard Library
import os
# Local
from .access_layer.utils import check_dir_exists
from .logger import get_logger
from .utils import is_s3
logger = get_logger()
def verify_and_get_out_dir(out_dir):
if out_dir is None:
raise RuntimeError("out_dir is a required argument")
is_s3_path, _, _ = is_s3(out_dir)
if not is_s3_path:
out_dir = os.path.expanduser(out_dir)
# we check and raise error if directory already exists because
# we don't want to merge tensors from current job with
# tensors from previous job
check_dir_exists(out_dir)
return out_dir
def get_tensorboard_dir(export_tensorboard, tensorboard_dir, out_dir):
if tensorboard_dir is not None:
tensorboard_dir = os.path.expanduser(tensorboard_dir)
if export_tensorboard and tensorboard_dir:
return tensorboard_dir
elif not export_tensorboard and tensorboard_dir:
# Assume the user forgot `export_tensorboard` and save anyway.
return tensorboard_dir
elif export_tensorboard and not tensorboard_dir:
return os.path.join(out_dir, "tensorboard")
else:
return None