Python tensorflow.sparse_retain() Examples
The following are 21
code examples of tensorflow.sparse_retain().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tensorflow
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: util.py From pregel with MIT License | 6 votes |
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
Example #2
Source File: conf_gcn.py From ConfGCN with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: layers.py From GPF with MIT License | 5 votes |
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)
Example #4
Source File: layers.py From lgcn with GNU General Public License v3.0 | 5 votes |
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
Example #5
Source File: layers.py From BioNEV with MIT License | 5 votes |
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)
Example #6
Source File: meta_gradient_attack.py From gnn-meta-attack with MIT License | 5 votes |
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)
Example #7
Source File: layers.py From Pixel2Mesh with Apache License 2.0 | 5 votes |
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)
Example #8
Source File: layers.py From H-GCN with MIT License | 5 votes |
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)
Example #9
Source File: layers.py From arxiv-public-datasets with MIT License | 5 votes |
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)
Example #10
Source File: layers.py From gcnn-survey-paper with Apache License 2.0 | 5 votes |
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)
Example #11
Source File: layers.py From NPHard with MIT License | 5 votes |
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)
Example #12
Source File: GCN.py From nettack with MIT License | 5 votes |
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)
Example #13
Source File: gcn.py From neural-structured-learning with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: NGCF.py From neural_graph_collaborative_filtering with MIT License | 5 votes |
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)
Example #15
Source File: layers.py From DGFraud with Apache License 2.0 | 5 votes |
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)
Example #16
Source File: util.py From gnn-benchmark with MIT License | 5 votes |
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)
Example #17
Source File: graph_convolutional_matrix_completion.py From redshells with MIT License | 5 votes |
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
Example #18
Source File: layers.py From zero-shot-gcn with MIT License | 5 votes |
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)
Example #19
Source File: layers.py From dgi with MIT License | 5 votes |
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)
Example #20
Source File: layers.py From Pixel2MeshPlusPlus with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #21
Source File: layers.py From OpenNE with MIT License | 5 votes |
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)