/usr/local/lib64/python3.6/site-packages/caffe2/python/layers
NameSizeModeActions
__pycache__/-0755rm
adaptive_weight.py56870644editdlrm
add_bias.py13960644editdlrm
arc_cosine_feature_map.py73450644editdlrm
batch_huber_loss.py35230644editdlrm
batch_lr_loss.py115770644editdlrm
batch_mse_loss.py23330644editdlrm
batch_normalization.py38230644editdlrm
batch_sigmoid_cross_entropy_loss.py14830644editdlrm
batch_softmax_loss.py45800644editdlrm
blob_weighted_sum.py22190644editdlrm
bpr_loss.py14990644editdlrm
bucket_weighted.py23550644editdlrm
build_index.py19370644editdlrm
concat.py48490644editdlrm
constant_weight.py12080644editdlrm
conv.py50500644editdlrm
dropout.py14100644editdlrm
fc.py92960644editdlrm
fc_without_bias.py19540644editdlrm
fc_with_bootstrap.py127880644editdlrm
feature_sparse_to_dense.py143610644editdlrm
functional.py48750644editdlrm
gather_record.py32600644editdlrm
homotopy_weight.py43060644editdlrm
label_smooth.py35070644editdlrm
last_n_window_collector.py23920644editdlrm
layers.py174120644editdlrm
layer_normalization.py42910644editdlrm
margin_rank_loss.py19510644editdlrm
merge_id_lists.py15000644editdlrm
pairwise_similarity.py35490644editdlrm
position_weighted.py20660644editdlrm
random_fourier_features.py31870644editdlrm
reservoir_sampling.py30130644editdlrm
sampling_train.py22100644editdlrm
sampling_trainable_mixin.py13660644editdlrm
select_record_by_context.py23810644editdlrm
semi_random_features.py58090644editdlrm
sparse_dropout_with_replacement.py39430644editdlrm
sparse_feature_hash.py46180644editdlrm
sparse_itemwise_dropout_with_replacement.py39440644editdlrm
sparse_lookup.py221700644editdlrm
split.py22570644editdlrm
tags.py41140644editdlrm
uniform_sampling.py27790644editdlrm
__init__.py9430644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/caffe2/python/layers/sparse_dropout_with_replacement.py (3943B)
from caffe2.python import schema from caffe2.python.layers.layers import ( IdList, ModelLayer, ) # Model layer for implementing probabilistic replacement of elements in # IdLists. Takes probabilities for train, eval and predict nets as input, as # well as the replacement value when dropout happens. For features we may have # available to us in train net but not in predict net, we'd set dropout # probability for predict net to be 1.0 and set the feature to the replacement # value given here. This way, the value is tied to the particular model and not # to any specific logic in feature processing in serving. # Consider the following example where X is the values in the IdList and Lengths # is the number of values corresponding to each example. # X: [1, 2, 3, 4, 5] # Lengths: [2, 3] # This IdList contains 2 items of lengths 2, 3. Let's assume we used a ratio of # 0.5 and ended up dropping out 2nd example, and used a replacement value of -1. # We will end up with the following IdList. # # Y: [1, 2, -1] # OutputLengths: [2, 1] # where the 2nd item values [3,4,5] were replaced with [-1] and the length got # set to 1. class SparseDropoutWithReplacement(ModelLayer): def __init__( self, model, input_record, dropout_prob_train, dropout_prob_eval, dropout_prob_predict, replacement_value, name='sparse_dropout', **kwargs): super(SparseDropoutWithReplacement, self).__init__(model, name, input_record, **kwargs) assert schema.equal_schemas(input_record, IdList), "Incorrect input type" self.dropout_prob_train = float(dropout_prob_train) self.dropout_prob_eval = float(dropout_prob_eval) self.dropout_prob_predict = float(dropout_prob_predict) self.replacement_value = int(replacement_value) assert (self.dropout_prob_train >= 0 and self.dropout_prob_train <= 1.0), \ "Expected 0 <= dropout_prob_train <= 1, but got %s" \ % self.dropout_prob_train assert (self.dropout_prob_eval >= 0 and self.dropout_prob_eval <= 1.0), \ "Expected 0 <= dropout_prob_eval <= 1, but got %s" \ % dropout_prob_eval assert (self.dropout_prob_predict >= 0 and self.dropout_prob_predict <= 1.0), \ "Expected 0 <= dropout_prob_predict <= 1, but got %s" \ % dropout_prob_predict assert(self.dropout_prob_train > 0 or self.dropout_prob_eval > 0 or self.dropout_prob_predict > 0), \ "Ratios all set to 0.0 for train, eval and predict" self.output_schema = schema.NewRecord(model.net, IdList) if input_record.lengths.metadata: self.output_schema.lengths.set_metadata( input_record.lengths.metadata) if input_record.items.metadata: self.output_schema.items.set_metadata( input_record.items.metadata) def _add_ops(self, net, ratio): input_values_blob = self.input_record.items() input_lengths_blob = self.input_record.lengths() output_lengths_blob = self.output_schema.lengths() output_values_blob = self.output_schema.items() net.SparseDropoutWithReplacement([input_values_blob, input_lengths_blob], [output_values_blob, output_lengths_blob], ratio=ratio, replacement_value=self.replacement_value) def add_train_ops(self, net): self._add_ops(net, self.dropout_prob_train) def add_eval_ops(self, net): self._add_ops(net, self.dropout_prob_eval) def add_ops(self, net): self._add_ops(net, self.dropout_prob_predict)