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


Python check.Ne方法代码示例

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


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

示例1: testCheckNe

# 需要导入模块: from syntaxnet.util import check [as 别名]
# 或者: from syntaxnet.util.check import Ne [as 别名]
def testCheckNe(self):
    check.Ne(1, 2, 'foo')
    with self.assertRaisesRegexp(ValueError, 'bar'):
      check.Ne(1, 1, 'bar')
    with self.assertRaisesRegexp(RuntimeError, 'baz'):
      check.Ne(1, 1, 'baz', RuntimeError) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:8,代码来源:check_test.py

示例2: _add_hooks_for_trainable_params

# 需要导入模块: from syntaxnet.util import check [as 别名]
# 或者: from syntaxnet.util.check import Ne [as 别名]
def _add_hooks_for_trainable_params(component, params):
  """Adds runtime hooks for a variable of trainable parameters.

  Ignores parameters that are not statically-deducible as matrices.

  Args:
    component: Component for which to add hooks.
    params: Variable for which to add hooks.
  """
  full_name = params.op.name
  matrix = component.get_variable(var_params=params)

  # Only add hooks for tensors that are statically-deducible as matrices.
  if params.shape.ndims != 2:
    tf.logging.info('Not adding hooks for trainable params %s', full_name)
    return

  # Infer the suffix to append to variable names, if any, based on whether the
  # possibly-averaged |matrix| is named differently than the |params|.
  suffix = re.sub('^' + re.escape(full_name), '', matrix.op.name)
  check.Ne(suffix, matrix.op.name,
           'Failed to find suffix for params %s' % full_name)

  def _hook_name(base_name):
    """Returns a hook node name constructed from a base name."""
    return full_name + base_name + suffix

  # Add the matrix and its transpose.
  transposed = tf.transpose(matrix)
  _add_hook_node(matrix, _hook_name('/matrix'))
  _add_hook_node(transposed, _hook_name('/transposed'))

  # Add blocked versions of the matrix and its transpose.
  for blocked, blocked_suffix in _blocked_and_dtype_transformations(matrix):
    _add_hook_node(blocked, _hook_name('/matrix' + blocked_suffix))
  for blocked, blocked_suffix in _blocked_and_dtype_transformations(transposed):
    _add_hook_node(blocked, _hook_name('/transposed' + blocked_suffix))

  # Also add hooks for the original shapes, which are obscured by padding.
  _add_hook_node(tf.shape(matrix), _hook_name('/matrix/shape'))
  _add_hook_node(tf.shape(transposed), _hook_name('/transposed/shape')) 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:43,代码来源:runtime_support.py

示例3: _get_hook_name

# 需要导入模块: from syntaxnet.util import check [as 别名]
# 或者: from syntaxnet.util.check import Ne [as 别名]
def _get_hook_name(component, variable_name, suffix):
  """Builds the name of a hook node.

  Specifically, the name of the hook node is:

    <component.name>/<variable_name><suffix><remainder>

  where <remainder> is whatever follows <variable_name> in the name of the op
  that produces the named variable.  Recall that component.get_variable() may
  return either the original variable or its moving average.  These might have
  names like:

    foo_component/bar_variable
    foo_component/bar_variable/ExponentialMovingAverage

  In the examples above, the <remainder> is "" for the original variable and
  "/ExponentialMovingAverage" for its moving average.  Calling this function
  with suffix="/baz_suffix" in either case would add hook nodes named:

    foo_component/bar_variable/baz_suffix
    foo_component/bar_variable/baz_suffix/ExponentialMovingAverage

  Note that the suffix is inserted after the variable name, not necessarily at
  the end of the entire op name.

  Args:
    component: Component that the hook node belongs to.
    variable_name: Variable that the hook node name is based on.
    suffix: Suffix to append to the variable name.

  Returns:
    Name of the hook node.
  """
  variable = component.get_variable(variable_name)
  full_name = variable.op.name
  prefix = component.name + '/' + variable_name
  hook_name = re.sub('^' + re.escape(prefix), prefix + suffix, full_name)

  # If re.sub() did not match anything, it returns the unmodified input (i.e.,
  # |full_name|).  Enforce that some change was made.
  check.Ne(
      full_name, hook_name,
      'Failed to match expected variable prefix "{}" in variable "{}"'.format(
          prefix, full_name))

  return hook_name 
开发者ID:generalized-iou,项目名称:g-tensorflow-models,代码行数:48,代码来源:runtime_support.py


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