-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.py
82 lines (67 loc) · 2.95 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
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
79
80
81
import os
import signal
import time
import argparse
def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("--gen_backbone", default="deepdaze", choices=["deepdaze", "bigsleep"])
parser.add_argument("--size", type=int, default=256)
parser.add_argument("--epochs", type=int, default=12)
parser.add_argument("--gradient_accumulate_every", type=int, default=1)
parser.add_argument("--batch_size", type=int, default=32)
parser.add_argument("--lr", type=float, default=1e-5)
parser.add_argument("--num_layers", type=int, default=32)
parser.add_argument("--saturate_bound", type=int, default=0)
parser.add_argument("--lower_bound_cutout", type=float, default=0.05)
parser.add_argument("--do_occlusion", type=int, default=0)
parser.add_argument("--center_bias", type=int, default=0)
parser.add_argument("--center_focus", type=int, default=0)
parser.add_argument("--meta", type=int, default=0)
parser.add_argument("--meta_lr", type=float, default=0.1)
parser.add_argument("--opt_steps", type=int, default=5)
parser.add_argument("--text", type=str, default="")
parser.add_argument("--text_weight", type=float, default=0.5)
parser.add_argument("--run_avg", type=float, default=0.0, help="What fraction of the old encoding to keep.")
parser.add_argument("--run_local", type=int, default=0)
parser.add_argument("--python_path", type=str, default="python3")
parser.add_argument("--host", type=str, default="abakus.ddnss.de")
parser.add_argument("--user", type=str, default="anton")
parser.add_argument("--mode", type=str, default="stream", choices=["stream", "pic"])
args = parser.parse_args()
return args
def time_stamp():
return time.strftime("%X", time.gmtime())
def kill_old_process(create_new=False):
pid = str(os.getpid())
pidfile = "/tmp/mydaemon.pid"
if os.path.isfile(pidfile):
print("Process already exists, killing old process...")
with open(pidfile, 'r') as f:
old_pid = int(f.read())
print("Old PID: ", old_pid)
try:
os.kill(old_pid, signal.SIGINT)
except ProcessLookupError:
pass
time.sleep(5)
# check if SIGINT was enough, else kill process
#try:
# os.kill(old_pid, 0)
#except OSError:
# os.kill(old_pid, signal.SIGTERM)
try:
os.unlink(pidfile)
except FileNotFoundError:
print("PID file was already deleted")
if create_new:
with open(pidfile, 'w') as f:
f.write(pid)
def clean_pid():
pidfile = "/tmp/mydaemon.pid"
os.unlink(pidfile)
def clean_folder(path):
try:
for f in os.listdir(path):
os.unlink(os.path.join(path, f))
except:
print("Could not clean up", path, "properly...")