Exemple #1
0
def VGG16(x, n_classes, is_pretrain=True):
    
    x = tools.conv('conv1_1', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv1_2', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool1', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
    
    x = tools.conv('conv2_1', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv2_2', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool2', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
    
    x = tools.conv('conv3_1', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv3_2', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv3_3', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
    
    x = tools.conv('conv4_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv4_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv4_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.conv('conv5_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv5_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv5_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)            

    x = tools.FC_layer('fc6', x, out_nodes=4096)
    #x = tools.batch_norm(x)
    x = tools.FC_layer('fc7', x, out_nodes=4096)
    #x = tools.batch_norm(x)
    x = tools.FC_layer('fc8', x, out_nodes=n_classes)

    return x
def Encoder_VGG(x, z_dim, n_class, is_pretrain=True, reuse = False):
    if (reuse):
        tf.get_variable_scope().reuse_variables() 
    x = tools.conv('conv1_1', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv1_2', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool1', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
    
    x = tools.conv('conv2_1', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv2_2', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool2', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
    
    x = tools.conv('conv3_1', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv3_2', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv3_3', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
    
    x = tools.conv('conv4_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv4_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv4_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.conv('conv5_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv5_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.conv('conv5_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)            

    x = tools.FC_layer('fc6', x, out_nodes=4096)
    x = tools.batch_norm(x)
    z_mu = tools.FC_layer('fc8', x, out_nodes=z_dim)
    z_lv = tools.FC_layer('fc9', x, out_nodes=z_dim)
    y_predict = tools.FC_layer('fc10', z_mu, out_nodes=n_class)
        

    return z_mu, z_lv, y_predict
Exemple #3
0
def VGG16(x, num_class):

    x = tools.conv_bn('conv1_1', x, 64, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv1_2', x, 64, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.pool('pool1', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.conv_bn('conv2_1', x, 128, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv2_2', x, 128, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.pool('pool2', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.conv_bn('conv3_1', x, 256, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv3_2', x, 256, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv3_3', x, 256, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.conv_bn('conv4_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1])
    #x = tools.conv_bn('conv4_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1])
    #x = tools.conv_bn('conv4_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    #x = tools.conv_bn('conv5_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1])
    #x = tools.conv_bn('conv5_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1])
    #x = tools.conv_bn('conv5_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1])
    #x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
    x = tools.conv_1x1('act_1x1' ,x,256,isActive=True)
    x = tools.conv_1x1('down_1x1',x,128,isActive=False)
    x = tools.GAP('GAP',x,is_max_pool=False)
    x = tools.FC_layer('fc6', x, out_nodes=64, isActive=True)
    #x = tools.batch_norm(x,'fc6')
    #x = tools.batch_norm(x,'fc7')
    x = tf.nn.dropout(x,0.5)
    x = tools.FC_layer('fc7', x, out_nodes=num_class)

    return x
Exemple #4
0
def VGG16_comp(x, num_class):

    x = tools.conv_bn('conv1_1', x, 64, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv1_2', x, 64, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.pool('pool1', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.conv_bn('conv2_1', x, 128, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv2_2', x, 128, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.pool('pool2', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.conv_bn('conv3_1', x, 256, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv3_2', x, 256, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv3_3', x, 256, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.conv_bn('conv4_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv4_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv4_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.conv_bn('conv5_1', x, 1024 , kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv5_2', x, 1024 , kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.conv_bn('conv5_3', x, 1024 , kernel_size=[3,3], stride=[1,1,1,1])
    x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)

    x = tools.FC_layer('fc6', x, out_nodes=4096, isActive=True)
    x = tools.FC_layer('fc7', x, out_nodes=2048, isActive=True)
    x = tf.nn.dropout(x,0.7)
    x = tools.FC_layer('fc8', x, out_nodes=num_class)

    return x
Exemple #5
0
def VGG16N(x, n_classes, is_pretrain=True):
    
    with tf.name_scope('VGG16'):

        x = tools.conv('conv1_1', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)   
        x = tools.conv('conv1_2', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        with tf.name_scope('pool1'):    
            x = tools.pool('pool1', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
            
        x = tools.conv('conv2_1', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)    
        x = tools.conv('conv2_2', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        with tf.name_scope('pool2'):    
            x = tools.pool('pool2', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
         
            

        x = tools.conv('conv3_1', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv3_2', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv3_3', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        with tf.name_scope('pool3'):
            x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
            

        x = tools.conv('conv4_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv4_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv4_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        with tf.name_scope('pool4'):
            x = tools.pool('pool4', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
        

        x = tools.conv('conv5_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv5_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv5_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        with tf.name_scope('pool5'):
            x = tools.pool('pool5', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)            
        
        
        x = tools.FC_layer('fc6', x, out_nodes=4096)        
        with tf.name_scope('batch_norm1'):
            x = tools.batch_norm(x)
        feature = tools.FC_layer('fc7', x, out_nodes=4096)

        with tf.name_scope('batch_norm2'):
            x = tools.batch_norm(feature)
        x = tools.FC_layer('fc8', x, out_nodes=n_classes)
    
        return x,feature



#%%







            
def VGG16N(x, n_classes, is_pretrain=True):
# is_pretrain=false : no tranining, use parameter from vgg16.npy
# is_pretrain=true: trainning new parameter
    
    with tf.name_scope('VGG16'):

        x = tools.conv('conv1_1', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=False)   
        x = tools.conv('conv1_2', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=False)
#        x = tf.nn.dropout(x, 0.5) 
        with tf.name_scope('pool1'):    
            x = tools.pool('pool1', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
            
            
        x = tools.conv('conv2_1', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=False)    
        x = tools.conv('conv2_2', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=False)
#        x = tf.nn.dropout(x, 0.5) 
        with tf.name_scope('pool2'):    
            x = tools.pool('pool2', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
            
            

        x = tools.conv('conv3_1', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=False)
        x = tools.conv('conv3_2', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=False)
        x = tools.conv('conv3_3', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=False)
       # x = tf.nn.dropout(x, 0.5) 
        with tf.name_scope('pool3'):
            x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
            

        x = tools.conv('conv4_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=True)
        x = tools.conv('conv4_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=True)
        x = tools.conv('conv4_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=True)
       # x = tf.nn.dropout(x, 0.5) 
        with tf.name_scope('pool4'):
            x = tools.pool('pool4', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
            

        x = tools.conv('conv5_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=True)
        x = tools.conv('conv5_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=True)
        x = tools.conv('conv5_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=True)
        x = tf.nn.dropout(x, 0.5) 
        with tf.name_scope('pool5'):
            x = tools.pool('pool5', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)            
        
        
        x = tools.FC_layer('fc6', x, out_nodes=4096)   
        x = tf.nn.dropout(x, 0.5) 
        #with tf.name_scope('batch_norm1'):
#        x = tools.batch_norm(x)           
        x = tools.FC_layer('fc7', x, out_nodes=4096)        
        #with tf.name_scope('batch_norm2'):
        x = tf.nn.dropout(x,0.5) 
#        x = tools.batch_norm(x) 
                   
        x = tools.FC_layer('fc8', x, out_nodes=n_classes)
    
        return x
Exemple #7
0
def Network(x, n_classes, dropout):
    global is_training
    x = tf.reshape(x, [-1, 28, 28, 1])
    x = tools.conv('conv1', x, 32, kernel_size=[5, 5], is_pretrain=is_pretrain)
    x = tools.pool('pool1', x, is_max_pool=True)
    x = tools.conv('conv2', x, 64, is_pretrain=is_pretrain)
    x = tools.pool('pool2', x, is_max_pool=True)

    fc_x = tools.FC_layer('FC1', x, 1024)

    fc_x = tf.layers.dropout(fc_x, rate=dropout, training=is_training)

    out = tools.FC_layer('FC2', fc_x, n_classes)

    return out
Exemple #8
0
def SVHN(x, n_classes):
    import tools
    '''
    Args:
        images: 4D tensor [batch_size, img_width, img_height, img_channel]
    Notes:
        In each conv layer, the kernel size is:
        [kernel_size, kernel_size, number of input channels, number of output channels].
        number of input channels are from previuous layer, if previous layer is THE input
        layer, number of input channels should be image's channels.


    '''
    x = tools.conv('conv1', x, 64)
    x = tools.pool('pool1', x)

    x = tools.conv('conv2', x, 64)
    x = tools.pool('pool2', x)

    x = tools.conv('conv3', x, 128)
    x = tools.pool('pool3', x)

    x = tools.FC_layer('fc4', x, out_nodes=64)
    x = tools.drop_out('drop_out', x, keep_prob=0.5)
    x = tools.final_layer('softmax', x, out_nodes=n_classes)
    return x
Exemple #9
0
def Generator(x):
    with tf.variable_scope('Generater'):

        x = tools.FC_layer('fc_gen', x, 7 * 7 * 64)

        x = tf.nn.relu(x)
        x = tf.reshape(x, shape=(-1, 7, 7, 64))

        x = tools.deconv('deconv_1_gen',
                         x,
                         32,
                         output_shape=[50, 14, 14, 32],
                         kernel_size=[5, 5],
                         stride=[1, 2, 2, 1])
        x = tf.nn.relu(x)

        x_logits = tools.deconv('deconv_2_gen',
                                x,
                                1,
                                output_shape=[50, 28, 28, 1],
                                kernel_size=[5, 5],
                                stride=[1, 2, 2, 1])
        x = tf.nn.tanh(x_logits)

        return x_logits, x
Exemple #10
0
def Model_finetune(layer, n_classes, is_pretrain=True):
    # '''
    # Model_finetune: that uses varies tools.py function to setup CNN and returns the logits
    # Arg: layer(tensor), n_classes(int), is_pretrain(Booleen)
    # layer: list of images that are decoded in tensor
    # n_classes: batch size for the training
    # is_pretrain: number of classification for output
    # Return: layer(logits)
    # '''
    with tf.name_scope('Model_finetune'):
        # first conv + pool
        layer = tools.conv('conv1_1', layer, 64, kernel_size=[7,7], stride=[1,1,1,1], is_pretrain=is_pretrain)   
        with tf.name_scope('pool1'):    
            layer = tools.pool('pool1', layer, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
        # second conv + pool
        layer = tools.conv('conv2_1', layer, 128, kernel_size=[7,7], stride=[1,1,1,1], is_pretrain=is_pretrain)    
        with tf.name_scope('pool2'):    
            layer = tools.pool('pool2', layer, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
                    
        # thrid conv + pool
        layer = tools.conv('conv3_1', layer, 256, kernel_size=[7,7], stride=[1,1,1,1], is_pretrain=is_pretrain)
        with tf.name_scope('pool3'):
            layer = tools.pool('pool3', layer, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
            
        # fourth conv + pool
        layer = tools.conv('conv4_1', layer, 512, kernel_size=[7,7], stride=[1,1,1,1], is_pretrain=is_pretrain)
        with tf.name_scope('pool4'):
            layer = tools.pool('pool4', layer, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
        
        # fifth conv + pool
        layer = tools.conv('conv5_1', layer, 512, kernel_size=[7,7], stride=[1,1,1,1], is_pretrain=is_pretrain)
        with tf.name_scope('pool5'):
            layer = tools.pool('pool5', layer, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)            
        
        # 3 fully connected layers, last one is softmax
        layer = tools.FC_layer('fc6', layer, out_nodes=2048)        
        with tf.name_scope('batch_norm1'):
            layer = tools.batch_norm(layer)           
        layer = tools.FC_layer('fc7', layer, out_nodes=2048)        
        with tf.name_scope('batch_norm2'):
            layer = tools.batch_norm(layer)            
        layer = tools.FC_layer('fc8', layer, out_nodes=n_classes)
    
        return layer
Exemple #11
0
def VGG16(x, n_class, is_pretrain=True):

    # using the name scope, the tensorboard maybe look better
    with tf.name_scope('VGG16'):

        x = tools.conv('conv1_1', x, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv1_2', x, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool1'):
            x = tools.pool('pool1', x, ksize=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)

        x = tools.conv('conv2_1', x, 128, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv2_2', x, 128, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool2'):
            x = tools.pool('pool2', x, ksize=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)

        x = tools.conv('conv3_1', x, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv3_2', x, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv3_3', x, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool3'):
            x = tools.pool('pool3', x, ksize=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)

        x = tools.conv('conv4_1', x, 512, kernel_size=[3, 3], stride=[1, 2, 2, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv4_2', x, 512, kernel_size=[3, 3], stride=[1, 2, 2, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv4_3', x, 512, kernel_size=[3, 3], stride=[1, 2, 2, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool4'):
            x = tools.pool('pool4', x, ksize=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)

        x = tools.conv('conv5_1', x, 512, kernel_size=[3, 3], stride=[1, 2, 2, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv5_2', x, 512, kernel_size=[3, 3], stride=[1, 2, 2, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv5_3', x, 512, kernel_size=[3, 3], stride=[1, 2, 2, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool5'):
            x = tools.pool('pool5', x, ksize=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)

        x = tools.FC_layer('fc6', x, out_nodes=4096)
        with tf.name_scope('batch_norma1'):
            x = tools.batch_norm(x)     # batch norm can avoid overfit, more efficient than dropout
        x = tools.FC_layer('fc7', x, out_nodes=4096)
        with tf.name_scope('batch_norm2'):
            x = tools.batch_norm(x)
        x = tools.FC_layer('fc8', x, out_nodes=n_class)

        return x
Exemple #12
0
def Network(x, n_classes, dropout, reuse, is_training):
    with tf.variable_scope('ConvNet', reuse=reuse):
        x = x['images']
        x = tf.reshape(x, [-1, 28, 28, 1])
        x = tools.conv('conv1',
                       x,
                       32,
                       kernel_size=[5, 5],
                       is_pretrain=is_pretrain)
        x = tools.pool('pool1', x, is_max_pool=True)
        x = tools.conv('conv2', x, 64, is_pretrain=is_pretrain)
        x = tools.pool('pool2', x, is_max_pool=True)

        fc_x = tools.FC_layer('FC1', x, 1024)

        fc_x = tf.layers.dropout(fc_x, rate=dropout, training=is_training)

        out = tools.FC_layer('FC2', fc_x, n_classes)

    return out
def VGG16_no_fc(x, keep_prob=0.5, is_pretrain=True):
    with tf.name_scope('VGG16'):
        x = tools.conv('conv1_1', x, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv1_2', x, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool1'):
            x = tools.pool('pool1', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)

        x = tools.conv('conv2_1', x, 128, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv2_2', x, 128, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool2'):
            x = tools.pool('pool2', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)

        x = tools.conv('conv3_1', x, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv3_2', x, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv3_3', x, 256, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool3'):
            x = tools.pool('pool3', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)

        x = tools.conv('conv4_1', x, 512, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv4_2', x, 512, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv4_3', x, 512, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool4'):
            x = tools.pool('pool4', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)

        x = tools.conv('conv5_1', x, 512, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv5_2', x, 512, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        x = tools.conv('conv5_3', x, 512, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool5'):
            x = tools.pool('pool5', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1], is_max_pool=True)


        y = tools.FC_layer('fc6', x, out_nodes=2048, keep_prob=keep_prob)
        # with tf.name_scope('batch_norm1'):
        # x = tools.batch_norm(x)
        y = tools.FC_layer('fc7', x, out_nodes=512, keep_prob=keep_prob)
        # with tf.name_scope('batch_norm2'):
        # x = tools.batch_norm(x)
        y = tools.FC_layer('fc8', x, out_nodes=2, keep_prob=keep_prob)

        return x
Exemple #14
0
    def LeNet5(self):

        with tf.name_scope('LeNet5'):

            self.conv1 = tools.conv('conv1',
                                    self.input,
                                    16,
                                    kernel_size=[3, 3],
                                    stride=[1, 1, 1, 1],
                                    is_pretrain=self.is_pretrain)
            self.pool1 = tools.pool('pool1',
                                    self.conv1,
                                    kernel=[1, 3, 3, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True,
                                    is_norm=True)

            self.conv2 = tools.conv('conv2',
                                    self.pool1,
                                    16,
                                    kernel_size=[3, 3],
                                    stride=[1, 1, 1, 1],
                                    is_pretrain=self.is_pretrain)
            self.pool2 = tools.pool('pool2',
                                    self.conv2,
                                    kernel=[1, 3, 3, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True,
                                    is_norm=True)

            self.fc1 = tools.FC_layer('local3', self.pool2, out_nodes=128)
            self.norm1 = tools.batch_norm('batch_norm1', self.fc1)

            self.fc2 = tools.FC_layer('local4', self.norm1, out_nodes=128)
            self.norm2 = tools.batch_norm('batch_norm2', self.fc2)

            self.fc3 = tools.FC_layer('softmax_linear',
                                      self.norm2,
                                      out_nodes=self.n_classes,
                                      use_relu=False)
Exemple #15
0
def AlexNet(x, n_classes, is_pretrain=True):

    with tf.name_scope('AlexNet'):

        x = tools.conv('conv1',
                       x,
                       16,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.pool('pool1',
                       x,
                       kernel=[1, 3, 3, 1],
                       stride=[1, 2, 2, 1],
                       is_max_pool=True,
                       is_norm=True)

        x = tools.conv('conv2',
                       x,
                       16,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.pool('pool2',
                       x,
                       kernel=[1, 3, 3, 1],
                       stride=[1, 2, 2, 1],
                       is_max_pool=True,
                       is_norm=True)

        x = tools.FC_layer('local3', x, out_nodes=128)
        x = tools.batch_norm('batch_norm1', x)

        x = tools.FC_layer('local4', x, out_nodes=128)
        x = tools.batch_norm('batch_norm2', x)

        x = tools.FC_layer('softmax_linear', x, out_nodes=n_classes)

        return x
Exemple #16
0
def mnist_net(x, prob):
    with tf.variable_scope('mnist_net'):

        x = tf.reshape(x, shape=[-1, 28, 28, 1])

        # first convolution layer
        x = tools.conv('conv_layer_1',
                       x,
                       32,
                       kernel_size=[5, 5],
                       stride=[1, 1, 1, 1])
        with tf.name_scope('max_pool_1'):
            x = tools.pool('max_pool_1',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1])

        # second convolution layer
        x = tools.conv('conv_layer_2',
                       x,
                       64,
                       kernel_size=[5, 5],
                       stride=[1, 1, 1, 1])
        with tf.name_scope('max_pool_2'):
            x = tools.pool('max_pool_2',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1])

        # fully convolution layers
        x = tools.FC_layer('fc_layer_1', x, 1024)
        x = tf.nn.relu(x)
        x = tools.drop(x, prob)
        x = tools.FC_layer('fc_layer_2', x, 10)

        return x
Exemple #17
0
def AlexNet(x, n_class):


    x = tools.conv_layer('conv1', x, filter_size=11, strides=4, in_channels=3, out_channels=96, activation=True)

    x = tools.pool('pool1', x, p_ksize=3, p_strides=2, is_max_pool=True)

    x = tools.conv_layer('conv2', x, filter_size=5, strides=1, in_channels=96, out_channels=256, activation=True)

    x = tools.pool('pool2', x, p_ksize=3, p_strides=2, is_max_pool=True)

    x = tools.conv_layer('conv3', x, filter_size=3, strides=1, in_channels=256, out_channels=384, activation=True)

    x = tools.conv_layer('conv4', x, filter_size=3, strides=1, in_channels=384, out_channels=384, activation=True)

    x = tools.conv_layer('conv5', x, filter_size=3, strides=1, in_channels=384, out_channels=256, activation=True)

    x = tools.pool('pool3', x, p_ksize=3, p_strides=2, is_max_pool=True)

    x = tools.FC_layer('FC1', x, out_nodes=4096, if_relu=True)
    x = tools.FC_layer('FC2', x, out_nodes=4096, if_relu=True)

    x = tools.FC_layer('FC3', x, out_nodes=n_class, if_relu=None)
    return x
Exemple #18
0
    def VGG16(self):

        with tf.name_scope('VGG16'):

            self.conv1_1 = tools.conv('conv1_1',
                                      self.input,
                                      64,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.conv1_2 = tools.conv('conv1_2',
                                      self.conv1_1,
                                      64,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.pool1 = tools.pool('pool1',
                                    self.conv1_2,
                                    kernel=[1, 2, 2, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True)

            self.conv2_1 = tools.conv('conv2_1',
                                      self.pool1,
                                      128,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.conv2_2 = tools.conv('conv2_2',
                                      self.conv2_1,
                                      128,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.pool2 = tools.pool('pool2',
                                    self.conv2_2,
                                    kernel=[1, 2, 2, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True)

            self.conv3_1 = tools.conv('conv3_1',
                                      self.pool2,
                                      256,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.conv3_2 = tools.conv('conv3_2',
                                      self.conv3_1,
                                      256,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.conv3_3 = tools.conv('conv3_3',
                                      self.conv3_2,
                                      256,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.pool3 = tools.pool('pool3',
                                    self.conv3_3,
                                    kernel=[1, 2, 2, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True)

            self.conv4_1 = tools.conv('conv4_1',
                                      self.pool3,
                                      512,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.conv4_2 = tools.conv('conv4_2',
                                      self.conv4_1,
                                      512,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.conv4_3 = tools.conv('conv4_3',
                                      self.conv4_2,
                                      512,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.pool4 = tools.pool('pool4',
                                    self.conv4_3,
                                    kernel=[1, 2, 2, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True)

            self.conv5_1 = tools.conv('conv5_1',
                                      self.pool4,
                                      512,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.conv5_2 = tools.conv('conv5_2',
                                      self.conv5_1,
                                      512,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.conv5_3 = tools.conv('conv5_3',
                                      self.conv5_2,
                                      512,
                                      kernel_size=[3, 3],
                                      stride=[1, 1, 1, 1],
                                      is_pretrain=self.is_pretrain)
            self.pool5 = tools.pool('pool5',
                                    self.conv5_3,
                                    kernel=[1, 2, 2, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True)

            self.fc6 = tools.FC_layer('fc6', self.pool5, out_nodes=4096)
            self.batch_norm1 = tools.batch_norm('batch_norm1', self.fc6)

            self.fc7 = tools.FC_layer('fc7', self.batch_norm1, out_nodes=4096)
            self.batch_norm2 = tools.batch_norm('batch_norm2', self.fc7)

            self.fc8 = tools.FC_layer('fc8',
                                      self.batch_norm2,
                                      out_nodes=self.n_classes)
Exemple #19
0
def VGG16N(x, n_classes, keep_prob,is_pretrain=True):
    
    with tf.name_scope('VGG16'):

        x = tools.conv('conv1_1', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)   
        x = tools.conv('conv1_2', x, 64, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
#        with tf.name_scope('batch_norm1'):
#            x = tools.batch_norm(x)
        with tf.name_scope('pool1'):    
            x = tools.pool('pool1', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
        
           
        
        x = tools.conv('conv2_1', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)    
        x = tools.conv('conv2_2', x, 128, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
#        with tf.name_scope('batch_norm2'):
#            x = tools.batch_norm(x) 
        with tf.name_scope('pool2'):    
            x = tools.pool('pool2', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
         
             

        x = tools.conv('conv3_1', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv3_2', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv3_3', x, 256, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
#        with tf.name_scope('batch_norm3'):
#            x = tools.batch_norm(x) 
        with tf.name_scope('pool3'):
            x = tools.pool('pool3', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
        
             

        x = tools.conv('conv4_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv4_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv4_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
#        with tf.name_scope('batch_norm4'):
#            x = tools.batch_norm(x) 
        with tf.name_scope('pool4'):
            x = tools.pool('pool4', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)
        
         

        x = tools.conv('conv5_1', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv5_2', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
        x = tools.conv('conv5_3', x, 512, kernel_size=[3,3], stride=[1,1,1,1], is_pretrain=is_pretrain)
#        with tf.name_scope('batch_norm5'):
#            x = tools.batch_norm(x)  
        with tf.name_scope('pool5'):
            x = tools.pool('pool5', x, kernel=[1,2,2,1], stride=[1,2,2,1], is_max_pool=True)            
        
       
        
        x = tools.FC_layer('fc6', x, out_nodes=4096) 
        
#        with tf.name_scope('batch_norm6'):
#            x = tools.batch_norm(x) 
        #dropouut    
        x=tf.nn.dropout(x, keep_prob)  
        
        x = tools.FC_layer('fc7', x, out_nodes=4096)  
        
#        with tf.name_scope('batch_norm7'):
#            x = tools.batch_norm(x)
        #dropout    
        x=tf.nn.dropout(x, keep_prob) 
        
        fc_output=x            
        x = tools.softmax_layer('fc8', x, out_nodes=n_classes)
    
        return x,fc_output



#%%







            
Exemple #20
0
# with tf.name_scope("x1"):
#     with tf.variable_scope("x1"):
#         x1 = VGG.VGG16N(F, True)
# with tf.name_scope("x2"):
#     with tf.variable_scope("x2"):
#         x2 = VGG.VGG16N(F, True)
# with tf.name_scope("x3"):
#     with tf.variable_scope("x3"):
#         x3 = VGG.VGG16N(F, True)
################################################################
x = tf.concat([F, B, I], 3)
with tf.name_scope("x"):
    with tf.variable_scope("x"):
        x = VGG.VGG16(x)
# x = tf.concat([x1,x2,x3],1)
x = tools.FC_layer('fc9', x, out_nodes=4096)
# with tf.name_scope('batch_norm3'):
#     x = tools.batch_norm(x)
x = tools.FC_layer('fc10', x, out_nodes=4096)
# with tf.name_scope('batch_norm4'):
#     x = tools.batch_norm(x)
x = tools.FC_layer('fc11', x, out_nodes=1024)
# with tf.name_scope('batch_norm5'):
#     x = tools.batch_norm(x)
x = tools.FC_layer('fc12', x, out_nodes=64)
# with tf.name_scope('batch_norm6'):
#     x = tools.batch_norm(x)
x = tools.FC_layer('fc13', x, out_nodes=1, name="x")
loss_MSE = tf.reduce_mean(tf.pow(tf.abs(tf.subtract(x, alpha_diff)), 2),
                          name="loss_MSE")
loss_SAD = tf.reduce_mean(tf.pow(tf.abs(tf.subtract(x, alpha_diff)), 1),
Exemple #21
0
def VGG16N(x, n_classes, IS_PRETRAIN):
    import tools

    x = tools.conv('conv1_1',
                   x,
                   64,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[0])
    x = tools.conv('conv1_2',
                   x,
                   64,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[1])
    x = tools.pool('pool1',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.conv('conv2_1',
                   x,
                   128,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[2])
    x = tools.conv('conv2_2',
                   x,
                   128,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[3])
    x = tools.pool('pool2',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.conv('conv3_1',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[4])
    x = tools.conv('conv3_2',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[5])
    x = tools.conv('conv3_3',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[6])
    x = tools.pool('pool3',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.conv('conv4_1',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[7])
    x = tools.conv('conv4_2',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[8])
    x = tools.conv('conv4_3',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[9])
    x = tools.pool('pool3',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.conv('conv5_1',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[10])
    x = tools.conv('conv5_2',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[11])
    x = tools.conv('conv5_3',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=IS_PRETRAIN[12])
    x = tools.pool('pool3',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.FC_layer('fc6', x, out_nodes=4096, is_pretrain=IS_PRETRAIN[13])
    x = tools.batch_norm(x)
    x = tools.FC_layer('fc7', x, out_nodes=4096, is_pretrain=IS_PRETRAIN[14])
    x = tools.batch_norm(x)
    x = tools.final_layer('fc8', x, out_nodes=n_classes)
    return x
Exemple #22
0
def Myvgg(x, n_class, is_pretrain=True):

    with tf.name_scope('Myvgg'):

        x = tools.conv('conv1_1',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv1_2',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool1'):
            x = tools.pool('pool1',
                           x,
                           ksize=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv2_1',
                       x,
                       128,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv2_2',
                       x,
                       128,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool2'):
            x = tools.pool('pool2',
                           x,
                           ksize=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv3_1',
                       x,
                       256,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv3_2',
                       x,
                       256,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        # x = tools.conv('conv3_3', x, 128, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool3'):
            x = tools.pool('pool3',
                           x,
                           ksize=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.FC_layer('fc6', x, out_nodes=2048)
        with tf.name_scope('batch_norma1'):
            x = tools.batch_norm(
                x)  # batch norm can avoid overfit, more efficient than dropout
        x = tools.FC_layer('fc7', x, out_nodes=2048)
        #x = tools.dropout(x,0.5)
        with tf.name_scope('batch_norm2'):
            x = tools.batch_norm(x)
        x = tools.FC_layer('fc8', x, out_nodes=n_class)

    return x
Exemple #23
0
def VGG16N(x, n_classes, is_pretrain=True):

    with tf.name_scope('VGG16'):

        x = tools.conv('conv1_1',
                       x,
                       8,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv1_2',
                       x,
                       8,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool1'):
            x = tools.pool('pool1',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv2_1',
                       x,
                       16,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv2_2',
                       x,
                       16,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool2'):
            x = tools.pool('pool2',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv3_1',
                       x,
                       32,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv3_2',
                       x,
                       32,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv3_3',
                       x,
                       32,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool3'):
            x = tools.pool('pool3',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv4_1',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv4_2',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv4_3',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool4'):
            x = tools.pool('pool4',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv5_1',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv5_2',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv5_3',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool5'):
            x = tools.pool('pool5',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.FC_layer('fc6', x, out_nodes=512)
        x = tf.nn.dropout(x, 0.5)
        #with tf.name_scope('batch_norm1'):
        #x = tools.batch_norm(x)
        x = tools.FC_layer('fc7', x, out_nodes=512)
        x = tf.nn.dropout(x, 0.5)
        #with tf.name_scope('batch_norm2'):
        #x = tools.batch_norm(x)
        x = tools.FC_layer('fc8', x, out_nodes=512)
        x = tf.nn.dropout(x, 0.5)

        x = tools.FC_layer('fc9', x, out_nodes=24)

        return x


#%%
Exemple #24
0
def VGG16_BN(x, n_classes, is_pretrain=True, is_training=True):
    with tf.name_scope('VGG16'):
        x = tools.conv('conv1_1',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv1_2',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool1'):
            x = tools.pool('pool1',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv2_1',
                       x,
                       128,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv2_2',
                       x,
                       128,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool2'):
            x = tools.pool('pool2',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv3_1',
                       x,
                       256,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv3_2',
                       x,
                       256,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv3_3',
                       x,
                       256,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool3'):
            x = tools.pool('pool3',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv4_1',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv4_2',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv4_3',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool4'):
            x = tools.pool('pool4',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv5_1',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv5_2',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv5_3',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool5'):
            x = tools.pool('pool5',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.FC_layer('fc6', x, out_nodes=4096)
        with tf.name_scope('batch_norm1'):
            x = tools.batch_norm_wrapper(
                x, is_training=is_training)  # 训练时为True,测试为False
        x = tools.FC_layer('fc7', x, out_nodes=4096)
        with tf.name_scope('batch_norm2'):
            x = tools.batch_norm_wrapper(x, is_training=is_training)
        x = tools.last_FC('fc8', x, out_nodes=n_classes)

        return x
Exemple #25
0
def MyResNet(x, n_class, is_pretrain=True):

    with tf.name_scope('MyResNet'):

        x1 = tools.conv('conv1_1',
                        x,
                        64,
                        kernel_size=[3, 3],
                        stride=[1, 1, 1, 1],
                        is_pretrain=is_pretrain)
        x2 = tools.conv_no_relu('conv1_2',
                                x,
                                64,
                                kernel_size=[3, 3],
                                stride=[1, 1, 1, 1],
                                is_pretrain=is_pretrain)
        x3 = tf.add(x1, x2)
        x = tf.nn.relu(x3, name='relu')

        with tf.name_scope('pool1'):
            x = tools.pool('pool1',
                           x,
                           ksize=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x1 = tools.conv('conv2_1',
                        x,
                        128,
                        kernel_size=[3, 3],
                        stride=[1, 1, 1, 1],
                        is_pretrain=is_pretrain)
        x2 = tools.conv_no_relu('conv2_2',
                                x,
                                128,
                                kernel_size=[3, 3],
                                stride=[1, 1, 1, 1],
                                is_pretrain=is_pretrain)
        x3 = tf.add(x1, x2)
        x = tf.nn.relu(x3, name='relu')
        with tf.name_scope('pool2'):
            x = tools.pool('pool2',
                           x,
                           ksize=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x1 = tools.conv('conv3_1',
                        x,
                        256,
                        kernel_size=[1, 1],
                        stride=[1, 1, 1, 1],
                        is_pretrain=is_pretrain)
        x2 = tools.conv_no_relu('conv3_2',
                                x,
                                256,
                                kernel_size=[1, 1],
                                stride=[1, 1, 1, 1],
                                is_pretrain=is_pretrain)
        x3 = tf.add(x1, x2)
        x = tf.nn.relu(x3, name='relu')
        # x = tools.conv('conv3_3', x, 128, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        with tf.name_scope('pool3'):
            x = tools.pool('pool3',
                           x,
                           ksize=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.FC_layer('fc6', x, out_nodes=512)
        with tf.name_scope('batch_norma1'):
            x = tools.batch_norm(
                x)  # batch norm can avoid overfit, more efficient than dropout
        x = tools.FC_layer('fc7', x, out_nodes=512)
        #x = tools.dropout(x,0.5)
        with tf.name_scope('batch_norm2'):
            x = tools.batch_norm(x)
        x = tools.FC_layer('fc8', x, out_nodes=n_class)

    return x
Exemple #26
0
def VGG16_DP(x, n_classes, is_pretrain=True, flag=0):
    with tf.name_scope('VGG16'):
        x = tools.conv('conv1_1',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv1_2',
                       x,
                       64,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool1'):
            x = tools.pool('pool1',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv2_1',
                       x,
                       128,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv2_2',
                       x,
                       128,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool2'):
            x = tools.pool('pool2',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv3_1',
                       x,
                       256,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv3_2',
                       x,
                       256,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv3_3',
                       x,
                       256,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool3'):
            x = tools.pool('pool3',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv4_1',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv4_2',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv4_3',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool4'):
            x = tools.pool('pool4',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.conv('conv5_1',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv5_2',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        x = tools.conv('conv5_3',
                       x,
                       512,
                       kernel_size=[3, 3],
                       stride=[1, 1, 1, 1],
                       is_pretrain=is_pretrain)
        with tf.name_scope('pool5'):
            x = tools.pool('pool5',
                           x,
                           kernel=[1, 2, 2, 1],
                           stride=[1, 2, 2, 1],
                           is_max_pool=True)

        x = tools.FC_layer('fc6', x, out_nodes=4096)
        with tf.name_scope('dropout1'):
            if flag == 0:
                dropout1 = tf.nn.dropout(x, 0.5)
            else:
                dropout1 = tf.nn.dropout(x, 1)
        x = tf.nn.relu(dropout1)
        x = tools.FC_layer('fc7', x, out_nodes=4096)
        with tf.name_scope('dropout2'):
            if flag == 0:
                dropout2 = tf.nn.dropout(x, 0.5)
            else:
                dropout2 = tf.nn.dropout(x, 1)
        x = tf.nn.relu(dropout2)
        x = tools.last_FC('fc8', x, out_nodes=n_classes)
        return x
Exemple #27
0
        outputs = tools.conv('conv2_1',
                             outputs,
                             64,
                             kernel_size=[3, 3],
                             stride=[1, 1, 1, 1],
                             is_pretrain=is_pretrain)
        #outputs = tools.conv('conv2_2', outputs, 64, kernel_size=[3, 3], stride=[1, 1, 1, 1], is_pretrain=is_pretrain)
        outputs = tools.pool('pool2',
                             outputs,
                             kernel=[1, 2, 2, 1],
                             stride=[1, 2, 2, 1],
                             is_max_pool=True)

        outputs = tools.FC_layer('fc6',
                                 outputs,
                                 out_nodes=1024,
                                 activaction_function=tf.nn.relu)
        outputs = tools.batch_norm(outputs)
        outputs = tools.FC_layer('fc7',
                                 outputs,
                                 out_nodes=1024,
                                 activaction_function=tf.nn.relu)
        outputs = tools.batch_norm(outputs)
        logits = tools.FC_layer('fc8',
                                outputs,
                                out_nodes=10,
                                activaction_function=tf.nn.softmax)

    loss = tools.loss(logits, y_)
    accuracy = tools.accuracy(logits, y_)
    my_global_step = tf.Variable(0, name='global_step', trainable=False)
Exemple #28
0
    def AlexNet(self):

        with tf.name_scope('AlexNet'):

            self.conv1 = tools.conv('conv1',
                                    self.input,
                                    96,
                                    kernel_size=[11, 11],
                                    stride=[1, 4, 4, 1],
                                    is_pretrain=self.is_pretrain)
            self.pool1 = tools.pool('pool1',
                                    self.conv1,
                                    kernel=[1, 3, 3, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True,
                                    is_norm=True)

            self.conv2 = tools.conv('conv2',
                                    self.pool1,
                                    256,
                                    kernel_size=[5, 5],
                                    stride=[1, 1, 1, 1],
                                    is_pretrain=self.is_pretrain)
            self.pool2 = tools.pool('pool2',
                                    self.conv2,
                                    kernel=[1, 3, 3, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True,
                                    is_norm=True)

            self.conv3 = tools.conv('conv3',
                                    self.pool2,
                                    384,
                                    kernel_size=[3, 3],
                                    stride=[1, 1, 1, 1],
                                    is_pretrain=self.is_pretrain)
            self.conv4 = tools.conv('conv4',
                                    self.conv3,
                                    384,
                                    kernel_size=[3, 3],
                                    stride=[1, 1, 1, 1],
                                    is_pretrain=self.is_pretrain)
            self.conv5 = tools.conv('conv5',
                                    self.conv4,
                                    256,
                                    kernel_size=[3, 3],
                                    stride=[1, 1, 1, 1],
                                    is_pretrain=self.is_pretrain)
            self.pool5 = tools.pool('pool5',
                                    self.conv5,
                                    kernel=[1, 3, 3, 1],
                                    stride=[1, 2, 2, 1],
                                    is_max_pool=True,
                                    is_norm=True)

            self.fc1 = tools.FC_layer('fc6', self.pool5, out_nodes=4096)
            self.norm1 = tools.batch_norm('batch_norm1', self.fc1)

            self.fc2 = tools.FC_layer('fc7', self.norm1, out_nodes=4096)
            self.norm2 = tools.batch_norm('batch_norm2', self.fc2)

            self.fc3 = tools.FC_layer('softmax_linear',
                                      self.norm2,
                                      out_nodes=self.n_classes,
                                      use_relu=False)
Exemple #29
0
def VGG16PlanInferencet(x, keep_prob, n_classes=12, is_pretrain=True):
    x = tools.conv('conv1_1',
                   x,
                   64,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv1_2',
                   x,
                   64,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool1',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.conv('conv2_1',
                   x,
                   128,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv2_2',
                   x,
                   128,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool2',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.conv('conv3_1',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv3_2',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv3_3',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool3',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.conv('conv4_1',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv4_2',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv4_3',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool3',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.conv('conv5_1',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv5_2',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv5_3',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool3',
                   x,
                   kernel=[1, 2, 2, 1],
                   stride=[1, 2, 2, 1],
                   is_max_pool=True)

    x = tools.FC_layer('fc6', x, out_nodes=4096)
    x = tools.batch_norm(x)
    x = tools.FC_layer('fc7', x, out_nodes=4096)
    x = tools.batch_norm(x)
    x_drop = tf.nn.dropout(x, keep_prob)
    x = tools.FC_layer('fc8', x_drop, out_nodes=n_classes)

    return x
Exemple #30
0
def VGG19(x, n_classes, is_pretrain=True):

    x = tools.conv('conv1_1',
                   x,
                   64,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv1_2',
                   x,
                   64,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool1', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1])

    x = tools.conv('conv2_1',
                   x,
                   128,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv2_2',
                   x,
                   128,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool2', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1])

    x = tools.conv('conv3_1',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv3_2',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv3_3',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv3_4',
                   x,
                   256,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool3', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1])

    x = tools.conv('conv4_1',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv4_2',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv4_3',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv4_4',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool4', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1])

    x = tools.conv('conv5_1',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv5_2',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv5_3',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.conv('conv5_4',
                   x,
                   512,
                   kernel_size=[3, 3],
                   stride=[1, 1, 1, 1],
                   is_pretrain=is_pretrain)
    x = tools.pool('pool5', x, kernel=[1, 2, 2, 1], stride=[1, 2, 2, 1])

    x = tools.FC_layer('fc6', x, out_nodes=4096)
    x = tf.nn.dropout(x, keep_prob=0.5)
    x = tools.FC_layer('fc7', x, out_nodes=4096)
    x = tf.nn.dropout(x, keep_prob=0.5)
    x = tools.FC_layer('fc8', x, out_nodes=n_classes)

    return x