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


Python variables.variable方法代码示例

本文整理汇总了Python中inception.slim.variables.variable方法的典型用法代码示例。如果您正苦于以下问题:Python variables.variable方法的具体用法?Python variables.variable怎么用?Python variables.variable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在inception.slim.variables的用法示例。


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

示例1: testVariableWithReplicaDeviceSetter

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testVariableWithReplicaDeviceSetter(self):
    with self.test_session():
      with tf.device(tf.train.replica_device_setter(ps_tasks=2)):
        a = variables.variable('a', [])
        b = variables.variable('b', [])
        c = variables.variable('c', [], device='cpu:12')
        d = variables.variable('d', [])
        with tf.device('cpu:99'):
          e_init = tf.constant(12)
        e = variables.variable('e', initializer=e_init)
      # The values below highlight how the replica_device_setter puts initial
      # values on the worker job, and how it merges explicit devices.
      self.assertDeviceEqual(a.device, '/job:ps/task:0/cpu:0')
      self.assertDeviceEqual(a.initial_value.device, '/job:worker/cpu:0')
      self.assertDeviceEqual(b.device, '/job:ps/task:1/cpu:0')
      self.assertDeviceEqual(b.initial_value.device, '/job:worker/cpu:0')
      self.assertDeviceEqual(c.device, '/job:ps/task:0/cpu:12')
      self.assertDeviceEqual(c.initial_value.device, '/job:worker/cpu:12')
      self.assertDeviceEqual(d.device, '/job:ps/task:1/cpu:0')
      self.assertDeviceEqual(d.initial_value.device, '/job:worker/cpu:0')
      self.assertDeviceEqual(e.device, '/job:ps/task:0/cpu:0')
      self.assertDeviceEqual(e.initial_value.device, '/job:worker/cpu:99') 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:24,代码来源:variables_test.py

示例2: testVariableWithVariableDeviceChooser

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testVariableWithVariableDeviceChooser(self):

    with tf.Graph().as_default():
      device_fn = variables.VariableDeviceChooser(num_parameter_servers=2)
      with scopes.arg_scope([variables.variable], device=device_fn):
        a = variables.variable('a', [])
        b = variables.variable('b', [])
        c = variables.variable('c', [], device='cpu:12')
        d = variables.variable('d', [])
        with tf.device('cpu:99'):
          e_init = tf.constant(12)
        e = variables.variable('e', initializer=e_init)
      # The values below highlight how the VariableDeviceChooser puts initial
      # values on the same device as the variable job.
      self.assertDeviceEqual(a.device, '/job:ps/task:0/cpu:0')
      self.assertDeviceEqual(a.initial_value.device, a.device)
      self.assertDeviceEqual(b.device, '/job:ps/task:1/cpu:0')
      self.assertDeviceEqual(b.initial_value.device, b.device)
      self.assertDeviceEqual(c.device, '/cpu:12')
      self.assertDeviceEqual(c.initial_value.device, c.device)
      self.assertDeviceEqual(d.device, '/job:ps/task:0/cpu:0')
      self.assertDeviceEqual(d.initial_value.device, d.device)
      self.assertDeviceEqual(e.device, '/job:ps/task:1/cpu:0')
      self.assertDeviceEqual(e.initial_value.device, '/cpu:99') 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:26,代码来源:variables_test.py

示例3: testVariableGPUPlacement

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testVariableGPUPlacement(self):

    with tf.Graph().as_default():
      device_fn = variables.VariableDeviceChooser(placement='gpu:0')
      with scopes.arg_scope([variables.variable], device=device_fn):
        a = variables.variable('a', [])
        b = variables.variable('b', [])
        c = variables.variable('c', [], device='cpu:12')
        d = variables.variable('d', [])
        with tf.device('cpu:99'):
          e_init = tf.constant(12)
        e = variables.variable('e', initializer=e_init)
      # The values below highlight how the VariableDeviceChooser puts initial
      # values on the same device as the variable job.
      self.assertDeviceEqual(a.device, '/gpu:0')
      self.assertDeviceEqual(a.initial_value.device, a.device)
      self.assertDeviceEqual(b.device, '/gpu:0')
      self.assertDeviceEqual(b.initial_value.device, b.device)
      self.assertDeviceEqual(c.device, '/cpu:12')
      self.assertDeviceEqual(c.initial_value.device, c.device)
      self.assertDeviceEqual(d.device, '/gpu:0')
      self.assertDeviceEqual(d.initial_value.device, d.device)
      self.assertDeviceEqual(e.device, '/gpu:0')
      self.assertDeviceEqual(e.initial_value.device, '/cpu:99') 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:26,代码来源:variables_test.py

示例4: testCreateVariable

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testCreateVariable(self):
    with self.test_session():
      with tf.variable_scope('A'):
        a = variables.variable('a', [5])
        self.assertEquals(a.op.name, 'A/a')
        self.assertListEqual(a.get_shape().as_list(), [5]) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:8,代码来源:variables_test.py

示例5: testGetVariables

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testGetVariables(self):
    with self.test_session():
      with tf.variable_scope('A'):
        a = variables.variable('a', [5])
      with tf.variable_scope('B'):
        b = variables.variable('a', [5])
      self.assertEquals([a, b], variables.get_variables())
      self.assertEquals([a], variables.get_variables('A'))
      self.assertEquals([b], variables.get_variables('B')) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:11,代码来源:variables_test.py

示例6: testGetVariablesSuffix

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testGetVariablesSuffix(self):
    with self.test_session():
      with tf.variable_scope('A'):
        a = variables.variable('a', [5])
      with tf.variable_scope('A'):
        b = variables.variable('b', [5])
      self.assertEquals([a], variables.get_variables(suffix='a'))
      self.assertEquals([b], variables.get_variables(suffix='b')) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:10,代码来源:variables_test.py

示例7: testGetVariableWithSingleVar

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testGetVariableWithSingleVar(self):
    with self.test_session():
      with tf.variable_scope('parent'):
        a = variables.variable('child', [5])
      self.assertEquals(a, variables.get_unique_variable('parent/child')) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:7,代码来源:variables_test.py

示例8: testGetVariableWithDistractors

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testGetVariableWithDistractors(self):
    with self.test_session():
      with tf.variable_scope('parent'):
        a = variables.variable('child', [5])
        with tf.variable_scope('child'):
          variables.variable('grandchild1', [7])
          variables.variable('grandchild2', [9])
      self.assertEquals(a, variables.get_unique_variable('parent/child')) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:10,代码来源:variables_test.py

示例9: testGetVariablesToRestore

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testGetVariablesToRestore(self):
    with self.test_session():
      with tf.variable_scope('A'):
        a = variables.variable('a', [5])
      with tf.variable_scope('B'):
        b = variables.variable('a', [5])
      self.assertEquals([a, b], variables.get_variables_to_restore()) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:9,代码来源:variables_test.py

示例10: testNoneGetVariablesToRestore

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testNoneGetVariablesToRestore(self):
    with self.test_session():
      with tf.variable_scope('A'):
        a = variables.variable('a', [5], restore=False)
      with tf.variable_scope('B'):
        b = variables.variable('a', [5], restore=False)
      self.assertEquals([], variables.get_variables_to_restore())
      self.assertEquals([a, b], variables.get_variables()) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:10,代码来源:variables_test.py

示例11: testGetMixedVariablesToRestore

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testGetMixedVariablesToRestore(self):
    with self.test_session():
      with tf.variable_scope('A'):
        a = variables.variable('a', [5])
        b = variables.variable('b', [5], restore=False)
      with tf.variable_scope('B'):
        c = variables.variable('c', [5])
        d = variables.variable('d', [5], restore=False)
      self.assertEquals([a, b, c, d], variables.get_variables())
      self.assertEquals([a, c], variables.get_variables_to_restore()) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:12,代码来源:variables_test.py

示例12: testReuseVariable

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testReuseVariable(self):
    with self.test_session():
      with tf.variable_scope('A'):
        a = variables.variable('a', [])
      with tf.variable_scope('A', reuse=True):
        b = variables.variable('a', [])
      self.assertEquals(a, b)
      self.assertListEqual([a], variables.get_variables()) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:10,代码来源:variables_test.py

示例13: testVariableWithDevice

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testVariableWithDevice(self):
    with self.test_session():
      with tf.variable_scope('A'):
        a = variables.variable('a', [], device='cpu:0')
        b = variables.variable('b', [], device='cpu:1')
      self.assertDeviceEqual(a.device, 'cpu:0')
      self.assertDeviceEqual(b.device, 'cpu:1') 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:9,代码来源:variables_test.py

示例14: testVariableWithDeviceFunction

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testVariableWithDeviceFunction(self):
    class DevFn(object):

      def __init__(self):
        self.counter = -1

      def __call__(self, op):
        self.counter += 1
        return 'cpu:%d' % self.counter

    with self.test_session():
      with scopes.arg_scope([variables.variable], device=DevFn()):
        a = variables.variable('a', [])
        b = variables.variable('b', [])
        c = variables.variable('c', [], device='cpu:12')
        d = variables.variable('d', [])
        with tf.device('cpu:99'):
          e_init = tf.constant(12)
        e = variables.variable('e', initializer=e_init)
      self.assertDeviceEqual(a.device, 'cpu:0')
      self.assertDeviceEqual(a.initial_value.device, 'cpu:0')
      self.assertDeviceEqual(b.device, 'cpu:1')
      self.assertDeviceEqual(b.initial_value.device, 'cpu:1')
      self.assertDeviceEqual(c.device, 'cpu:12')
      self.assertDeviceEqual(c.initial_value.device, 'cpu:12')
      self.assertDeviceEqual(d.device, 'cpu:2')
      self.assertDeviceEqual(d.initial_value.device, 'cpu:2')
      self.assertDeviceEqual(e.device, 'cpu:3')
      self.assertDeviceEqual(e.initial_value.device, 'cpu:99') 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:31,代码来源:variables_test.py

示例15: testVariableCollection

# 需要导入模块: from inception.slim import variables [as 别名]
# 或者: from inception.slim.variables import variable [as 别名]
def testVariableCollection(self):
    with self.test_session():
      a = variables.variable('a', [], collections='A')
      b = variables.variable('b', [], collections='B')
      self.assertEquals(a, tf.get_collection('A')[0])
      self.assertEquals(b, tf.get_collection('B')[0]) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:8,代码来源:variables_test.py


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