def inference(images): k = 32 b1 = 6 b2 = 12 b3 = 24 b4 = 16 # conv1 conv1 = helper.convolution(images, [7, 7, 3, k], helper.DECAY, 2, 'conv1') # pool1 pool1 = tf.nn.max_pool(conv1, [1, 3, 3, 1], [1, 2, 2, 1], 'SAME', name='pool1') input1 = helper.dense_block(pool1, k, b1, 'conv1') transition1 = helper.transition(input1, k, b1, 'transition1') input2 = helper.dense_block(transition1, k, b2, 'conv2') transition2 = helper.transition(input2, k, b2, 'transition2') input3 = helper.dense_block(transition2, k, b3, 'conv3') transition3 = helper.transition(input3, k, b3, 'transition3') input4 = helper.dense_block(transition3, k, b4, 'conv4') avg_pool = tf.nn.avg_pool(input4, ksize=[1, 7, 7, 1], strides=[1, 1, 1, 1], padding='SAME') dense = tf.contrib.layers.flatten(avg_pool) with tf.variable_scope("fc") as scope: kernel = helper.variable_with_weight_decay( 'weights', shape=[51200, helper.NUM_CLASSES], stddev=5e-2, wd=helper.DECAY) conv = tf.matmul(dense, kernel) biases = helper.variable_on_cpu('biases', helper.NUM_CLASSES, tf.constant_initializer(0.0)) output = tf.nn.bias_add(conv, biases) return output
def inference(input): conv1 = helper.convolution(input, [7, 7, 3, 64], helper.DECAY, 2, 'conv1') pool1 = tf.nn.max_pool(conv1, ksize=[1, 3, 3, 1], strides=[1, 2, 2, 1], padding='SAME', name='pool1') block1_1 = helper.block_convolution(pool1, 64, helper.DECAY, 1, 'block1_1') + pool1 block1_2 = helper.block_convolution(block1_1, 64, helper.DECAY, 1, 'block1_2') + block1_1 block1_3 = helper.block_convolution( block1_2, 64, helper.DECAY, 2, 'block1_3') + helper.convolution( block1_2, [1, 1, 64, 64], helper.DECAY, 2, 'proj1') block2_1 = helper.block_convolution( block1_3, 128, helper.DECAY, 1, 'block2_1') + helper.convolution( block1_3, [1, 1, 64, 128], helper.DECAY, 1, 'proj2') block2_2 = helper.block_convolution(block2_1, 128, helper.DECAY, 1, 'block2_2') + block2_1 block2_3 = helper.block_convolution(block2_2, 128, helper.DECAY, 1, 'block2_3') + block2_2 block2_4 = helper.block_convolution( block2_3, 128, helper.DECAY, 2, 'block2_4') + helper.convolution( block2_3, [1, 1, 128, 128], helper.DECAY, 2, 'proj3') block3_1 = helper.block_convolution( block2_4, 256, helper.DECAY, 1, 'block3_1') + helper.convolution( block2_4, [1, 1, 128, 256], helper.DECAY, 1, 'proj4') block3_2 = helper.block_convolution(block3_1, 256, helper.DECAY, 1, 'block3_2') + block3_1 block3_3 = helper.block_convolution(block3_2, 256, helper.DECAY, 1, 'block3_3') + block3_2 block3_4 = helper.block_convolution(block3_3, 256, helper.DECAY, 1, 'block3_4') + block3_3 block3_5 = helper.block_convolution(block3_4, 256, helper.DECAY, 1, 'block3_5') + block3_4 block3_6 = helper.block_convolution( block3_5, 256, helper.DECAY, 2, 'block3_6') + helper.convolution( block3_5, [1, 1, 256, 256], helper.DECAY, 2, 'proj5') block4_1 = helper.block_convolution( block3_6, 512, helper.DECAY, 1, 'block4_1') + helper.convolution( block3_6, [1, 1, 256, 512], helper.DECAY, 1, 'proj6') block4_2 = helper.block_convolution(block4_1, 512, helper.DECAY, 1, 'block4_2') + block4_1 block4_3 = helper.block_convolution(block4_2, 512, helper.DECAY, 1, 'block4_3') + block4_2 avg_pool = tf.nn.avg_pool(block4_3, ksize=[1, 7, 7, 1], strides=[1, 1, 1, 1], padding='SAME') dense = tf.contrib.layers.flatten(avg_pool) with tf.variable_scope("fc") as scope: kernel = helper.variable_with_weight_decay( 'weights', shape=[25088, helper.NUM_CLASSES], stddev=5e-2, wd=helper.DECAY) conv = tf.matmul(dense, kernel) biases = helper.variable_on_cpu('biases', helper.NUM_CLASSES, tf.constant_initializer(0.0)) output = tf.nn.bias_add(conv, biases) return output
def gaussian_blur(image, kernel, verbose=False): return convolution(image, kernel, average=True, verbose=verbose)
def inference(images, dropout, is_training): L = 20 N = (L - 6) // 4 d4 = 1024 d4_red = d4 / 4 d3 = d4 / 2 d3_red = d3 / 4 d2 = d3 / 2 d2_red = d2 / 4 d1 = d2 / 2 d1_red = d1 / 4 # conv1 conv1 = helper.convolution(images, [3, 3, 3, d1_red], helper.DECAY, 1, 'conv1', dropout, is_training) conv1 = tf.nn.avg_pool(conv1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID') conv2 = helper.convolution(conv1, [3, 3, d1_red, d1], helper.DECAY, 1, 'conv2', dropout, is_training) conv2 = tf.nn.avg_pool(conv2, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID') x1 = N * [d1] red3 = N * [d1_red] x3 = N * [d1] red5 = N * [d1_red] x5 = N * [d1] pool_proj = N * [d1] block1 = helper.dense_inception(conv2, 'block1', dropout, is_training, red3, red5, x1, x3, x5, pool_proj) transition1 = helper.transition(block1, 'transition1', d2, dropout, is_training) x1 = N * [d2] red3 = N * [d2_red] x3 = N * [d2] red5 = N * [d2_red] x5 = N * [d2] pool_proj = N * [d2] block2 = helper.dense_inception(transition1, 'block2', dropout, is_training, red3, red5, x1, x3, x5, pool_proj) transition2 = helper.transition(block2, 'transition2', d3, dropout, is_training) x1 = N * [d3] red3 = N * [d3_red] x3 = N * [d3] red5 = N * [d3_red] x5 = N * [d3] pool_proj = N * [d3] block3 = helper.dense_inception(transition2, 'block3', dropout, is_training, red3, red5, x1, x3, x5, pool_proj) transition3 = helper.transition(block3, 'transition3', d4, dropout, is_training) x1 = N * [d4] red3 = N * [d4_red] x3 = N * [d4] red5 = N * [d4_red] x5 = N * [d4] pool_proj = N * [d4] block4 = helper.dense_inception(transition3, 'block4', dropout, is_training, red3, red5, x1, x3, x5, pool_proj) output = helper.softmax_classifier(block4, 'output', dropout, is_training) return output