parameters: (class_count, final_tensor_name, bottleneck_tensor)
return_statement: return (train_step, cross_entropy_mean, bottleneck_input, ground_truth_input,
            final_tensor)
docstring: Adds a new softmax and fully-connected layer for training.
  
    We need to retrain the top layer to identify our new classes, so this function
    adds the right operations to the graph, along with some variables to hold the
    weights, and then sets up all the gradients for the backward pass.
  
    The set up for the softmax and fully-connected layers is based on:
    https://tensorflow.org/versions/master/tutorials/mnist/beginners/index.html
  
    Args:
      class_count: Integer of how many categories of things we're trying to
      recognize.
      final_tensor_name: Name string for the new final node that produces results.
      bottleneck_tensor: The output of the main CNN graph.
  
    Returns:
      The tensors for the training and cross entropy results, and tensors for the
      bottleneck input and ground truth input.
docstring_summary: Adds a new softmax and fully-connected layer for training.
docstring_tokens: Adds a new softmax and fully - connected layer for training .
function: def add_final_training_ops(class_count, final_tensor_name, bottleneck_tensor):
    """Adds a new softmax and fully-connected layer for training.
  
    We need to retrain the top layer to identify our new classes, so this function
    adds the right operations to the graph, along with some variables to hold the
    weights, and then sets up all the gradients for the backward pass.
  
    The set up for the softmax and fully-connected layers is based on:
    https://tensorflow.org/versions/master/tutorials/mnist/beginners/index.html
  
    Args:
      class_count: Integer of how many categories of things we're trying to
      recognize.
      final_tensor_name: Name string for the new final node that produces results.
      bottleneck_tensor: The output of the main CNN graph.
  
    Returns:
      The tensors for the training and cross entropy results, and tensors for the
      bottleneck input and ground truth input.
    """
    with tf.name_scope('input'):
      bottleneck_input = tf.placeholder_with_default(
          bottleneck_tensor, shape=[None, BOTTLENECK_TENSOR_SIZE],
          name='BottleneckInputPlaceholder')
  
      ground_truth_input = tf.placeholder(tf.float32,
                                          [None, class_count],
                                          name='GroundTruthInput')
  
    # Organizing the following ops as `final_training_ops` so they're easier
    # to see in TensorBoard
    layer_name = 'final_training_ops'
    with tf.name_scope(layer_name):
      with tf.name_scope('weights'):
        layer_weights = tf.Variable(tf.truncated_normal([BOTTLENECK_TENSOR_SIZE, class_count], stddev=0.001), name='final_weights')
        variable_summaries(layer_weights, layer_name + '/weights')
      with tf.name_scope('biases'):
        layer_biases = tf.Variable(tf.zeros([class_count]), name='final_biases')
        variable_summaries(layer_biases, layer_name + '/biases')
      with tf.name_scope('Wx_plus_b'):
        logits = tf.matmul(bottleneck_input, layer_weights) + layer_biases
        tf.histogram_summary(layer_name + '/pre_activations', logits)
  
    final_tensor = tf.nn.softmax(logits, name=final_tensor_name)
    tf.histogram_summary(final_tensor_name + '/activations', final_tensor)
  
    with tf.name_scope('cross_entropy'):
      cross_entropy = tf.nn.softmax_cross_entropy_with_logits(
        logits, ground_truth_input)
      with tf.name_scope('total'):
        cross_entropy_mean = tf.reduce_mean(cross_entropy)
      tf.scalar_summary('cross entropy', cross_entropy_mean)
  
    with tf.name_scope('train'):
      train_step = tf.train.GradientDescentOptimizer(FLAGS.learning_rate).minimize(
          cross_entropy_mean)
  
    return (train_step, cross_entropy_mean, bottleneck_input, ground_truth_input,
            final_tensor)
function_tokens: def add_final_training_ops ( class_count , final_tensor_name , bottleneck_tensor ) : with tf . name_scope ( 'input' ) : bottleneck_input = tf . placeholder_with_default ( bottleneck_tensor , shape = [ None , BOTTLENECK_TENSOR_SIZE ] , name = 'BottleneckInputPlaceholder' ) ground_truth_input = tf . placeholder ( tf . float32 , [ None , class_count ] , name = 'GroundTruthInput' ) # Organizing the following ops as `final_training_ops` so they're easier # to see in TensorBoard layer_name = 'final_training_ops' with tf . name_scope ( layer_name ) : with tf . name_scope ( 'weights' ) : layer_weights = tf . Variable ( tf . truncated_normal ( [ BOTTLENECK_TENSOR_SIZE , class_count ] , stddev = 0.001 ) , name = 'final_weights' ) variable_summaries ( layer_weights , layer_name + '/weights' ) with tf . name_scope ( 'biases' ) : layer_biases = tf . Variable ( tf . zeros ( [ class_count ] ) , name = 'final_biases' ) variable_summaries ( layer_biases , layer_name + '/biases' ) with tf . name_scope ( 'Wx_plus_b' ) : logits = tf . matmul ( bottleneck_input , layer_weights ) + layer_biases tf . histogram_summary ( layer_name + '/pre_activations' , logits ) final_tensor = tf . nn . softmax ( logits , name = final_tensor_name ) tf . histogram_summary ( final_tensor_name + '/activations' , final_tensor ) with tf . name_scope ( 'cross_entropy' ) : cross_entropy = tf . nn . softmax_cross_entropy_with_logits ( logits , ground_truth_input ) with tf . name_scope ( 'total' ) : cross_entropy_mean = tf . reduce_mean ( cross_entropy ) tf . scalar_summary ( 'cross entropy' , cross_entropy_mean ) with tf . name_scope ( 'train' ) : train_step = tf . train . GradientDescentOptimizer ( FLAGS . learning_rate ) . minimize ( cross_entropy_mean ) return ( train_step , cross_entropy_mean , bottleneck_input , ground_truth_input , final_tensor )