本文整理汇总了Python中tensorflow.python.ops.nn.zero_fraction函数的典型用法代码示例。如果您正苦于以下问题:Python zero_fraction函数的具体用法?Python zero_fraction怎么用?Python zero_fraction使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zero_fraction函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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.zero_fraction(x_tf)
y_tf_np = y_tf.eval()
eps = 1e-8
self.assertAllClose(y_tf_np, y_np, eps)
示例2: _compute_fraction_of_zero
def _compute_fraction_of_zero(variables):
"""Given a linear variables list, compute the fraction of zero weights.
Args:
variables: A list or list of list of variables
Returns:
The fraction of zeros (sparsity) in the linear model.
"""
all_weight_vars = []
for var_or_var_list in variables:
var_list = nest.flatten(var_or_var_list)
# Skip empty-lists associated with columns that created no Variables.
if var_list:
all_weight_vars += [array_ops.reshape(var, [-1]) for var in var_list]
return nn.zero_fraction(array_ops.concat(all_weight_vars, axis=0))
示例3: _compute_fraction_of_zero
def _compute_fraction_of_zero(cols_to_vars):
"""Given a linear cols_to_vars dict, compute the fraction of zero weights.
Args:
cols_to_vars: A dictionary mapping FeatureColumns to lists of tf.Variables
like one returned from feature_column_lib.linear_model.
Returns:
The fraction of zeros (sparsity) in the linear model.
"""
all_weight_vars = []
for var_or_var_list in cols_to_vars.values():
# Skip empty-lists associated with columns that created no Variables.
if var_or_var_list:
all_weight_vars += [
array_ops.reshape(var, [-1]) for var in var_or_var_list
]
return nn.zero_fraction(array_ops.concat(all_weight_vars, axis=0))
示例4: _add_layer_summary
def _add_layer_summary(value, tag):
summary.scalar("%s/fraction_of_zero_values" % tag, nn.zero_fraction(value))
summary.histogram("%s/activation" % tag, value)
示例5: _add_hidden_layer_summary
def _add_hidden_layer_summary(self, value, tag):
# TODO(zakaria): Move this code to tf.learn and add test.
logging_ops.scalar_summary("%s:fraction_of_zero_values" % tag, nn.zero_fraction(value))
logging_ops.histogram_summary("%s:activation" % tag, value)
示例6: _add_hidden_layer_summary
def _add_hidden_layer_summary(value, tag):
summary.scalar('%s/fraction_of_zero_values' % tag, nn.zero_fraction(value))
summary.histogram('%s/activation' % tag, value)
示例7: _add_hidden_layer_summary
def _add_hidden_layer_summary(value, tag):
logging_ops.scalar_summary("%s/fraction_of_zero_values" % tag,
nn.zero_fraction(value))
logging_ops.histogram_summary("%s/activation" % tag, value)
示例8: _add_hidden_layer_summary
def _add_hidden_layer_summary(self, value, tag):
# TODO(zakaria): Move this code to tf.learn and add test.
summary.scalar("%s/fraction_of_zero_values" % tag, nn.zero_fraction(value))
summary.histogram("%s/activation" % tag, value)
示例9: testZeroFractionEmpty
def testZeroFractionEmpty(self):
with self.test_session():
x = np.zeros(0)
y = nn.zero_fraction(x).eval()
self.assertTrue(np.isnan(y))