-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.py
29 lines (25 loc) · 842 Bytes
/
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
import json
import torch
import time
from torch.autograd import Variable
def to_var(x, volatile=False):
if torch.cuda.is_available():
x = x.cuda()
return Variable(x, volatile=volatile)
def calculate_image_norm(folder):
pass
def add_log_entry(name,start_time, params):
localtime = time.asctime( time.localtime(time.time()) )
line = "experiment: " + name +" | started training at: " +localtime + " | params: " + json.dumps(params) +"\n"
if name == "test":
print(line)
else:
with open("log.md", 'a') as f:
f.write(line)
def add_log_results(name,run_time,loss):
line = "finished experiment: " + name +" | run time: " +run_time + " | loss: " + loss +"\n"
if name == "test":
print(line)
else:
with open("log.md", 'a') as f:
f.write(line)