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='')
| 88 | |
| 89 | |
| 90 | def 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 | |
| 117 | def get_masked_weights(): |
nothing calls this directly
no test coverage detected