forked from hukkelas/DeepPrivacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_docker
executable file
·48 lines (41 loc) · 1.33 KB
/
run_docker
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
#!/usr/bin/env python3
import sys
import os
import random
gpu_id = sys.argv[1]
internal_cmd = " ".join(sys.argv[2:])
def clean_command(cmd):
while " " in cmd:
cmd = cmd.replace(" ", " ")
return cmd
model_name = internal_cmd
rm_cmd = ""
try:
start_idx = model_name.index(" models/") + len(" models/")
end_idx = model_name[start_idx:].index("/") + start_idx
model_name = model_name[start_idx:end_idx]
except ValueError:
print("Did not find model name. giving the model a random name and removing the container.")
rm_cmd = " --rm "
model_name = str(random.randint(0, 10000))
print("Model name:", model_name)
filedir = os.path.dirname(os.path.abspath(__file__))
if "train" in internal_cmd:
docker_container = "haakohu_{}_train".format(model_name)
else:
docker_container = "haakohu_{}_other".format(model_name)
os.system("docker rm {}".format(docker_container))
command = "nvidia-docker run --name {} --ipc=host{}\
-v /dev/log:/home/haakohu/DeepPrivacy/log -u 1174424 -v {}:/workspace \
-v /lhome/haakohu/DSFD:/lhome/haakohu/DSFD \
-e CUDA_VISIBLE_DEVICES={} --log-opt max-size=50m\
-it haakohu/pytorch {}".format(
docker_container,
rm_cmd,
filedir,
gpu_id,
internal_cmd
)
command = clean_command(command)
print(command)
os.system(command)