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


Python tensorflow.sparse_retain方法代码示例

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


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

示例1: sparse_dropout

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def sparse_dropout(self, x, keep_prob, noise_shape):
		"""
		Dropout for sparse tensors.

		Parameters
		----------
		x:		Input data
		keep_prob:	Keep probability
		noise_shape:	Size of each entry of x

		Returns
		-------
		pre_out:	x after dropout

		"""
		random_tensor  = keep_prob
		random_tensor += tf.random_uniform(noise_shape)
		dropout_mask   = tf.cast(tf.floor(random_tensor), dtype=tf.bool)
		pre_out        = tf.sparse_retain(x, dropout_mask)
		return pre_out * (1./keep_prob) 
开发者ID:malllabiisc,项目名称:ConfGCN,代码行数:22,代码来源:conf_gcn.py

示例2: sparse_dropout

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def sparse_dropout(x, keep_prob, noise_shape=None, seed=None, name=None):
    '''borrowed logic and implementation from https://github.com/tensorflow/tensorflow/blob/r1.4/tensorflow/python/ops/nn_ops.py'''

    # Skipping all the assertions

    if (keep_prob == 1):
        return x

    # uniform [keep_prob, 1.0 + keep_prob)
    random_tensor = keep_prob
    random_tensor += tf.random_uniform(noise_shape,
                                       seed=seed,
                                       dtype=x.dtype)

    # 0. if [keep_prob, 1.0) and 1. if [1.0, 1.0 + keep_prob)
    binary_tensor = tf.floor(random_tensor)
    # Typecase necessary as mentioned on https://www.tensorflow.org/api_docs/python/tf/sparse_retain
    binary_tensor = tf.cast(binary_tensor, dtype=tf.bool)
    ret = tf.sparse_retain(x, binary_tensor)
    ret = ret * (1 / keep_prob)
    return ret 
开发者ID:shagunsodhani,项目名称:pregel,代码行数:23,代码来源:util.py

示例3: sparse_dropout

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def sparse_dropout(x, keep_prob, noise_shape):
    """Dropout for sparse tensors."""
    random_tensor = keep_prob
    random_tensor += tf.random_uniform(noise_shape)
    dropout_mask = tf.cast(tf.floor(random_tensor), dtype=tf.bool)
    pre_out = tf.sparse_retain(x, dropout_mask)
    return pre_out * (1./keep_prob) 
开发者ID:danielzuegner,项目名称:nettack,代码行数:9,代码来源:GCN.py

示例4: sparse_dropout

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def sparse_dropout(x, keep_prob, noise_shape):
    """Dropout for sparse tensors."""
    random_tensor = keep_prob
    random_tensor += tf.random_uniform(noise_shape)
    dropout_mask = tf.cast(tf.floor(random_tensor), dtype=tf.bool)
    pre_out = tf.sparse_retain(x, dropout_mask)
    return pre_out * (1. / keep_prob) 
开发者ID:walsvid,项目名称:Pixel2MeshPlusPlus,代码行数:9,代码来源:layers.py

示例5: _dropout_sparse

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def _dropout_sparse(x, keep_prob, num_nonzero_elements):
        random_tensor = keep_prob + tf.random_uniform([num_nonzero_elements])
        dropout_mask = tf.cast(tf.floor(random_tensor), dtype=tf.bool)
        return tf.sparse_retain(x, dropout_mask) / keep_prob 
开发者ID:m3dev,项目名称:redshells,代码行数:6,代码来源:graph_convolutional_matrix_completion.py

示例6: dropout_supporting_sparse_tensors

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def dropout_supporting_sparse_tensors(X, keep_prob):
    """Add dropout layer on top of X.

    Parameters
    ----------
    X : tf.Tensor or tf.SparseTensor
        Tensor over which dropout is applied.
    keep_prob : float, tf.placeholder
        Probability of keeping a value (= 1 - probability of dropout).

    Returns
    -------
    X : tf.Tensor or tf.SparseTensor
        Tensor with elementwise dropout applied.

    Author: Oleksandr Shchur & Johannes Klicpera
    """
    if isinstance(X, tf.SparseTensor):
        # nnz = X.values.shape  # number of nonzero entries
        # random_tensor = keep_prob
        # random_tensor += tf.random_uniform(nnz)
        # dropout_mask = tf.cast(tf.floor(random_tensor), dtype=tf.bool)
        # pre_out = tf.sparse_retain(X, dropout_mask)
        # return pre_out * (1.0 / keep_prob)
        values_after_dropout = tf.nn.dropout(X.values, keep_prob)
        return tf.SparseTensor(X.indices, values_after_dropout, X.dense_shape)
    else:
        return tf.nn.dropout(X, keep_prob) 
开发者ID:shchur,项目名称:gnn-benchmark,代码行数:30,代码来源:util.py

示例7: _dropout_sparse

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def _dropout_sparse(self, X, keep_prob, n_nonzero_elems):
        """
        Dropout for sparse tensors.
        """
        noise_shape = [n_nonzero_elems]
        random_tensor = keep_prob
        random_tensor += tf.random_uniform(noise_shape)
        dropout_mask = tf.cast(tf.floor(random_tensor), dtype=tf.bool)
        pre_out = tf.sparse_retain(X, dropout_mask)

        return pre_out * tf.div(1., keep_prob) 
开发者ID:xiangwang1223,项目名称:neural_graph_collaborative_filtering,代码行数:13,代码来源:NGCF.py

示例8: sparse_dropout

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def sparse_dropout(x, keep_prob, noise_shape):
  """Dropout for sparse tensors."""
  random_tensor = keep_prob
  random_tensor += tf.random_uniform(noise_shape)
  dropout_mask = tf.cast(tf.floor(random_tensor), dtype=tf.bool)
  pre_out = tf.sparse_retain(x, dropout_mask)
  return tf.SparseTensor(
      indices=pre_out.indices,
      values=pre_out.values / keep_prob,
      dense_shape=pre_out.dense_shape) 
开发者ID:tensorflow,项目名称:neural-structured-learning,代码行数:12,代码来源:gcn.py

示例9: dropout_sparse

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def dropout_sparse(x, keep_prob, num_nonzero_elems):
    """Dropout for sparse tensors. Currently fails for very large sparse tensors (>1M elements)
    """
    noise_shape = [num_nonzero_elems]
    random_tensor = keep_prob
    random_tensor += tf.random_uniform(noise_shape)
    dropout_mask = tf.cast(tf.floor(random_tensor), dtype=tf.bool)
    pre_out = tf.sparse_retain(x, dropout_mask)
    return pre_out * (1. / keep_prob) 
开发者ID:xiangyue9607,项目名称:BioNEV,代码行数:11,代码来源:layers.py

示例10: sparse_dropout

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import sparse_retain [as 别名]
def sparse_dropout(x, keep_prob, noise_shape, is_training):
    """Dropout for sparse tensors."""
    if is_training == True:
        random_tensor = keep_prob
        random_tensor += tf.random_uniform(noise_shape)
        dropout_mask = tf.cast(tf.floor(random_tensor), dtype=tf.bool)
        pre_out = tf.sparse_retain(x, dropout_mask)
        x = pre_out * (1./keep_prob)
    return x 
开发者ID:divelab,项目名称:lgcn,代码行数:11,代码来源:layers.py


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