示例#1
0
def transition(x, K, wd, is_training):
    with tf.variable_scope('conv'):
        current = common.batchNormalization(x, is_training=is_training)
        current = tf.nn.relu(current)
        shape = current.get_shape().as_list()
        dim = math.floor(shape[3] * 0.5)
        current = common.spatialConvolution(current, 1, 1, dim, wd=wd)
        current = common.avgPool(current, 2, 2)
    return current
示例#2
0
def getModel(x, num_output, K, stages, wd, is_training, transfer_mode=False):
    with tf.variable_scope('conv1'):
        x = common.spatialConvolution(x, 7, 2, 2 * K, wd=wd)
        x = common.batchNormalization(x, is_training=is_training)
        x = tf.nn.relu(x)
        x = common.maxPool(x, 3, 2)

    with tf.variable_scope('block1'):
        x = block(x, stages[0], K, is_training=is_training, wd=wd)

    with tf.variable_scope('trans1'):
        x = transition(x, K, wd=wd, is_training=is_training)

    with tf.variable_scope('block2'):
        x = block(x, stages[1], K, is_training=is_training, wd=wd)

    with tf.variable_scope('trans2'):
        x = transition(x, K, wd=wd, is_training=is_training)

    with tf.variable_scope('block3'):
        x = block(x, stages[2], K, is_training=is_training, wd=wd)

    with tf.variable_scope('trans3'):
        x = transition(x, K, wd=wd, is_training=is_training)

    with tf.variable_scope('block4'):
        x = block(x, stages[3], K, is_training=is_training, wd=wd)

    x = common.avgPool(x, 7, 1, padding='VALID')

    x = common.flatten(x)

    if not transfer_mode:
        with tf.variable_scope('output'):
            x = common.fullyConnected(x, num_output, wd=wd)
    else:
        with tf.variable_scope('transfer_output'):
            x = common.fullyConnected(x, num_output, wd=wd)

    return x
示例#3
0
def inference(x, num_output, wd, is_training, transfer_mode= False):
    with tf.variable_scope('block1'):
      network = block(x, [11, 4, 96], wd, is_training)
    network = common.maxPool(network, 3, 2)
    with tf.variable_scope('block2'):
      network = block(network, [5, 1, 256], wd, is_training)
    network = common.maxPool(network, 3, 2)
    with tf.variable_scope('block3'):
      network = block(network, [3, 1, 384], wd, is_training)
    network = common.maxPool(network, 3, 2)
    with tf.variable_scope('block4'):
      network = block(network, [3, 1, 1024], wd, is_training)
    network = common.avgPool(network, 7, 1)
    network = common.flatten(network)
    if not transfer_mode:
      with tf.variable_scope('output'):
        network = common.fullyConnected(network, num_output, wd= wd)
    else:
      with tf.variable_scope('transfer_output'):
        network = common.fullyConnected(network, num_output, wd= wd)

    return network
示例#4
0
def inference(x,
              num_output,
              wd,
              dropout_rate,
              is_training,
              transfer_mode=False):
    with tf.variable_scope('features'):
        with tf.variable_scope('conv1'):
            network = common.spatialConvolution(x, 7, 2, 64, wd=wd)
            network = common.batchNormalization(network,
                                                is_training=is_training)
            network = tf.nn.relu(network)
        network = common.maxPool(network, 3, 2)
        with tf.variable_scope('conv2'):
            network = common.spatialConvolution(network, 1, 1, 64, wd=wd)
            network = common.batchNormalization(network,
                                                is_training=is_training)
            network = tf.nn.relu(network)
        with tf.variable_scope('conv3'):
            network = common.spatialConvolution(network, 3, 1, 192, wd=wd)
            network = common.batchNormalization(network,
                                                is_training=is_training)
            network = tf.nn.relu(network)
        network = common.maxPool(network, 3, 2)
        with tf.variable_scope('inception3a'):
            network = inception(network,
                                64, [96, 128], [16, 32],
                                32,
                                wd=wd,
                                is_training=is_training)
        with tf.variable_scope('inception3b'):
            network = inception(network,
                                128, [128, 192], [32, 96],
                                64,
                                wd=wd,
                                is_training=is_training)
        network = common.maxPool(network, 3, 2)
        with tf.variable_scope('inception4a'):
            network = inception(network,
                                192, [96, 208], [16, 48],
                                64,
                                wd=wd,
                                is_training=is_training)
        with tf.variable_scope('inception4b'):
            network = inception(network,
                                160, [112, 224], [24, 64],
                                64,
                                wd=wd,
                                is_training=is_training)
        with tf.variable_scope('inception4c'):
            network = inception(network,
                                128, [128, 256], [24, 64],
                                64,
                                wd=wd,
                                is_training=is_training)
        with tf.variable_scope('inception4d'):
            network = inception(network,
                                112, [144, 288], [32, 64],
                                64,
                                wd=wd,
                                is_training=is_training)

    with tf.variable_scope('mainb'):
        with tf.variable_scope('inception4e'):
            main_branch = inception(network,
                                    256, [160, 320], [32, 128],
                                    128,
                                    wd=wd,
                                    is_training=is_training)
        main_branch = common.maxPool(main_branch, 3, 2)
        with tf.variable_scope('inception5a'):
            main_branch = inception(main_branch,
                                    256, [160, 320], [32, 128],
                                    128,
                                    wd=wd,
                                    is_training=is_training)
        with tf.variable_scope('inception5b'):
            main_branch = inception(main_branch,
                                    384, [192, 384], [48, 128],
                                    128,
                                    wd=wd,
                                    is_training=is_training)
        main_branch = common.avgPool(main_branch, 7, 1)
        main_branch = common.flatten(main_branch)
        main_branch = tf.nn.dropout(main_branch, dropout_rate)
        if not transfer_mode:
            with tf.variable_scope('output'):
                main_branch = common.fullyConnected(main_branch,
                                                    num_output,
                                                    wd=wd)
        else:
            with tf.variable_scope('transfer_output'):
                main_branch = common.fullyConnected(main_branch,
                                                    num_output,
                                                    wd=wd)

    with tf.variable_scope('auxb'):
        aux_classifier = common.avgPool(network, 5, 3)
        with tf.variable_scope('conv1'):
            aux_classifier = common.spatialConvolution(aux_classifier,
                                                       1,
                                                       1,
                                                       128,
                                                       wd=wd)
            aux_classifier = common.batchNormalization(aux_classifier,
                                                       is_training=is_training)
            aux_classifier = tf.nn.relu(aux_classifier)
        aux_classifier = common.flatten(aux_classifier)
        with tf.variable_scope('fc1'):
            aux_classifier = common.fullyConnected(aux_classifier, 1024, wd=wd)
            aux_classifier = tf.nn.dropout(aux_classifier, dropout_rate)
        if not transfer_mode:
            with tf.variable_scope('output'):
                aux_classifier = common.fullyConnected(aux_classifier,
                                                       num_output,
                                                       wd=wd)
        else:
            with tf.variable_scope('transfer_output'):
                aux_classifier = common.fullyConnected(aux_classifier,
                                                       num_output,
                                                       wd=wd)

    return tf.concat([main_branch, aux_classifier], 1)