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


Python nn_impl.zero_fraction函数代码示例

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


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

示例1: testUnknownSize

 def testUnknownSize(self):
   value = array_ops.placeholder(dtype=dtypes.float32)
   sparsity = nn_impl.zero_fraction(value)
   with self.cached_session() as sess:
     self.assertAllClose(
         0.25,
         sess.run(sparsity, {value: [[0., 1.], [0.3, 2.]]}))
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:7,代码来源:nn_test.py

示例2: add_pruning_summaries

 def add_pruning_summaries(self):
   """Adds summaries of weight sparsities and thresholds."""
   with ops.name_scope(self._spec.name + '_summaries'):
     summary.scalar('sparsity', self._sparsity)
     summary.scalar('last_mask_update_step', self._last_update_step)
     masks = get_masks()
     thresholds = get_thresholds()
     for mask, threshold in zip(masks, thresholds):
       summary.scalar(mask.op.name + '/sparsity', nn_impl.zero_fraction(mask))
       summary.scalar(threshold.op.name + '/threshold', threshold)
开发者ID:Albert-Z-Guo,项目名称:tensorflow,代码行数:10,代码来源:pruning.py

示例3: testZeroFraction

 def testZeroFraction(self):
   x_shape = [5, 17]
   x_np = np.random.randint(0, 2, size=x_shape).astype(np.float32)
   y_np = self._ZeroFraction(x_np)
   with self.test_session():
     x_tf = constant_op.constant(x_np)
     x_tf.set_shape(x_shape)
     y_tf = nn_impl.zero_fraction(x_tf)
     y_tf_np = y_tf.eval()
   eps = 1e-8
   self.assertAllClose(y_tf_np, y_np, eps)
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:11,代码来源:nn_test.py

示例4: get_weight_sparsity

def get_weight_sparsity():
  """Get sparsity of the weights.

  Args:
    None

  Returns:
    A list containing the sparsity of each of the weight tensors
  """
  masks = get_masks()
  return [nn_impl.zero_fraction(mask) for mask in masks]
开发者ID:SylChan,项目名称:tensorflow,代码行数:11,代码来源:pruning.py

示例5: add_pruning_summaries

  def add_pruning_summaries(self):
    """Adds summaries for this pruning spec.

    Args: none

    Returns: none
    """
    with ops.name_scope(self._spec.name + '_summaries'):
      summary.scalar('sparsity', self._sparsity)
      summary.scalar('last_mask_update_step', self._last_update_step)
      masks = get_masks()
      thresholds = get_thresholds()
      for index, mask in enumerate(masks):
        if not self._exists_in_do_not_prune_list(mask.name):
          summary.scalar(mask.name + '/sparsity', nn_impl.zero_fraction(mask))
          summary.scalar(thresholds[index].op.name + '/threshold',
                         thresholds[index])
开发者ID:SylChan,项目名称:tensorflow,代码行数:17,代码来源:pruning.py

示例6: add_zero_fraction_summary

def add_zero_fraction_summary(tensor, name=None, prefix=None,
                              print_summary=False):
  """Adds a summary for the percentage of zero values in the given tensor.

  Args:
    tensor: a variable or op tensor.
    name: the optional name for the summary.
    prefix: An optional prefix for the summary names.
    print_summary: If `True`, the summary is printed to stdout when the summary
      is computed.

  Returns:
    A scalar `Tensor` of type `string` whose contents are the serialized
    `Summary` protocol buffer.
  """
  name = _get_summary_name(tensor, name, prefix, 'Fraction of Zero Values')
  tensor = nn.zero_fraction(tensor)
  return add_scalar_summary(tensor, name, print_summary=print_summary)
开发者ID:1000sprites,项目名称:tensorflow,代码行数:18,代码来源:summaries.py

示例7: testZeroFractionEmpty

 def testZeroFractionEmpty(self):
   with self.test_session():
     x = np.zeros(0)
     y = nn_impl.zero_fraction(x).eval()
     self.assertTrue(np.isnan(y))
开发者ID:AlbertXiebnu,项目名称:tensorflow,代码行数:5,代码来源:nn_test.py

示例8: testZeroFraction2_27Ones

 def testZeroFraction2_27Ones(self):
   sparsity = nn_impl.zero_fraction(
       array_ops.ones([int(2**27 * 1.01)], dtype=dtypes.int8))
   self.assertAllClose(0.0, self.evaluate(sparsity))
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:4,代码来源:nn_test.py

示例9: testZeroFractionEmpty

 def testZeroFractionEmpty(self):
   x = np.zeros(0)
   y = self.evaluate(nn_impl.zero_fraction(x))
   self.assertTrue(np.isnan(y))
开发者ID:Wajih-O,项目名称:tensorflow,代码行数:4,代码来源:nn_test.py

示例10: testZeroFraction2_27Ones

 def testZeroFraction2_27Ones(self):
   sparsity = nn_impl.zero_fraction(
       array_ops.ones([int(2**27 * 1.01)], dtype=dtypes.int8))
   with self.cached_session():
     self.assertAllClose(0.0, sparsity.eval())
开发者ID:abhinav-upadhyay,项目名称:tensorflow,代码行数:5,代码来源:nn_test.py


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