-
Notifications
You must be signed in to change notification settings - Fork 8
/
train.py
68 lines (60 loc) · 2.97 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
import argparse
import os
import torch
from train_helper_ALTGVT import Trainer
def str2bool(v):
return v.lower() in ("yes", "true", "t", "1")
def parse_args():
parser = argparse.ArgumentParser(description='Train')
parser.add_argument('--data-dir', default='/home/hdd/dataset_xzw/ShanghaiTech/part_A_final', help='data path')
parser.add_argument('--dataset', default='sha', help='dataset name: qnrf, nwpu, sha, shb, custom')
parser.add_argument('--lr', type=float, default=1e-5,
help='the initial learning rate')
parser.add_argument('--weight-decay', type=float, default=1e-4,
help='the weight decay')
parser.add_argument('--resume', default='', type=str,
help='the path of resume training model')
parser.add_argument('--max-epoch', type=int, default=4000,
help='max training epoch')
parser.add_argument('--val-epoch', type=int, default=1,
help='the num of steps to log training information')
parser.add_argument('--val-start', type=int, default=0,
help='the epoch start to val')
parser.add_argument('--batch-size', type=int, default=16,
help='train batch size')
parser.add_argument('--device', default='0', help='assign device')
parser.add_argument('--num-workers', type=int, default=16,
help='the num of training process')
parser.add_argument('--crop-size', type=int, default= 256,
help='the crop size of the train image')
parser.add_argument('--wot', type=float, default=0.1, help='weight on OT loss')
parser.add_argument('--wtv', type=float, default=0.01, help='weight on TV loss')
parser.add_argument('--reg', type=float, default=10.0,
help='entropy regularization in sinkhorn')
parser.add_argument('--num-of-iter-in-ot', type=int, default=100,
help='sinkhorn iterations')
parser.add_argument('--norm-cood', type=int, default=0, help='whether to norm cood when computing distance')
parser.add_argument('--run-name', default='CCTrans', help='run name for wandb interface/logging')
parser.add_argument('--wandb', default=0, type=int, help='boolean to set wandb logging')
args = parser.parse_args()
if args.dataset.lower() == 'qnrf':
args.crop_size = 512
elif args.dataset.lower() == 'nwpu':
args.crop_size = 384
args.val_epoch = 50
elif args.dataset.lower() == 'sha':
args.crop_size = 256
elif args.dataset.lower() == 'shb':
args.crop_size = 512
elif args.dataset.lower() == 'custom':
args.crop_size = 256
else:
raise NotImplementedError
return args
if __name__ == '__main__':
args = parse_args()
torch.backends.cudnn.benchmark = True
os.environ['CUDA_VISIBLE_DEVICES'] = args.device.strip() # set vis gpu
trainer = Trainer(args)
trainer.setup()
trainer.train()