-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_residual_net.py
71 lines (67 loc) · 2.91 KB
/
main_residual_net.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
import sys
sys.path.append('./trainer')
import argparse
import residual_net
import nutszebra_data_augmentation
import nutszebra_cifar10
import nutszebra_optimizer
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='cifar10')
parser.add_argument('--load_model', '-m',
default=None,
help='trained model')
parser.add_argument('--load_optimizer', '-o',
default=None,
help='optimizer for trained model')
parser.add_argument('--load_log', '-l',
default=None,
help='optimizer for trained model')
parser.add_argument('--save_path', '-p',
default='./',
help='model and optimizer will be saved every epoch')
parser.add_argument('--epoch', '-e', type=int,
default=250,
help='maximum epoch')
parser.add_argument('--batch', '-b', type=int,
default=64,
help='mini batch number')
parser.add_argument('--gpu', '-g', type=int,
default=-1,
help='-1 means cpu mode, put gpu id here')
parser.add_argument('--start_epoch', '-s', type=int,
default=1,
help='start from this epoch')
parser.add_argument('--train_batch_divide', '-trb', type=int,
default=1,
help='divid batch number by this')
parser.add_argument('--test_batch_divide', '-teb', type=int,
default=1,
help='divid batch number by this')
parser.add_argument('--lr', '-lr', type=float,
default=0.1,
help='leraning rate')
parser.add_argument('--k', '-k', type=int,
default=1,
help='width hyperparameter')
parser.add_argument('--N', '-n', type=int,
default=18,
help='width hyperparameter')
parser.add_argument('--multiplier', '-multiplier', type=int,
default=4,
help='multiplier for last convolution of block')
args = parser.parse_args().__dict__
print(args)
lr = args.pop('lr')
k = args.pop('k')
N = args.pop('N')
multiplier = args.pop('multiplier')
print('generating model')
model = residual_net.ResidualNetwork(10, block_num=3, out_channels=(16 * k, 32 * k, 64 * k), N=(N, N, N), multiplier=multiplier)
print('Done')
print('Parameters: {}'.format(model.count_parameters()))
optimizer = nutszebra_optimizer.OptimizerResnet(model, lr=lr)
args['model'] = model
args['optimizer'] = optimizer
args['da'] = nutszebra_data_augmentation.DataAugmentationCifar10NormalizeSmall
main = nutszebra_cifar10.TrainCifar10(**args)
main.run()