forked from taki0112/ResNet-Tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
79 lines (59 loc) · 2.21 KB
/
main.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
76
77
78
79
from ResNet import ResNet
import argparse
from utils import *
"""parsing and configuration"""
def parse_args():
desc = "Tensorflow implementation of ResNet"
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('--phase', type=str, default='train', help='train or test ?')
parser.add_argument('--dataset', type=str, default='tiny', help='[cifar10, cifar100, mnist, fashion-mnist, tiny')
parser.add_argument('--epoch', type=int, default=82, help='The number of epochs to run')
parser.add_argument('--batch_size', type=int, default=256, help='The size of batch per gpu')
parser.add_argument('--res_n', type=int, default=18, help='18, 34, 50, 101, 152')
parser.add_argument('--lr', type=float, default=0.1, help='learning rate')
parser.add_argument('--checkpoint_dir', type=str, default='checkpoint',
help='Directory name to save the checkpoints')
parser.add_argument('--log_dir', type=str, default='logs',
help='Directory name to save training logs')
return check_args(parser.parse_args())
"""checking arguments"""
def check_args(args):
# --checkpoint_dir
check_folder(args.checkpoint_dir)
# --result_dir
check_folder(args.log_dir)
# --epoch
try:
assert args.epoch >= 1
except:
print('number of epochs must be larger than or equal to one')
# --batch_size
try:
assert args.batch_size >= 1
except:
print('batch size must be larger than or equal to one')
return args
"""main"""
def main():
# parse arguments
args = parse_args()
if args is None:
exit()
# open session
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
cnn = ResNet(sess, args)
# build graph
cnn.build_model()
# show network architecture
show_all_variables()
if args.phase == 'train' :
# launch the graph in a session
cnn.train()
print(" [*] Training finished! \n")
cnn.test()
print(" [*] Test finished!")
if args.phase == 'test' :
cnn.test()
print(" [*] Test finished!")
if __name__ == '__main__':
main()