当前位置: 首页>>代码示例>>Python>>正文


Python variables.local_variable函数代码示例

本文整理汇总了Python中tensorflow.contrib.framework.python.ops.variables.local_variable函数的典型用法代码示例。如果您正苦于以下问题:Python local_variable函数的具体用法?Python local_variable怎么用?Python local_variable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了local_variable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testGetLocalVariablesReturnsTransients

 def testGetLocalVariablesReturnsTransients(self):
   with self.test_session():
     with variable_scope.variable_scope('A'):
       a = variables_lib2.local_variable(0)
     with variable_scope.variable_scope('B'):
       b = variables_lib2.local_variable(0)
     self.assertEquals([a], variables_lib2.get_local_variables('A'))
     self.assertEquals([b], variables_lib2.get_local_variables('B'))
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:8,代码来源:variables_test.py

示例2: testGetVariablesDontReturnsTransients

 def testGetVariablesDontReturnsTransients(self):
   with self.test_session():
     with variable_scope.variable_scope('A'):
       variables_lib2.local_variable(0)
     with variable_scope.variable_scope('B'):
       variables_lib2.local_variable(0)
     self.assertEquals([], variables_lib2.get_variables('A'))
     self.assertEquals([], variables_lib2.get_variables('B'))
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:8,代码来源:variables_test.py

示例3: test_local_variable

 def test_local_variable(self):
   with self.test_session() as sess:
     self.assertEquals([], variables_lib.local_variables())
     value0 = 42
     variables_lib2.local_variable(value0)
     value1 = 43
     variables_lib2.local_variable(value1)
     variables = variables_lib.local_variables()
     self.assertEquals(2, len(variables))
     self.assertRaises(errors_impl.OpError, sess.run, variables)
     variables_lib.initialize_variables(variables).run()
     self.assertAllEqual(set([value0, value1]), set(sess.run(variables)))
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:12,代码来源:tensor_util_test.py

示例4: testEvaluateWithEvalFeedDict

  def testEvaluateWithEvalFeedDict(self):
    # Create a checkpoint.
    checkpoint_dir = os.path.join(self.get_temp_dir(),
                                  'evaluate_with_eval_feed_dict')
    self._train_model(checkpoint_dir, num_steps=1)

    # We need a variable that that the saver will try to restore.
    variables.get_or_create_global_step()

    # Create a variable and an eval op that increments it with a placeholder.
    my_var = variables.local_variable(0.0, name='my_var')
    increment = array_ops.placeholder(dtype=dtypes.float32)
    eval_ops = state_ops.assign_add(my_var, increment)

    increment_value = 3
    num_evals = 5
    expected_value = increment_value * num_evals
    final_values = evaluation.evaluate_repeatedly(
        checkpoint_dir=checkpoint_dir,
        eval_ops=eval_ops,
        feed_dict={increment: 3},
        final_ops={'my_var': array_ops.identity(my_var)},
        hooks=[evaluation.StopAfterNEvalsHook(num_evals),],
        max_number_of_evaluations=1)
    self.assertEqual(final_values['my_var'], expected_value)
开发者ID:Immexxx,项目名称:tensorflow,代码行数:25,代码来源:evaluation_test.py

示例5: testEvalOpAndFinalOp

  def testEvalOpAndFinalOp(self):
    checkpoint_dir = os.path.join(self.get_temp_dir(), 'eval_ops_and_final_ops')

    # Train a model for a single step to get a checkpoint.
    self._train_model(checkpoint_dir, num_steps=1)
    checkpoint_path = evaluation.wait_for_new_checkpoint(checkpoint_dir)

    # Create the model so we have something to restore.
    inputs = constant_op.constant(self._inputs, dtype=dtypes.float32)
    logistic_classifier(inputs)

    num_evals = 5
    final_increment = 9.0

    my_var = variables.local_variable(0.0, name='MyVar')
    eval_ops = state_ops.assign_add(my_var, 1.0)
    final_ops = array_ops.identity(my_var) + final_increment

    final_ops_values = evaluation.evaluate_once(
        checkpoint_path=checkpoint_path,
        eval_ops=eval_ops,
        final_ops={'value': final_ops},
        hooks=[
            evaluation.StopAfterNEvalsHook(num_evals),
        ])
    self.assertEqual(final_ops_values['value'], num_evals + final_increment)
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:26,代码来源:evaluation_test.py

示例6: testLocalVariableNameAndShape

 def testLocalVariableNameAndShape(self):
   with self.test_session():
     with variable_scope.variable_scope('A'):
       a = variables_lib2.local_variable([1, 1, 1, 1, 1], name='a')
       self.assertEquals(a.op.name, 'A/a')
       self.assertListEqual(a.get_shape().as_list(), [5])
       self.assertListEqual([a], variables_lib2.get_local_variables())
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:7,代码来源:variables_test.py

示例7: testOnlyFinalOp

  def testOnlyFinalOp(self):
    checkpoint_dir = os.path.join(self.get_temp_dir(), 'only_final_ops')

    # Train a model for a single step to get a checkpoint.
    self._train_model(checkpoint_dir, num_steps=1)
    checkpoint_path = evaluation.wait_for_new_checkpoint(checkpoint_dir)

    # Create the model so we have something to restore.
    inputs = constant_op.constant(self._inputs, dtype=dtypes.float32)
    logistic_classifier(inputs)

    final_increment = 9.0

    my_var = variables.local_variable(0.0, name='MyVar')
    final_ops = array_ops.identity(my_var) + final_increment

    final_ops_values = evaluation.evaluate_once(
        checkpoint_path=checkpoint_path, final_ops={'value': final_ops})
    self.assertEqual(final_ops_values['value'], final_increment)
开发者ID:Immexxx,项目名称:tensorflow,代码行数:19,代码来源:evaluation_test.py

示例8: get_or_create_eval_step

def get_or_create_eval_step():
  """Gets or creates the eval step `Tensor`.

  Returns:
    A `Tensor` representing a counter for the evaluation step.

  Raises:
    ValueError: If multiple `Tensors` have been added to the
      `tf.GraphKeys.EVAL_STEP` collection.
  """
  graph = ops.get_default_graph()
  eval_steps = graph.get_collection(ops.GraphKeys.EVAL_STEP)
  if len(eval_steps) == 1:
    return eval_steps[0]
  elif len(eval_steps) > 1:
    raise ValueError('Multiple tensors added to tf.GraphKeys.EVAL_STEP')
  else:
    counter = variables.local_variable(0.0, name='eval_step')
    graph.add_to_collection(ops.GraphKeys.EVAL_STEP, counter)
    return counter
开发者ID:kadeng,项目名称:tensorflow,代码行数:20,代码来源:evaluation.py

示例9: _build_inference_graph

  def _build_inference_graph(self):
    """Build simple inference graph.

    This includes a regular variable, local variable, and fake table.

    Returns:
      Tuple of 3 `Tensor` objects, 2 input and 1 output.
    """
    variables_lib.create_global_step()
    in0 = variables.Variable(1.0)
    in1 = variables_lib.local_variable(2.0)
    fake_table = variables.Variable(
        3.0,
        trainable=False,
        collections=['fake_tables'],
        name='fake_table_var')
    in0.graph.add_to_collections([ops.GraphKeys.TABLE_INITIALIZERS],
                                 fake_table.initializer)
    out = in0 + in1 + fake_table
    return in0, in1, out
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:20,代码来源:graph_actions_test.py

示例10: test_train_loss

 def test_train_loss(self):
   with ops.Graph().as_default() as g, self.test_session(g):
     variables_lib.create_global_step()
     loss_var = variables_lib.local_variable(10.0)
     train_op = control_flow_ops.group(
         state_ops.assign_add(variables_lib.get_global_step(), 1),
         state_ops.assign_add(loss_var, -1.0))
     self._assert_summaries(self._output_dir)
     self._assert_ckpt(self._output_dir, False)
     loss = learn.graph_actions.train(
         g,
         output_dir=self._output_dir,
         train_op=train_op,
         loss_op=loss_var.value(),
         steps=6)
     # TODO(ebrevdo,ptucker,ispir): this meta_graph_def lacks the
     # SaverDef, so we can't add it to the summary assertion test below.
     # meta_graph_def = meta_graph.create_meta_graph_def()
     self.assertEqual(4.0, loss)
     self._assert_summaries(self._output_dir, expected_graphs=[g])
     self._assert_ckpt(self._output_dir, True)
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:21,代码来源:graph_actions_test.py

示例11: testTrainWithLocalVariable

  def testTrainWithLocalVariable(self):
    with ops.Graph().as_default():
      random_seed.set_random_seed(0)
      tf_inputs = constant_op.constant(self._inputs, dtype=dtypes.float32)
      tf_labels = constant_op.constant(self._labels, dtype=dtypes.float32)

      local_multiplier = variables_lib.local_variable(1.0)

      tf_predictions = logistic_classifier(tf_inputs) * local_multiplier
      losses.log_loss(tf_labels, tf_predictions)
      total_loss = losses.get_total_loss()
      optimizer = gradient_descent.GradientDescentOptimizer(learning_rate=1.0)
      train_op = training.create_train_op(total_loss, optimizer)

      loss = training.train(
          train_op,
          None,
          hooks=[basic_session_run_hooks.StopAtStepHook(num_steps=300)],
          save_summaries_steps=None,
          save_checkpoint_secs=None)
      self.assertIsNotNone(loss)
      self.assertLess(loss, .015)
开发者ID:Dr4KK,项目名称:tensorflow,代码行数:22,代码来源:training_test.py

示例12: testTrainWithLocalVariable

  def testTrainWithLocalVariable(self):
    logdir = os.path.join(
        tempfile.mkdtemp(prefix=self.get_temp_dir()), 'tmp_logs')
    with ops.Graph().as_default():
      random_seed.set_random_seed(0)
      tf_inputs = constant_op.constant(self._inputs, dtype=dtypes.float32)
      tf_labels = constant_op.constant(self._labels, dtype=dtypes.float32)

      local_multiplier = variables_lib2.local_variable(1.0)

      tf_predictions = LogisticClassifier(tf_inputs) * local_multiplier
      loss_ops.log_loss(tf_predictions, tf_labels)
      total_loss = loss_ops.get_total_loss()

      optimizer = gradient_descent.GradientDescentOptimizer(learning_rate=1.0)

      train_op = learning.create_train_op(total_loss, optimizer)

      loss = learning.train(
          train_op, logdir, number_of_steps=300, log_every_n_steps=10)
      self.assertIsNotNone(loss)
      self.assertLess(loss, .015)
开发者ID:AndrewTwinz,项目名称:tensorflow,代码行数:22,代码来源:learning_test.py

示例13: testInitializedVariableValue

 def testInitializedVariableValue(self):
   with self.test_session() as sess:
     a = variables_lib2.local_variable([0, 0, 0, 0, 0], name='a')
     sess.run(variables_lib.local_variables_initializer())
     self.assertAllEqual(a.eval(), [0] * 5)
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:5,代码来源:variables_test.py

示例14: testLocalVariableNotInVariablesToRestore

 def testLocalVariableNotInVariablesToRestore(self):
   with self.test_session():
     with variable_scope.variable_scope('A'):
       a = variables_lib2.local_variable(0)
       self.assertFalse(a in variables_lib2.get_variables_to_restore())
       self.assertTrue(a in variables_lib.local_variables())
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:6,代码来源:variables_test.py

示例15: testLocalVariableNotInAllVariables

 def testLocalVariableNotInAllVariables(self):
   with self.test_session():
     with variable_scope.variable_scope('A'):
       a = variables_lib2.local_variable(0)
       self.assertFalse(a in variables_lib.global_variables())
       self.assertTrue(a in variables_lib.local_variables())
开发者ID:AliMiraftab,项目名称:tensorflow,代码行数:6,代码来源:variables_test.py


注:本文中的tensorflow.contrib.framework.python.ops.variables.local_variable函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。