def classify(inputs, num_classes, dropout_keep_prob=0.5, scope='cnn_v4', reuse=None, is_training=True): """ model used to make predictions input: x -> shape=[None,bands,frames,num_channels] output: logits -> shape=[None,num_labels] """ with slim.arg_scope(simple_arg_scope()): #with slim.arg_scope(batchnorm_arg_scope()): with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=is_training): with tf.variable_scope(scope, [inputs], reuse=reuse) as scope: net = tf.expand_dims( inputs, -1 ) #input needs to be in the format NHWC!! if there is only one channel, expand it by 1 dimension print('model input shape: %s' % net.get_shape()) net = slim.repeat(net, 2, slim.conv2d, 64, [3, 9], scope='conv1') net = slim.max_pool2d(net, [2, 2], scope='pool1') net = slim.repeat(net, 3, slim.conv2d, 128, [3, 5], scope='conv2') net = slim.max_pool2d(net, [2, 2], scope='pool2') net = slim.repeat(net, 3, slim.conv2d, 256, [3, 3], scope='conv3') net = slim.max_pool2d(net, [2, 2], scope='pool3') net = slim.flatten(net) net = slim.fully_connected(net, 4096, scope='fc1') net = slim.dropout(net, dropout_keep_prob, is_training=is_training, scope='dropout1') net = slim.fully_connected(net, 4096, scope='fc2') net = slim.dropout(net, dropout_keep_prob, is_training=is_training, scope='dropout2') logits = slim.fully_connected(net, num_classes, scope='fc3', activation_fn=None) return logits
def classify(inputs, num_estimator, num_classes, dropout_keep_prob=0.5, middle_size=3, gamma_decay=1e-6, weight_decay=0., scope=None, reuse=None, is_training=True): """ model used to make predictions input: x -> shape=[None,bands,frames,num_channels] output: logits -> shape=[None,num_labels] """ with slim.arg_scope(simple_arg_scope(weight_decay=weight_decay)): #with slim.arg_scope(batchnorm_arg_scope()): with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=is_training): with tf.variable_scope(scope, 'model_v1', [inputs], reuse=reuse) as scope: net = tf.expand_dims( inputs, -1 ) #input needs to be in the format NHWC!! if there is only one channel, expand it by 1 dimension with tf.variable_scope('bottom'): net = slim.conv2d(net, 32, [3, 3], rate=2, scope='convB1') net = slim.max_pool2d(net, [2, 2], scope='poolB1') #random block with tf.variable_scope('middle'): net = slim.repeat(net, middle_size, slim.conv2d, 32, [3, 3], scope='convM') #, reuse=i>0 net = slim.max_pool2d(net, [2, 1], scope='poolM') # Use conv2d instead of fully_connected layers. with tf.variable_scope('top'): net = slim.flatten(net) net = slim.fully_connected(net, 64, scope='fc1') net = slim.dropout(net, dropout_keep_prob, is_training=is_training, scope='dropout1') logits = slim.fully_connected(net, num_classes, scope='fc2', activation_fn=None) gamma = tf.Variable(1. / (num_estimator), name='gamma') tf.losses.add_loss( tf.nn.l2_loss(gamma), loss_collection=tf.GraphKeys.REGULARIZATION_LOSSES) return logits, gamma
def classify(x, num_classes, num_filter, dropout_keep_prob=0.5, weight_decay=5e-4, scope='model_v1', reuse=None, route=3, is_training=True): """ model used to make predictions input: x -> shape=[None,bands,frames,num_channels] output: logits -> shape=[None,num_labels] """ with slim.arg_scope(simple_arg_scope(weight_decay=weight_decay)): #with slim.arg_scope(batchnorm_arg_scope()): with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=is_training): with tf.variable_scope(scope, [x], reuse=reuse) as sc: net = tf.expand_dims( x, -1 ) #input needs to be in the format NHWC!! if there is only one channel, expand it by 1 dimension with tf.variable_scope('stump'): net = slim.conv2d(net, 16, [1, 7], scope='conv1x7') net = slim.max_pool2d(net, [1, 2], stride=[1, 2], scope='pool1') net = slim.conv2d(net, num_filter, [1, 5], scope='conv1x5') with tf.variable_scope('middle'): for i in range(route): net = slim.max_pool2d(net, [1, 2], stride=[1, 2], scope='pool%d' % (i + 2)) net = slim.conv2d(net, num_filter, [3, 3], scope='conv3x3_%d' % (i + 2)) #net = tf.reduce_max(net, 2) with tf.variable_scope('top'): net = slim.flatten(net) net = slim.dropout(net, dropout_keep_prob, is_training=is_training, scope='dropout1') logits = slim.fully_connected(net, num_classes, scope='fc2', activation_fn=None) return logits
def classify(inputs, num_estimator, num_classes, dropout_keep_prob=0.5, middle_size=6, gamma_decay=1e-6, weight_decay=0., scope=None, reuse=None, is_training=True): """ model used to make predictions input: x -> shape=[None,bands,frames,num_channels] output: logits -> shape=[None,num_labels] """ with slim.arg_scope(simple_arg_scope(weight_decay=weight_decay)): #with slim.arg_scope(batchnorm_arg_scope()): with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=is_training): with tf.variable_scope(scope, 'model_v1', [inputs], reuse=reuse) as scope: net = tf.expand_dims( inputs, -1 ) #input needs to be in the format NHWC!! if there is only one channel, expand it by 1 dimension net = slim.conv2d(net, 64, [3, 9], scope='conv1') net = slim.max_pool2d(net, [1, 2], scope='pool1') net = slim.conv2d(net, 128, [3, 5], scope='conv2') net = slim.max_pool2d(net, [1, 2], scope='pool2') net = slim.flatten(net) net = slim.fully_connected(net, 256, scope='fc1') net = slim.dropout(net, dropout_keep_prob, is_training=is_training, scope='dropout1') logits = slim.fully_connected(net, num_classes, scope='fc2', activation_fn=None) return logits
def classify(inputs, num_classes, dropout_keep_prob=0.5, middle_size=1, bottom_size=1, weight_decay=1e-5, fc_size=16, num_filter=16, scope=None, reuse=None, is_training=True): """ model used to make predictions input: x -> shape=[None,bands,frames,num_channels] output: logits -> shape=[None,num_labels] """ with slim.arg_scope(simple_arg_scope(weight_decay=weight_decay)): #with slim.arg_scope(batchnorm_arg_scope()): with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=is_training): with tf.variable_scope(scope, 'model_v1', [inputs], reuse=reuse) as scope: net = tf.expand_dims( inputs, -1 ) #input needs to be in the format NHWC!! if there is only one channel, expand it by 1 dimension with tf.variable_scope('bottom'): #net = slim.conv2d(net, num_filter, [4, 4], rate=2, scope='convB1') net = slim.repeat(net, bottom_size, slim.conv2d, num_filter, [3, 9], scope='convB2') net = slim.max_pool2d(net, [1, 2], stride=[1, 2], scope='poolB1') #random block with tf.variable_scope('middle'): net = slim.repeat(net, middle_size, slim.conv2d, num_filter, [3, 5], scope='convM1') #, reuse=i>0 net = slim.max_pool2d(net, [1, 2], stride=[1, 2], scope='poolM') net = slim.repeat(net, middle_size, slim.conv2d, num_filter, [3, 3], scope='convM2') #, reuse=i>0 net = slim.max_pool2d(net, [1, 2], stride=[1, 2], scope='poolM') net = slim.repeat(net, middle_size, slim.conv2d, num_filter, [3, 3], scope='convM3') #, reuse=i>0 net = slim.max_pool2d(net, [1, 2], stride=[1, 2], scope='poolM') #net = slim.repeat(net, middle_size, slim.conv2d, num_filter, [3, 3], scope='convM4') #, reuse=i>0 #net = slim.max_pool2d(net, [1, 2], stride=[1, 2], scope='poolM') # Use conv2d instead of fully_connected layers. with tf.variable_scope('top'): net = slim.flatten(net) net = slim.fully_connected(net, fc_size, scope='fc1') net = slim.dropout(net, dropout_keep_prob, is_training=is_training, scope='dropout1') logits = slim.fully_connected(net, num_classes, scope='fc2', activation_fn=None) return logits
def classify( x, num_classes, num_layers=[2, 2, 2], #,2], scope='resnet_18_v1', reuse=None, is_training=True): """ resnet-18 used to make predictions """ with slim.arg_scope(simple_arg_scope()): with slim.arg_scope(batchnorm_arg_scope()): with slim.arg_scope([slim.batch_norm, slim.dropout], is_training=is_training): with slim.arg_scope( [slim.conv2d], weights_initializer=slim.variance_scaling_initializer( seed=0)): with tf.variable_scope(scope, [x], reuse=reuse) as sc: x = tf.expand_dims( x, -1 ) #input needs to be in the format NHWC!! if there is only one channel, expand it by 1 dimension num_blocks = len(num_layers) stride = 1 # initial convolution with tf.variable_scope('bottom', [x]): shortcut = x = slim.conv2d(x, 64, [3, 7], scope='convInit') #shortcut = x = slim.avg_pool2d(x, [1,2], 2) #resnet blocks for i in range(num_blocks): with tf.variable_scope("block%d" % i): depth = 2**(i + 6) #64,128,256,512 for j in range(num_layers[i]): residual = slim.conv2d(x, depth, [3, 3], stride, scope='convA%d.%d' % (i, j)) residual = slim.conv2d(residual, depth, [3, 3], activation_fn=None, scope='convB%d.%d' % (i, j)) shortcut = x = tf.nn.relu(shortcut + residual) stride = 1 if i + 1 < num_blocks: shortcut = slim.conv2d(x, 2**(i + 6 + 1), 1, stride=2, scope='convS.%d' % i) stride = 2 #print (x.get_shape()) # initial convolution with tf.variable_scope('top', [x]): x = tf.reduce_mean(x, [1, 2], name='global_pool') logits = slim.fully_connected(x, num_classes, scope='logits', activation_fn=None) return logits