-
Notifications
You must be signed in to change notification settings - Fork 2
/
train.py
75 lines (66 loc) · 3.45 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import argparse
import torch
import os
from utils.regression_trainer import Reg_Trainer
def parse_arg():
parser = argparse.ArgumentParser()
parser.add_argument('--content', default="code_test", type=str,
help='what is it?')
parser.add_argument('--seed', default=15, type=int)
parser.add_argument('--crop-size', default=512, type=int,
help='the cropped size of the training data')
parser.add_argument('--downsample-ratio', default=8, type=int,
help='the downsample ratio of the model')
parser.add_argument('--data-dir', default='SHA',
help='the directory of the data')
parser.add_argument('--save-dir', default='history',
help='the directory for saving models and training logs')
parser.add_argument('--pretrained', default='pretrained/pcpvt_large.pth',
help='the path to the pretrained pcpvt model')
parser.add_argument('--drop', type=float, default=0.0, metavar='PCT',
help='Dropout rate (default: 0.)')
parser.add_argument('--drop-path', type=float, default=0.45, metavar='PCT',
help='Drop path rate (default: 0.1)')
parser.add_argument('--max-num', default=1, type=int,
help='the maximum number of saved models ')
parser.add_argument('--device', default='0',
help="assign device")
parser.add_argument('--resume', default="",
help='the path of the resume training model')
parser.add_argument('--batch-size', default=8, type=int,
help='the number of samples in a batch')
parser.add_argument('--num-workers', default=0, type=int,
help='the number of workers')
parser.add_argument('--gamma', default=2, type=float,
help="gamma for focal loss")
# Optimizer
parser.add_argument('--opt', default='adamw', type=str, metavar='OPTIMIZER',
help='Optimizer')
parser.add_argument('--opt-eps', default=1e-8, type=float, metavar='EPSILON',
help='Optimizer Epsilon')
parser.add_argument('--opt-betas', default=None, type=float, nargs='+', metavar='BETA',
help='Optimizer Betas')
parser.add_argument('--momentum', type=float, default=0.9, metavar='M',
help='SGD momentum')
parser.add_argument('--weight-decay', type=float, default=1e-4,
help='weight decay')
# Learning rate
parser.add_argument('--lr', default=1e-4, type=float,
help='the learning rate')
parser.add_argument('--start-epoch', default=0, type=int,
help='the number of starting epoch')
parser.add_argument('--epochs', default=1000, type=int,
help='the maximum number of training epoch')
parser.add_argument('--start-val', default=200, type=int,
help='the starting epoch for validation')
parser.add_argument('--val-epoch', default=1, type=int,
help='the number of epoch between validation')
args = parser.parse_args()
return args
if __name__ == '__main__':
args = parse_arg()
torch.backends.cudnn.benchmark = True
os.environ['CUDA_VISIBLE_DEVICES'] = args.device.strip()
trainer = Reg_Trainer(args)
trainer.setup()
trainer.train()