docstr: This test shows a very simple line model with test_loss.
  
  The template is used to share parameters between a training and test model.
docstr_tok: ["This","test","shows","a","very","simple","line","model","with","test_loss",".","The","template","is","used","to","share","parameters","between","a","training","and","test","model","."]
code: def test_end_to_end(self):
      """This test shows a very simple line model with test_loss.
  
      The template is used to share parameters between a training and test model.
      """
      # y = 2x + 1
      training_input, training_output = (
          [1.0, 2.0, 3.0, 4.0],
          [2.8, 5.1, 7.2, 8.7],
      )
      test_input, test_output = ([5.0, 6.0, 7.0, 8.0], [11, 13, 15, 17])
  
      random_seed.set_random_seed(1234)
  
      def test_line(x):
          m = variable_scope.get_variable(
              "w",
              shape=[],
              initializer=init_ops.truncated_normal_initializer(),
          )
          b = variable_scope.get_variable(
              "b",
              shape=[],
              initializer=init_ops.truncated_normal_initializer(),
          )
          return x * m + b
  
      line_template = template.make_template("line", test_line)
  
      train_prediction = line_template(training_input)
      test_prediction = line_template(test_input)
  
      train_loss = math_ops.reduce_mean(
          math_ops.square(train_prediction - training_output)
      )
      test_loss = math_ops.reduce_mean(
          math_ops.square(test_prediction - test_output)
      )
  
      optimizer = gradient_descent.GradientDescentOptimizer(0.1)
      train_op = optimizer.minimize(train_loss)
  
      with session.Session() as sess:
          self.evaluate(variables.global_variables_initializer())
          initial_test_loss = self.evaluate(test_loss)
          self.evaluate(train_op)
          final_test_loss = self.evaluate(test_loss)
  
      # Parameters are tied, so the loss should have gone down when we trained it.
      self.assertLess(final_test_loss, initial_test_loss)
  
imports: import functools
  import traceback
  from tensorflow.python.client import session
  from tensorflow.python.eager import context
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import random_seed
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import init_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import template
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.ops import variables
  import tensorflow.python.ops.nn_grad
  from tensorflow.python.platform import test
  from tensorflow.python.training import gradient_descent
label_desc: Use image node_id 1 for calling the TemplateTest obj's underlying member method code with example usage: obj.test_end_to_end() and returns: unknown