• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python nn_impl.zero_fraction函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python nn_ops.bias_add函数代码示例发布时间:2022-05-27
下一篇:
Python nn_impl.l2_normalize函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap