Ejemplo n.º 1
0
def inference(input_layer, para_data, train_phase, keep_prob):
    parameters = []
    #input shape should be (N,32,104,2)
    input_depth = input_layer.shape[-1]

    #input[N,32,100,3],output[N,32,104,64]
    with tf.variable_scope('preprocess'):
        bn_input = bm.batch_norm_layer(input_layer, train_phase, 'bn_input')
        filter = bm.weight_variable([3,3,input_depth,64], 'filter_input')
        biases = bm.bias_variable([64])
        conv_input = bm.conv2d(bn_input, filter, 1, 'SAME') + biases

    #input[N,32,104,64],output[N,32,104,128]
    #first layer not change the depth
    resnet_l1, p1 = resnet_first_layer(conv_input, 128, train_phase, 'resnet_l1')
    parameters[0:0] = p1

    #input[N,32,104,128],output[N,16,52,256]
    resnet_l2, p2 = resnet_layer(resnet_l1, 256, train_phase, 'resnet_l2')
    parameters[0:0] = p2

    #input[N,16,52,256],output[N,8,26,512]
    resnet_l3, p3 = resnet_layer(resnet_l2, 512, train_phase, 'resnet_l3')
    parameters[0:0] = p3

    #input[N,8,26,512],output[N,4,13,1024]
    resnet_l4, p4 = resnet_layer(resnet_l3, 1024, train_phase, 'resnet_l4')
    parameters[0:0] = p4

    #pad for avg pool
    #input[N,4,13,1024],output[N,6,15,1024]
    resnet_l4_pad = tf.pad(resnet_l4, [[0,0],[1,1],[1,1],[0,0]], 'CONSTANT', 'l4_pad')
    #input[N,6,15,1024],output[N,2,5,1024]
    avg_pool_layer = tf.nn.avg_pool(resnet_l4_pad, [1,3,3,1], [1,3,3,1], 'VALID')

    #platten for fc
    #input[N,2,5,1024],output[N,2*5*1024]
    avg_pool_flat = tf.reshape(avg_pool_layer, [-1, 2 * 5 * 1024])

    #fc layer
    #input[N,4*9*1024],output[N,512]
    fc1, p_fc = bm.fc_layer(avg_pool_flat, 512)
    parameters[0:0] = p_fc

    # link the para_data(N,556)
    fc1_link = tf.concat([fc1, para_data], axis=1)

    # fc layer2(N,256)
    fc2, fc_weight2 = bm.fc_bn_drop_layer(fc1_link, 256, train_phase, keep_prob, "fc2")
    parameters[0:0] = fc_weight2

    # score layer
    y_pred, score_weight = bm.score_layer(fc2, 3)
    parameters[0:0] = score_weight

    return y_pred, parameters
Ejemplo n.º 2
0
def inference(input_layer, para_data, train_phase, keep_prob):
    with tf.variable_scope("inference"):
        parameters = []
        # input (N,32,104,2)
        bn_input = bm.batch_norm_layer(input_layer, train_phase, "bn_input")

        # conv1 (N,16,52,64)
        conv1, filter1 = bm.conv_bn_pool_layer(bn_input, 64, train_phase,
                                               "conv1")
        parameters[0:0] = filter1

        # conv2 (N,8,26,128)
        conv2, filter2 = bm.conv_bn_pool_layer(conv1, 128, train_phase,
                                               "conv2")
        parameters[0:0] = filter2

        # conv3 (N, 4, 13, 256)
        conv3, filter3 = bm.conv_bn_pool_layer(conv2, 256, train_phase,
                                               "conv3")
        parameters[0:0] = filter3

        # flat
        flat_conv3 = tf.reshape(conv3, [-1, 4 * 13 * 256])

        # fc layer1(N, 512)
        fc1, fc_weight1 = bm.fc_bn_drop_layer(flat_conv3, 512, train_phase,
                                              keep_prob, "fc1")
        parameters[0:0] = fc_weight1

        #link the para_data
        fc1_link = tf.concat([fc1, para_data], axis=1)

        #fc layer2(N,256)
        fc2, fc_weight2 = bm.fc_bn_drop_layer(fc1_link, 256, train_phase,
                                              keep_prob, "fc2")
        parameters[0:0] = fc_weight2

        # score layer
        y_pred, score_weight = bm.score_layer(fc2, 3)
        parameters[0:0] = score_weight

    return y_pred, parameters