docstr: This test shows a very simple line model with test_loss in eager mode.
  
  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","in","eager","mode",".","The","template","is","used","to","share","parameters","between","a","training","and","test","model","."]
code: def test_end_to_end_eager(self):
      """This test shows a very simple line model with test_loss in eager mode.
  
      The template is used to share parameters between a training and test model.
      """
      with context.eager_mode():
          # 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)
  
          def train_loss():
              train_prediction = line_template(training_input)
              return math_ops.reduce_mean(
                  math_ops.square(train_prediction - training_output)
              )
  
          def test_loss():
              test_prediction = line_template(test_input)
              return math_ops.reduce_mean(
                  math_ops.square(test_prediction - test_output)
              )
  
          optimizer = gradient_descent.GradientDescentOptimizer(0.1)
          initial_test_loss = test_loss()
          optimizer.minimize(train_loss)
          final_test_loss = test_loss()
  
          # Parameters are tied, so the loss should have gone down after training.
          self.assertLess(
              final_test_loss.numpy(), initial_test_loss.numpy()
          )
  
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 2 for calling the TemplateTest obj's underlying member method code with example usage: obj.test_end_to_end_eager() and returns: unknown, math_ops, math_ops