1+
2+ import tensorflow as tf
3+ import tools
4+
5+ #%%
6+ def VGG16 (x , n_classes , is_pretrain = True ):
7+
8+ x = tools .conv ('conv1_1' , x , 64 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
9+ x = tools .conv ('conv1_2' , x , 64 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
10+ x = tools .pool ('pool1' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
11+
12+ x = tools .conv ('conv2_1' , x , 128 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
13+ x = tools .conv ('conv2_2' , x , 128 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
14+ x = tools .pool ('pool2' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
15+
16+ x = tools .conv ('conv3_1' , x , 256 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
17+ x = tools .conv ('conv3_2' , x , 256 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
18+ x = tools .conv ('conv3_3' , x , 256 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
19+ x = tools .pool ('pool3' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
20+
21+ x = tools .conv ('conv4_1' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
22+ x = tools .conv ('conv4_2' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
23+ x = tools .conv ('conv4_3' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
24+ x = tools .pool ('pool3' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
25+
26+ x = tools .conv ('conv5_1' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
27+ x = tools .conv ('conv5_2' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
28+ x = tools .conv ('conv5_3' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
29+ x = tools .pool ('pool3' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
30+
31+ x = tools .FC_layer ('fc6' , x , out_nodes = 4096 )
32+ x = tools .batch_norm (x )
33+ x = tools .FC_layer ('fc7' , x , out_nodes = 4096 )
34+ x = tools .batch_norm (x )
35+ x = tools .FC_layer ('fc8' , x , out_nodes = n_classes )
36+
37+ return x
38+
39+
40+
41+
42+
43+ #%% TO get better tensorboard figures!
44+
45+ def VGG16N (x , n_classes , is_pretrain = True ):
46+
47+ with tf .name_scope ('VGG16' ):
48+
49+ x = tools .conv ('conv1_1' , x , 64 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
50+ x = tools .conv ('conv1_2' , x , 64 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
51+ with tf .name_scope ('pool1' ):
52+ x = tools .pool ('pool1' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
53+
54+ x = tools .conv ('conv2_1' , x , 128 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
55+ x = tools .conv ('conv2_2' , x , 128 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
56+ with tf .name_scope ('pool2' ):
57+ x = tools .pool ('pool2' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
58+
59+
60+
61+ x = tools .conv ('conv3_1' , x , 256 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
62+ x = tools .conv ('conv3_2' , x , 256 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
63+ x = tools .conv ('conv3_3' , x , 256 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
64+ with tf .name_scope ('pool3' ):
65+ x = tools .pool ('pool3' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
66+
67+
68+ x = tools .conv ('conv4_1' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
69+ x = tools .conv ('conv4_2' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
70+ x = tools .conv ('conv4_3' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
71+ with tf .name_scope ('pool4' ):
72+ x = tools .pool ('pool4' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
73+
74+
75+ x = tools .conv ('conv5_1' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
76+ x = tools .conv ('conv5_2' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
77+ x = tools .conv ('conv5_3' , x , 512 , kernel_size = [3 ,3 ], stride = [1 ,1 ,1 ,1 ], is_pretrain = is_pretrain )
78+ with tf .name_scope ('pool5' ):
79+ x = tools .pool ('pool5' , x , kernel = [1 ,2 ,2 ,1 ], stride = [1 ,2 ,2 ,1 ], is_max_pool = True )
80+
81+
82+ x = tools .FC_layer ('fc6' , x , out_nodes = 4096 )
83+ with tf .name_scope ('batch_norm1' ):
84+ x = tools .batch_norm (x )
85+ x = tools .FC_layer ('fc7' , x , out_nodes = 4096 )
86+ with tf .name_scope ('batch_norm2' ):
87+ x = tools .batch_norm (x )
88+ x = tools .FC_layer ('fc8' , x , out_nodes = n_classes )
89+
90+ return x
91+
92+
93+
94+ #%%
95+
96+
97+
98+
99+
100+
101+
102+
0 commit comments