Created
June 21, 2020 15:53
-
-
Save sayakpaul/f1a07c1850ee9c1d1a29c6e0a249c88b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for layer in model.layers: | |
if isinstance(layer, pruning_wrapper.PruneLowMagnitude): | |
for weight in layer.layer.get_prunable_weights(): | |
print(np.allclose( | |
target_sparsity, get_sparsity(tf.keras.backend.get_value(weight)), | |
rtol=1e-6, atol=1e-6) | |
) | |
def get_sparsity(weights): | |
return 1.0 - np.count_nonzero(weights) / float(weights.size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment