def inference_AlexNet(self,im): l1 = self._AlexNet_conv_layer(im, 96, (11,11), (4,4), (3,3), (2,2), name='l1') l2 = self._AlexNet_conv_layer(l1, 256, (5,5), (1,1), (3,3), (2,2), name='l2') with tf.variable_scope('l3') as scope: l3_conv = tl.conv2d(l2, 384, (3,3), (1,1), name='l3') l3 = tl.relu(l3_conv) with tf.variable_scope('l4') as scope: l4_conv = tl.conv2d(l3, 384, (3,3), (1,1), name='l4') l4 = tl.relu(l4_conv) with tf.variable_scope('l5') as scope: l5_lconv = tl.conv2d(l4, 256, (3,3), (1,1), name='l5') l5_lrelu = tl.relu(l5_lconv) l5 = tl.max_pool2d(l5_lrelu, (3,3), (2,2), padding='VALID', name='pool') #print l5.get_shape() fc0 = tf.reshape(l5, [self.batch_size, -1]) fc1 = tl.fc(fc0, 4096, name='fc1') l6_lrelu = tl.relu(fc1) l6 = tl.dropout(l6_lrelu, self.keep_prob) fc2 = tl.fc(l6, 4096, name='fc2') l7_lrelu = tl.relu(fc2) l7 = tl.dropout(l7_lrelu, self.keep_prob) fc3 = tl.fc(l7, 10, name='fc3') return fc3
def inference(self, im): l0 = im l1 = self._conv_layer(l0, 32, (5, 5), (1, 1), (2, 2), (2, 2), name='l1') l2 = self._conv_layer(l1, 32, (5, 5), (1, 1), (2, 2), (2, 2), name='l2') l3 = self._conv_layer(l2, 64, (5, 5), (1, 1), (2, 2), (2, 2), name='l3') fc0 = tf.reshape(l3, [self.batch_size, -1]) fc1 = tl.fc(fc0, 64, name='fc1') fc2 = tl.fc(fc1, 10, name='fc2') return fc2
def inference_VGG19(self, im): with tf.variable_scope('l1_conv1') as scope: l1_conv1 = tl.conv2d(im, 64, (3, 3), (1, 1), name='l1') with tf.variable_scope('l2_conv2') as scope: l2_conv2 = tl.conv2d(l1_conv1, 64, (3, 3), (1, 1), name='l2') l2_pooling = tl.max_pool2d(l2_conv2, (3, 3), (2, 2), padding='SAME', name='pool') with tf.variable_scope('l3_conv1') as scope: l3_conv1 = tl.conv2d(l2_pooling, 128, (3, 3), (1, 1), name='l3') with tf.variable_scope('l4_conv2') as scope: l4_conv2 = tl.conv2d(l3_conv1, 128, (3, 3), (1, 1), name='l4') l4_pooling = tl.max_pool2d(l4_conv2, (3, 3), (2, 2), padding='SAME', name='pool') with tf.variable_scope('l5_conv1') as scope: l5_conv1 = tl.conv2d(l4_pooling, 256, (3, 3), (1, 1), name='l5') with tf.variable_scope('l6_conv2') as scope: l6_conv2 = tl.conv2d(l5_conv1, 256, (3, 3), (1, 1), name='l6') with tf.variable_scope('l7_conv3') as scope: l7_conv3 = tl.conv2d(l6_conv2, 256, (3, 3), (1, 1), name='l7') with tf.variable_scope('l8_conv4') as scope: l8_conv4 = tl.conv2d(l7_conv3, 256, (3, 3), (1, 1), name='l8') l8_pooling = tl.max_pool2d(l8_conv4, (3, 3), (2, 2), padding='SAME', name='pool') with tf.variable_scope('l9_conv1') as scope: l9_conv1 = tl.conv2d(l8_pooling, 512, (3, 3), (1, 1), name='l9') with tf.variable_scope('l10_conv2') as scope: l10_conv2 = tl.conv2d(l9_conv1, 512, (3, 3), (1, 1), name='l10') with tf.variable_scope('l11_conv3') as scope: l11_conv3 = tl.conv2d(l10_conv2, 512, (3, 3), (1, 1), name='l11') with tf.variable_scope('l12_conv4') as scope: l12_conv4 = tl.conv2d(l11_conv3, 512, (3, 3), (1, 1), name='l12') l12_pooling = tl.max_pool2d(l12_conv4, (3, 3), (2, 2), padding='SAME', name='pool') with tf.variable_scope('l13_conv1') as scope: l3_conv1 = tl.conv2d(l12_pooling, 512, (3, 3), (1, 1), name='l13') with tf.variable_scope('l14_conv2') as scope: l14_conv2 = tl.conv2d(l3_conv1, 512, (3, 3), (1, 1), name='l14') with tf.variable_scope('l15_conv3') as scope: l15_conv3 = tl.conv2d(l14_conv2, 512, (3, 3), (1, 1), name='l15') with tf.variable_scope('l16_conv4') as scope: l16_conv4 = tl.conv2d(l15_conv3, 512, (3, 3), (1, 1), name='l16') l16_pooling = tl.max_pool2d(l16_conv4, (3, 3), (2, 2), padding='SAME', name='pool') fc0 = tf.reshape(l16_pooling, [self.batch_size, -1]) fc1 = tl.fc(fc0, 4096, name='fc1') fc1_out = tl.dropout(fc1, self.keep_prob) fc2 = tl.fc(fc1_out, 4096, name='fc2') fc2_out = tl.dropout(fc2, self.keep_prob ) fc3 = tl.fc(fc2_out, 10, name='fc3') return fc3
def inference_MobileNet(self, im): n=6 num_classes=10 width_multiplier=1 net = tl.conv2d(im, round(32 * width_multiplier), (3, 3), (2, 2), padding='SAME', name='conv_1') net = tl.bn_new(net, name='conv_1') net = tl.relu(net) net = self.MobileNet_separable_2d(net, 32, name ='sep1') net = self.MobileNet_separable_2d(net, 64, (2, 2), name='sep2') net = self.MobileNet_separable_2d(net, 128, name ='sep3') net = self.MobileNet_separable_2d(net, 128, (2, 2), name='sep4') net = self.MobileNet_separable_2d(net, 256, name ='sep5') net = self.MobileNet_separable_2d(net, 256, (2, 2), name='sep6') net = self.MobileNet_separable_2d(net, 512, name ='sep7') for i in range(n): net = self.MobileNet_separable_2d(net, 512, name ='sep' + str(i + 8)) net = self.MobileNet_separable_2d(net, 512, (2, 2), name ='sep' + str(n + 9)) net = self.MobileNet_separable_2d(net, 1024, name='sep' + str(n + 10)) #shape = net.get_shape() #net = tl.avg_pool2d(net, shape[1:3], name='avg_pool') net = tf.reshape(net, [self.batch_size, -1]) logits = tl.fc(net, num_classes, name='fc') return logits
def inference_ResNet(self, im): n=5 n_class=10 with tf.variable_scope('conv_0') as scope: y = tl.conv2d(im, 16, (3,3), (1,1), padding='SAME', name='conv_init') y = tl.bn_new(y) y = tl.relu(y) y = self.residual_group(y, 16, n, False, name='group_1') y = self.residual_group(y, 32, n, True, name='group_2') y = self.residual_group(y, 64, n, True, name='group_3') #print(y.get_shape()) #shape = y.get_shape() #y = tl.avg_pool2d(y, shape[1:3], (1, 1), padding='VALID', name='avg_pool') y = tf.reshape(y, [self.batch_size, -1]) y = tl.fc(y, n_class, name='fc') return y
def inference_Inceptionv3(self,im): n=3 # n_class=10 n_class=101 with tf.variable_scope('Inceptionv3') as scope: y = tl.conv2d(im, 32, (3, 3), (2, 2), name='conv0') y = tl.bn_new(y,name='conv1') y = tl.relu(y) y = tl.conv2d(y, 32, (3, 3), (1, 1), name='conv1') y = tl.bn_new(y,name='conv2') y = tl.relu(y) y = tl.conv2d(y, 64, (3, 3), (1, 1), padding='SAME', name='conv2') y = tl.bn_new(y,name='conv3') y = tl.relu(y) y = tl.max_pool2d(y, (3, 3), (2, 2), name='pool1') y = tl.bn_new(y,name='conv4') y = tl.relu(y) # 73 x 73 x 64 y = tl.conv2d(y, 80, (3, 3), (1, 1), name='conv3') y = tl.bn_new(y,name='conv5') y = tl.relu(y) # 73 x 73 x 80. y = tl.conv2d(y, 192, (3, 3), (2, 2), name='conv4') y = tl.bn_new(y,name='conv6') y = tl.relu(y) # 71 x 71 x 192. y = tl.max_pool2d(y, (3, 3), (2, 2), name='pool2') # 35 x 35 x 192. for i in range(n - 1): y = self.Inceptionv3_module1(y, (5, 5),name='mixed_35x35x256a'+str(i)) for i in range(n - 1): y = self.Inceptionv3_module2(y,name='mixed_17x17x768e'+str(i)) for i in range(n - 1): y = self.Inceptionv3_module3(y,name='mixed_8x8x2048a'+str(i)) shape = y.get_shape() y = tl.avg_pool2d(y, shape[1:3], padding='VALID', name='pool') # 1 x 1 x 2048 y = tl.dropout(y, self.keep_prob) y = tl.flatten(y) # 2048 logits = tl.fc(y, n_class, name='logits') return logits