forked from XintianHan/Survival-MDN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
36 lines (28 loc) · 1.05 KB
/
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
from __future__ import absolute_import, division, print_function
import os
from datetime import datetime
import numpy as np
import pandas as pd
SEP = "__" # Avoid common signs like "_".
def to_np(x):
return x.data.cpu().numpy()
class MyPrinter(object):
def __init__(self, verbose, exp_name=None, log_path=None, debug=False):
self.verbose = verbose
self.debug = debug
if log_path is not None:
self.log_file = os.path.join(log_path, "%s.log" % exp_name)
else:
self.log_file = None
def print(self, content, level=0, print_time=False):
if self.verbose > level:
if print_time or self.debug:
print(" ".join(
["\033[90m---",
str(datetime.now()), "---\033[0m"]))
print(content)
if self.log_file is not None:
with open(self.log_file, "a") as f:
if print_time or self.debug:
f.write("--- %s ---\n" % str(datetime.now()))
f.write(content + "\n")