def inference(x, num_output, wd, dropout_rate, is_training, transfer_mode= False): with tf.variable_scope('conv1'): network = common.spatialConvolution(x, 11, 4, 64, wd= wd) network = common.batchNormalization(network, is_training= is_training) network = tf.nn.relu (network) #common.activation_summary(network) network = common.maxPool(network, 3, 2) with tf.variable_scope('conv2'): network = common.spatialConvolution(network, 5, 1, 192, wd= wd) network = common.batchNormalization(network, is_training= is_training) network = tf.nn.relu(network) #common.activation_summary(network) network = common.maxPool(network, 3, 2) with tf.variable_scope('conv3'): network = common.spatialConvolution(network, 3, 1, 384, wd= wd) network = common.batchNormalization(network, is_training= is_training) network = tf.nn.relu(network) #common.activation_summary(network) with tf.variable_scope('conv4'): network = common.spatialConvolution(network, 3, 1, 256, wd= wd) network = common.batchNormalization(network, is_training= is_training) network = tf.nn.relu(network) with tf.variable_scope('conv5'): network = common.spatialConvolution(network, 3, 1, 256, wd= wd) network = common.batchNormalization(network, is_training= is_training) network = tf.nn.relu(network) network = common.maxPool(network, 3, 2) network = common.flatten(network) with tf.variable_scope('fc1'): network = tf.nn.dropout(network, dropout_rate) network = common.fullyConnected(network, 4096, wd= wd) network = common.batchNormalization(network, is_training= is_training) network = tf.nn.relu(network) with tf.variable_scope('fc2'): network = tf.nn.dropout(network, dropout_rate) network = common.fullyConnected(network, 4096, wd= wd) network = common.batchNormalization(network, is_training= is_training) network = tf.nn.relu(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
def inference(x, num_output, wd, dropout_rate, is_training, transfer_mode= False, model_type= 'A'): # Create tables describing VGG configurations A, B, D, E if model_type == 'A': config = [64, 'M', 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'] elif model_type == 'B': config = [64, 64, 'M', 128, 128, 'M', 256, 256, 'M', 512, 512, 'M', 512, 512, 'M'] elif model_type == 'D': config = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 'M', 512, 512, 512, 'M', 512, 512, 512, 'M'] elif model_type == 'E': config = [64, 64, 'M', 128, 128, 'M', 256, 256, 256, 256, 'M', 512, 512, 512, 512, 'M', 512, 512, 512, 512, 'M'] else: print('Unknown model type: ' + model_type + ' | Please specify a modelType A or B or D or E') network= x for k,v in enumerate(config): if v == 'M': network= common.maxPool(network, 2, 2) else: with tf.variable_scope('conv'+str(k)): network = common.spatialConvolution(network, 3, 1, v, wd= wd) network = tf.nn.relu(network) network= common.flatten(network) with tf.variable_scope('fc1'): network = common.fullyConnected(network, 4096, wd= wd) network = tf.nn.relu(network) network = common.batchNormalization(network, is_training= is_training) network = tf.nn.dropout(network, dropout_rate) with tf.variable_scope('fc2'): network = common.fullyConnected(network, 4096, wd= wd) network = tf.nn.relu(network) network = common.batchNormalization(network, is_training= is_training) network = tf.nn.dropout(network, dropout_rate) 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
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
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
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)