-
Notifications
You must be signed in to change notification settings - Fork 0
/
train.py
69 lines (56 loc) · 4.46 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
import argparse
import os
import trainer
if __name__ == "__main__":
# ----------------------------------------
# Initialize the parameters
# ----------------------------------------
parser = argparse.ArgumentParser()
# Pre-train, saving, and loading parameters
parser.add_argument('--load_pre_train', type = bool, default = False, help = 'load pre-train weight or not')
parser.add_argument('--save_mode', type = str, default = 'epoch', help = 'saving mode, and by_epoch saving is recommended')
parser.add_argument('--save_by_epoch', type = int, default = 1, help = 'interval between model checkpoints (by epochs)')
parser.add_argument('--save_name_mode', type = bool, default = True, help = 'True for concise name, and False for exhaustive name')
parser.add_argument('--load_name', type = str, default = 'model/epoch74_batchsize2', help = 'load the pre-trained model with certain epoch')
# GPU parameters
parser.add_argument('--multi_gpu', type = bool, default = False, help = 'True for more than 1 GPU')
parser.add_argument('--gpu_ids', type = str, default = '0, 1', help = 'gpu_ids: e.g. 0 0,1 0,1,2 use -1 for CPU')
parser.add_argument('--cudnn_benchmark', type = bool, default = True, help = 'True for unchanged input data type')
# Training parameters
parser.add_argument('--epochs', type = int, default = 250, help = 'number of epochs of training')
parser.add_argument('--batch_size', type = int, default = 4, help = 'size of the batches')
parser.add_argument('--lr_g', type = float, default = 4e-2, help = 'Adam: learning rate for G')
parser.add_argument('--b1', type = float, default = 0.9, help = 'Adam: decay of first order momentum of gradient')
parser.add_argument('--b2', type = float, default = 0.999, help = 'Adam: decay of second order momentum of gradient')
parser.add_argument('--weight_decay', type = float, default = 0, help = 'weight decay for optimizer')
parser.add_argument('--lr_decrease_mode', type = str, default = 'epoch', help = 'lr decrease mode, by_epoch or by_iter')
parser.add_argument('--lr_decrease_epoch', type = int, default = 250, help = 'lr decrease at certain epoch and its multiple')
parser.add_argument('--lr_decrease_iter', type = int, default = 200000, help = 'lr decrease at certain epoch and its multiple')
parser.add_argument('--lr_decrease_factor', type = float, default = 0.8, help = 'lr decrease factor')
parser.add_argument('--num_workers', type = int, default = 1, help = 'number of cpu threads to use during batch generation')
# Initialization parameters
parser.add_argument('--pad', type = str, default = 'reflect', help = 'pad type of networks')
parser.add_argument('--norm', type = str, default = 'in', help = 'normalization type of networks')
parser.add_argument('--in_channels', type = int, default = 3, help = 'input number of channel')
parser.add_argument('--out_channels', type = int, default = 3, help = 'output number of channel')
parser.add_argument('--latent_channels', type = int, default = 64, help = 'start channels for the main stream of generator')
parser.add_argument('--init_type', type = str, default = 'normal', help = 'initialization type of networks')
parser.add_argument('--init_gain', type = float, default = 0.02, help = 'initialization gain of networks')
# Dataset parameters
parser.add_argument('--task', type = str, default = 'UDC', help = 'the specific task of the system')
parser.add_argument('--angle_aug', type = bool, default = True, help = 'data augmentation')
parser.add_argument('--in_root', type = str, default = '../ECCV_UDC/Poled/LQ_Patch_512', help = 'LQ image patch baseroot')
parser.add_argument('--out_root', type = str, default = '../ECCV_UDC/Poled/HQ_Patch_512', help = 'GT image patch baseroot')
opt = parser.parse_args()
# ----------------------------------------
# Choose CUDA visible devices
# ----------------------------------------
if opt.multi_gpu == True:
os.environ["CUDA_VISIBLE_DEVICES"] = opt.gpu_ids
print('Multi-GPU mode, %s GPUs are used' % (opt.gpu_ids))
else:
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
print('Single-GPU mode')
print('training settings: [Epochs: %d] [Batch size: %d] [Learning rate: %.8f] [Saving mode: %s]'
% (opt.epochs, opt.batch_size, opt.lr_g, opt.save_mode))
trainer.train(opt)