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


Python scopes.arg_scope方法代码示例

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


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

示例1: testVariableWithVariableDeviceChooser

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [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

示例2: testVariableGPUPlacement

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [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

示例3: testDeviceFn

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

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

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

    with tf.Graph().as_default():
      with scopes.arg_scope([variables.global_step], device=DevFn()):
        gs = variables.global_step()
        gs2 = variables.global_step()
      self.assertDeviceEqual(gs.device, '/cpu:0')
      self.assertEquals(gs, gs2)
      self.assertDeviceEqual(gs2.device, '/cpu:0') 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:19,代码来源:variables_test.py

示例4: inception_v3_parameters

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def inception_v3_parameters(weight_decay=0.00004, stddev=0.1,
                            batch_norm_decay=0.9997, batch_norm_epsilon=0.001):
  """Yields the scope with the default parameters for inception_v3.

  Args:
    weight_decay: the weight decay for weights variables.
    stddev: standard deviation of the truncated guassian weight distribution.
    batch_norm_decay: decay for the moving average of batch_norm momentums.
    batch_norm_epsilon: small float added to variance to avoid dividing by zero.

  Yields:
    a arg_scope with the parameters needed for inception_v3.
  """
  # Set weight_decay for weights in Conv and FC layers.
  with scopes.arg_scope([ops.conv2d, ops.fc],
                        weight_decay=weight_decay):
    # Set stddev, activation and parameters for batch_norm.
    with scopes.arg_scope([ops.conv2d],
                          stddev=stddev,
                          activation=tf.nn.relu,
                          batch_norm_params={
                              'decay': batch_norm_decay,
                              'epsilon': batch_norm_epsilon}) as arg_scope:
      yield arg_scope 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:26,代码来源:inception_model.py

示例5: testCurrentArgScope

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testCurrentArgScope(self):
    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
    key_op = (func1.__module__, func1.__name__)
    current_scope = {key_op: func1_kwargs.copy()}
    with self.test_session():
      with scopes.arg_scope([func1], a=1, b=None, c=[1]) as scope:
        self.assertDictEqual(scope, current_scope) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:9,代码来源:scopes_test.py

示例6: testCurrentArgScopeNested

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testCurrentArgScopeNested(self):
    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
    func2_kwargs = {'b': 2, 'd': [2]}
    key = lambda f: (f.__module__, f.__name__)
    current_scope = {key(func1): func1_kwargs.copy(),
                     key(func2): func2_kwargs.copy()}
    with self.test_session():
      with scopes.arg_scope([func1], a=1, b=None, c=[1]):
        with scopes.arg_scope([func2], b=2, d=[2]) as scope:
          self.assertDictEqual(scope, current_scope) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:12,代码来源:scopes_test.py

示例7: testReuseArgScope

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testReuseArgScope(self):
    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
    key_op = (func1.__module__, func1.__name__)
    current_scope = {key_op: func1_kwargs.copy()}
    with self.test_session():
      with scopes.arg_scope([func1], a=1, b=None, c=[1]) as scope1:
        pass
      with scopes.arg_scope(scope1) as scope:
        self.assertDictEqual(scope, current_scope) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:11,代码来源:scopes_test.py

示例8: testReuseArgScopeNested

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testReuseArgScopeNested(self):
    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
    func2_kwargs = {'b': 2, 'd': [2]}
    key = lambda f: (f.__module__, f.__name__)
    current_scope1 = {key(func1): func1_kwargs.copy()}
    current_scope2 = {key(func1): func1_kwargs.copy(),
                      key(func2): func2_kwargs.copy()}
    with self.test_session():
      with scopes.arg_scope([func1], a=1, b=None, c=[1]) as scope1:
        with scopes.arg_scope([func2], b=2, d=[2]) as scope2:
          pass
      with scopes.arg_scope(scope1):
        self.assertDictEqual(scopes._current_arg_scope(), current_scope1)
      with scopes.arg_scope(scope2):
        self.assertDictEqual(scopes._current_arg_scope(), current_scope2) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:17,代码来源:scopes_test.py

示例9: testSimpleArgScope

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testSimpleArgScope(self):
    func1_args = (0,)
    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
    with self.test_session():
      with scopes.arg_scope([func1], a=1, b=None, c=[1]):
        args, kwargs = func1(0)
        self.assertTupleEqual(args, func1_args)
        self.assertDictEqual(kwargs, func1_kwargs) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:10,代码来源:scopes_test.py

示例10: testOverwriteArgScope

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testOverwriteArgScope(self):
    func1_args = (0,)
    func1_kwargs = {'a': 1, 'b': 2, 'c': [1]}
    with scopes.arg_scope([func1], a=1, b=None, c=[1]):
      args, kwargs = func1(0, b=2)
      self.assertTupleEqual(args, func1_args)
      self.assertDictEqual(kwargs, func1_kwargs) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:9,代码来源:scopes_test.py

示例11: testNestedArgScope

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testNestedArgScope(self):
    func1_args = (0,)
    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
    with scopes.arg_scope([func1], a=1, b=None, c=[1]):
      args, kwargs = func1(0)
      self.assertTupleEqual(args, func1_args)
      self.assertDictEqual(kwargs, func1_kwargs)
      func1_kwargs['b'] = 2
      with scopes.arg_scope([func1], b=2):
        args, kwargs = func1(0)
        self.assertTupleEqual(args, func1_args)
        self.assertDictEqual(kwargs, func1_kwargs) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:14,代码来源:scopes_test.py

示例12: testSharedArgScope

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testSharedArgScope(self):
    func1_args = (0,)
    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
    with scopes.arg_scope([func1, func2], a=1, b=None, c=[1]):
      args, kwargs = func1(0)
      self.assertTupleEqual(args, func1_args)
      self.assertDictEqual(kwargs, func1_kwargs)
      args, kwargs = func2(0)
      self.assertTupleEqual(args, func1_args)
      self.assertDictEqual(kwargs, func1_kwargs) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:12,代码来源:scopes_test.py

示例13: testSharedArgScopeTuple

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testSharedArgScopeTuple(self):
    func1_args = (0,)
    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
    with scopes.arg_scope((func1, func2), a=1, b=None, c=[1]):
      args, kwargs = func1(0)
      self.assertTupleEqual(args, func1_args)
      self.assertDictEqual(kwargs, func1_kwargs)
      args, kwargs = func2(0)
      self.assertTupleEqual(args, func1_args)
      self.assertDictEqual(kwargs, func1_kwargs) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:12,代码来源:scopes_test.py

示例14: testPartiallySharedArgScope

# 需要导入模块: from inception.slim import scopes [as 别名]
# 或者: from inception.slim.scopes import arg_scope [as 别名]
def testPartiallySharedArgScope(self):
    func1_args = (0,)
    func1_kwargs = {'a': 1, 'b': None, 'c': [1]}
    func2_args = (1,)
    func2_kwargs = {'a': 1, 'b': None, 'd': [2]}
    with scopes.arg_scope([func1, func2], a=1, b=None):
      with scopes.arg_scope([func1], c=[1]), scopes.arg_scope([func2], d=[2]):
        args, kwargs = func1(0)
        self.assertTupleEqual(args, func1_args)
        self.assertDictEqual(kwargs, func1_kwargs)
        args, kwargs = func2(1)
        self.assertTupleEqual(args, func2_args)
        self.assertDictEqual(kwargs, func2_kwargs) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:15,代码来源:scopes_test.py

示例15: testVariableCollectionsWithArgScope

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


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