-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclipig.py
43 lines (29 loc) · 1.15 KB
/
clipig.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
import pathlib
import time
import sys
from src.parameters import parse_arguments, save_yaml_config
from src.files import make_filename_dir, change_extension
from src.training import ImageTraining
from src.files import prepare_output_name
if __name__ == "__main__":
parameters = parse_arguments()
num_repeat = parameters.pop("repeat", 1)
try:
for i in range(num_repeat):
trainer = ImageTraining(parameters)
start_time = time.time()
trainer.train()
run_time = time.time() - start_time
trainer.save_image()
filename = change_extension(parameters["output"], "yaml")
if not pathlib.Path(filename).exists():
trainer.save_yaml(filename, run_time=run_time)
# update output-name when repeating
parameters["output"] = str(prepare_output_name(parameters["output"], make_dir=False))
except KeyboardInterrupt:
pass
except RuntimeError as e:
# sometimes the keyboard interrupt ungracefully breaks
# the torchscript execution
if not str(e).strip().endswith("RuntimeError:"):
raise