/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
caffe2
/
python
/
layers
/
/usr/local/lib64/python3.6/site-packages/caffe2/python/layers
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
adaptive_weight.py
5687
0644
edit
dl
rm
add_bias.py
1396
0644
edit
dl
rm
arc_cosine_feature_map.py
7345
0644
edit
dl
rm
batch_huber_loss.py
3523
0644
edit
dl
rm
batch_lr_loss.py
11577
0644
edit
dl
rm
batch_mse_loss.py
2333
0644
edit
dl
rm
batch_normalization.py
3823
0644
edit
dl
rm
batch_sigmoid_cross_entropy_loss.py
1483
0644
edit
dl
rm
batch_softmax_loss.py
4580
0644
edit
dl
rm
blob_weighted_sum.py
2219
0644
edit
dl
rm
bpr_loss.py
1499
0644
edit
dl
rm
bucket_weighted.py
2355
0644
edit
dl
rm
build_index.py
1937
0644
edit
dl
rm
concat.py
4849
0644
edit
dl
rm
constant_weight.py
1208
0644
edit
dl
rm
conv.py
5050
0644
edit
dl
rm
dropout.py
1410
0644
edit
dl
rm
fc.py
9296
0644
edit
dl
rm
fc_without_bias.py
1954
0644
edit
dl
rm
fc_with_bootstrap.py
12788
0644
edit
dl
rm
feature_sparse_to_dense.py
14361
0644
edit
dl
rm
functional.py
4875
0644
edit
dl
rm
gather_record.py
3260
0644
edit
dl
rm
homotopy_weight.py
4306
0644
edit
dl
rm
label_smooth.py
3507
0644
edit
dl
rm
last_n_window_collector.py
2392
0644
edit
dl
rm
layers.py
17412
0644
edit
dl
rm
layer_normalization.py
4291
0644
edit
dl
rm
margin_rank_loss.py
1951
0644
edit
dl
rm
merge_id_lists.py
1500
0644
edit
dl
rm
pairwise_similarity.py
3549
0644
edit
dl
rm
position_weighted.py
2066
0644
edit
dl
rm
random_fourier_features.py
3187
0644
edit
dl
rm
reservoir_sampling.py
3013
0644
edit
dl
rm
sampling_train.py
2210
0644
edit
dl
rm
sampling_trainable_mixin.py
1366
0644
edit
dl
rm
select_record_by_context.py
2381
0644
edit
dl
rm
semi_random_features.py
5809
0644
edit
dl
rm
sparse_dropout_with_replacement.py
3943
0644
edit
dl
rm
sparse_feature_hash.py
4618
0644
edit
dl
rm
sparse_itemwise_dropout_with_replacement.py
3944
0644
edit
dl
rm
sparse_lookup.py
22170
0644
edit
dl
rm
split.py
2257
0644
edit
dl
rm
tags.py
4114
0644
edit
dl
rm
uniform_sampling.py
2779
0644
edit
dl
rm
__init__.py
943
0644
edit
dl
rm
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)
Save
cmd:
run