Computer Vision News - February 2018

either using them as a black box or use transfer learning techniques to warm start training algorithms. To code a CNN layer in TensorFlow, you must define several low level operations: 1. Create the weight and bias variables 2. Convolve the weights with the input from the previous layer 3. Add the biases to the result 4. And apply an activation function. This can be rather laborious to code: TF-Slim provides wrappers defined at the neural-network-layer level, streamlining setting up your neural network, while keeping all the options of TensorFlow available. For example, the following embodies the above TensorFlow code in TF-Slim: TF-Slim also provides the useful function repeat, which you can call instead of defining your layers one by one or inside a loop, as you can see in this snippet: One final Slim shortcut we will look at is the arg_scope function, which allows the user to declare a set of variables to be used by the succeeding functions inside the arg_scope function, as demonstrated in the snippet below: TF-Slim wrappers reduce a very lengthy, complex code in TensorFlow to just a few lines. For example, the entire VGG architecture is defined by the following snippet: Computer Vision News 15 Tool We Tried for You: TensorFlow-Slim input = ... with tf.name_scope( 'conv1_1' ) as scope: kernel = tf.Variable(tf.truncated_normal([ 3 , 3 , 64 , 128 ], dtype = tf.float32, stddev = 1e-1 ), name = 'weights' ) conv = tf.nn.conv2d( input , kernel, [ 1 , 1 , 1 , 1 ], padding = 'SAME' ) biases = tf.Variable(tf.constant( 0.0 , shape = [ 128 ], dtype = tf.float32), trainable = True , name = 'biases' ) bias = tf.nn.bias_add(conv, biases) conv1 = tf.nn.relu(bias, name = scope) net = slim.repeat(net, 3 , slim.conv2d, 256 , [ 3 , 3 ], scope = 'conv3' ) with slim.arg_scope([slim.conv2d], padding = 'SAME' , weights_regularizer = slim.l2_regularizer( 0.0005 )): net = slim.conv2d(inputs, 64 , [ 11 , 11 ], scope = 'conv1' ) net = slim.conv2d(net, 128 ,[ 11 , 11 ], scope = 'conv2' ) input = ... net = slim.conv2d( input , 128 , [ 3 , 3 ], scope = 'conv1_1' )

RkJQdWJsaXNoZXIy NTc3NzU=