-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrain.py
55 lines (41 loc) · 1.48 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
47
48
49
50
51
52
53
54
55
#new start by wk!
#new start for PCM paper!
import argparse
import os
import torch
import logging
from tools.init_tool import init_all
from config_parser import create_config
from tools.train_tool import train
import faulthandler
faulthandler.enable()
logging.basicConfig(format='%(asctime)s - %(levelname)s - %(name)s - %(message)s',
datefmt='%m/%d/%Y %H:%M:%S',
level=logging.INFO)
logger = logging.getLogger(__name__)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--config', '-c', help="specific config file", required=True)
parser.add_argument('--gpu', '-g', help="gpu id list")
parser.add_argument('--checkpoint', help="checkpoint file path")
args = parser.parse_args()
configFilePath = args.config
use_gpu = True
gpu_list = []
if args.gpu is None:
use_gpu = False
else:
use_gpu = True
os.environ["CUDA_VISIBLE_DEVICES"] = args.gpu
device_list = args.gpu.split(",")
for a in range(0, len(device_list)):
gpu_list.append(int(a))
os.system("clear")
config = create_config(configFilePath)
cuda = torch.cuda.is_available()
logger.info("CUDA available: %s" % str(cuda))
if not cuda and len(gpu_list) > 0:
logger.error("CUDA is not available but specific gpu id")
raise NotImplementedError
parameters = init_all(config, gpu_list, args.checkpoint, "train")
train(parameters, config, gpu_list)