-
Notifications
You must be signed in to change notification settings - Fork 1
/
train.py
48 lines (41 loc) · 1.49 KB
/
train.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
# -*- coding: utf-8 -*-
import argparse
import os
from parser.cmds import Evaluate, Train
import shutil
import torch
import traceback
from pathlib import Path
from easydict import EasyDict as edict
import yaml
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='LCFRS'
)
parser.add_argument('--conf', '-c', default='')
parser.add_argument('--device', '-d', default='0')
parser.add_argument('--t', '-t', default='0')
args2 = parser.parse_args()
yaml_cfg = yaml.load(open(args2.conf, 'r'),Loader=yaml.Loader)
args = edict(yaml_cfg)
args.update(args2.__dict__)
print(f"Set the device with ID {args.device} visible")
os.environ['CUDA_VISIBLE_DEVICES'] = args.device
args.device = 'cuda' if torch.cuda.is_available() else 'cpu'
config_path = Path(args.conf if args.conf else args2.load_from_dir + "/config.yaml")
config_name = config_path.stem
args.save_dir = args.save_dir + "/{}".format(config_name)
try:
command = Train()
command(args)
except KeyboardInterrupt:
command = int(input('Enter 0 to delete the repo, and enter anything else to save.'))
if command == 0:
shutil.rmtree(args.save_dir)
print("You have successfully delete the created log directory.")
else:
print("log directory have been saved.")
except Exception:
traceback.print_exc()
shutil.rmtree(args.save_dir)
print("log directory have been deleted.")