當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。