parameters: (x, y, activation=tf.nn.relu)
return_statement: return learn.models.logistic_regression(net, y)
docstring: Builds a residual network.
  
    Note that if the input tensor is 2D, it must be square in order to be
    converted to a 4D tensor.
  
    Borrowed structure from:
    github.com/pkmital/tensorflow_tutorials/blob/master/10_residual_network.py
  
    Args:
      x: Input of the network
      y: Output of the network
      activation: Activation function to apply after each convolution
  
    Returns:
      Predictions and loss tensors.
docstring_summary: Builds a residual network.
docstring_tokens: Builds a residual network .
function: def res_net(x, y, activation=tf.nn.relu):
    """Builds a residual network.
  
    Note that if the input tensor is 2D, it must be square in order to be
    converted to a 4D tensor.
  
    Borrowed structure from:
    github.com/pkmital/tensorflow_tutorials/blob/master/10_residual_network.py
  
    Args:
      x: Input of the network
      y: Output of the network
      activation: Activation function to apply after each convolution
  
    Returns:
      Predictions and loss tensors.
    """
  
    # Configurations for each bottleneck group.
    BottleneckGroup = namedtuple(
        'BottleneckGroup', ['num_blocks', 'num_filters', 'bottleneck_size'])
    groups = [BottleneckGroup(3, 128, 32),
              BottleneckGroup(3, 256, 64),
              BottleneckGroup(3, 512, 128),
              BottleneckGroup(3, 1024, 256)]
  
    input_shape = x.get_shape().as_list()
  
    # Reshape the input into the right shape if it's 2D tensor
    if len(input_shape) == 2:
      ndim = int(sqrt(input_shape[1]))
      x = tf.reshape(x, [-1, ndim, ndim, 1])
  
    # First convolution expands to 64 channels
    with tf.variable_scope('conv_layer1'):
      net = learn.ops.conv2d(x, 64, [7, 7], batch_norm=True,
                             activation=activation, bias=False)
  
    # Max pool
    net = tf.nn.max_pool(
        net, [1, 3, 3, 1], strides=[1, 2, 2, 1], padding='SAME')
  
    # First chain of resnets
    with tf.variable_scope('conv_layer2'):
      net = learn.ops.conv2d(net, groups[0].num_filters,
                             [1, 1], [1, 1, 1, 1],
                             padding='VALID', bias=True)
  
    # Create the bottleneck groups, each of which contains `num_blocks`
    # bottleneck groups.
    for group_i, group in enumerate(groups):
      for block_i in range(group.num_blocks):
        name = 'group_%d/block_%d' % (group_i, block_i)
  
        # 1x1 convolution responsible for reducing dimension
        with tf.variable_scope(name + '/conv_in'):
          conv = learn.ops.conv2d(net, group.bottleneck_size,
                                  [1, 1], [1, 1, 1, 1],
                                  padding='VALID',
                                  activation=activation,
                                  batch_norm=True,
                                  bias=False)
  
        with tf.variable_scope(name + '/conv_bottleneck'):
          conv = learn.ops.conv2d(conv, group.bottleneck_size,
                                  [3, 3], [1, 1, 1, 1],
                                  padding='SAME',
                                  activation=activation,
                                  batch_norm=True,
                                  bias=False)
  
        # 1x1 convolution responsible for restoring dimension
        with tf.variable_scope(name + '/conv_out'):
          input_dim = net.get_shape()[-1].value
          conv = learn.ops.conv2d(conv, input_dim,
                                  [1, 1], [1, 1, 1, 1],
                                  padding='VALID',
                                  activation=activation,
                                  batch_norm=True,
                                  bias=False)
  
        # shortcut connections that turn the network into its counterpart
        # residual function (identity shortcut)
        net = conv + net
  
      try:
        # upscale to the next group size
        next_group = groups[group_i + 1]
        with tf.variable_scope('block_%d/conv_upscale' % group_i):
          net = learn.ops.conv2d(net, next_group.num_filters,
                                 [1, 1], [1, 1, 1, 1],
                                 bias=False,
                                 padding='SAME')
      except IndexError:
        pass
  
    net_shape = net.get_shape().as_list()
    net = tf.nn.avg_pool(net,
                         ksize=[1, net_shape[1], net_shape[2], 1],
                         strides=[1, 1, 1, 1], padding='VALID')
  
    net_shape = net.get_shape().as_list()
    net = tf.reshape(net, [-1, net_shape[1] * net_shape[2] * net_shape[3]])
  
    return learn.models.logistic_regression(net, y)
function_tokens: def res_net ( x , y , activation = tf . nn . relu ) : # Configurations for each bottleneck group. BottleneckGroup = namedtuple ( 'BottleneckGroup' , [ 'num_blocks' , 'num_filters' , 'bottleneck_size' ] ) groups = [ BottleneckGroup ( 3 , 128 , 32 ) , BottleneckGroup ( 3 , 256 , 64 ) , BottleneckGroup ( 3 , 512 , 128 ) , BottleneckGroup ( 3 , 1024 , 256 ) ] input_shape = x . get_shape ( ) . as_list ( ) # Reshape the input into the right shape if it's 2D tensor if len ( input_shape ) == 2 : ndim = int ( sqrt ( input_shape [ 1 ] ) ) x = tf . reshape ( x , [ - 1 , ndim , ndim , 1 ] ) # First convolution expands to 64 channels with tf . variable_scope ( 'conv_layer1' ) : net = learn . ops . conv2d ( x , 64 , [ 7 , 7 ] , batch_norm = True , activation = activation , bias = False ) # Max pool net = tf . nn . max_pool ( net , [ 1 , 3 , 3 , 1 ] , strides = [ 1 , 2 , 2 , 1 ] , padding = 'SAME' ) # First chain of resnets with tf . variable_scope ( 'conv_layer2' ) : net = learn . ops . conv2d ( net , groups [ 0 ] . num_filters , [ 1 , 1 ] , [ 1 , 1 , 1 , 1 ] , padding = 'VALID' , bias = True ) # Create the bottleneck groups, each of which contains `num_blocks` # bottleneck groups. for group_i , group in enumerate ( groups ) : for block_i in range ( group . num_blocks ) : name = 'group_%d/block_%d' % ( group_i , block_i ) # 1x1 convolution responsible for reducing dimension with tf . variable_scope ( name + '/conv_in' ) : conv = learn . ops . conv2d ( net , group . bottleneck_size , [ 1 , 1 ] , [ 1 , 1 , 1 , 1 ] , padding = 'VALID' , activation = activation , batch_norm = True , bias = False ) with tf . variable_scope ( name + '/conv_bottleneck' ) : conv = learn . ops . conv2d ( conv , group . bottleneck_size , [ 3 , 3 ] , [ 1 , 1 , 1 , 1 ] , padding = 'SAME' , activation = activation , batch_norm = True , bias = False ) # 1x1 convolution responsible for restoring dimension with tf . variable_scope ( name + '/conv_out' ) : input_dim = net . get_shape ( ) [ - 1 ] . value conv = learn . ops . conv2d ( conv , input_dim , [ 1 , 1 ] , [ 1 , 1 , 1 , 1 ] , padding = 'VALID' , activation = activation , batch_norm = True , bias = False ) # shortcut connections that turn the network into its counterpart # residual function (identity shortcut) net = conv + net try : # upscale to the next group size next_group = groups [ group_i + 1 ] with tf . variable_scope ( 'block_%d/conv_upscale' % group_i ) : net = learn . ops . conv2d ( net , next_group . num_filters , [ 1 , 1 ] , [ 1 , 1 , 1 , 1 ] , bias = False , padding = 'SAME' ) except IndexError : pass net_shape = net . get_shape ( ) . as_list ( ) net = tf . nn . avg_pool ( net , ksize = [ 1 , net_shape [ 1 ] , net_shape [ 2 ] , 1 ] , strides = [ 1 , 1 , 1 , 1 ] , padding = 'VALID' ) net_shape = net . get_shape ( ) . as_list ( ) net = tf . reshape ( net , [ - 1 , net_shape [ 1 ] * net_shape [ 2 ] * net_shape [ 3 ] ] ) return learn . models . logistic_regression ( net , y )