MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / apply_mask

Function apply_mask

tensorflow/contrib/model_pruning/python/pruning.py:90–114  ·  view source on GitHub ↗

Apply mask to a given weight tensor. Args: x: Input weight tensor scope: The current variable scope. Defaults to "". Returns: Tensor representing masked_weights

(x, scope='')

Source from the content-addressed store, hash-verified

88
89
90def apply_mask(x, scope=''):
91 """Apply mask to a given weight tensor.
92
93 Args:
94 x: Input weight tensor
95 scope: The current variable scope. Defaults to "".
96 Returns:
97 Tensor representing masked_weights
98 """
99
100 mask = pruning_utils.weight_mask_variable(x, scope)
101 threshold = pruning_utils.weight_threshold_variable(x, scope)
102 # Add masked_weights in the weights namescope so as to make it easier
103 # for the quantization library to add quant ops.
104 masked_weights = math_ops.multiply(mask, x, _MASKED_WEIGHT_NAME)
105
106 # Make sure the mask for a given variable are not added multiple times to the
107 # collection. This is particularly important when applying mask to RNN's
108 # weight variables
109 if mask not in ops.get_collection_ref(_MASK_COLLECTION):
110 ops.add_to_collection(_THRESHOLD_COLLECTION, threshold)
111 ops.add_to_collection(_MASK_COLLECTION, mask)
112 ops.add_to_collection(_MASKED_WEIGHT_COLLECTION, masked_weights)
113 ops.add_to_collection(_WEIGHT_COLLECTION, x)
114 return masked_weights
115
116
117def get_masked_weights():

Callers

nothing calls this directly

Calls 3

multiplyMethod · 0.80
get_collection_refMethod · 0.80
add_to_collectionMethod · 0.80

Tested by

no test coverage detected