Skip to content

Instantly share code, notes, and snippets.

@seahrh
Created June 8, 2018 06:08
Show Gist options
  • Save seahrh/ad13ccf6a01f0fb99509503c86288d77 to your computer and use it in GitHub Desktop.
Save seahrh/ad13ccf6a01f0fb99509503c86288d77 to your computer and use it in GitHub Desktop.
Get model size after L1 regularization
# Get model size after L1 regularization
# see: https://colab.research.google.com/notebooks/mlcc/sparsity_and_l1_regularization.ipynb?utm_source=mlcc&utm_campaign=colab-external&utm_medium=referral&utm_content=l1regularization-colab&hl=en#scrollTo=e6GfTI0CFhB8
def model_size(estimator):
variables = estimator.get_variable_names()
size = 0
for variable in variables:
if not any(x in variable
for x in ['global_step',
'centered_bias_weight',
'bias_weight',
'Ftrl']
):
size += np.count_nonzero(estimator.get_variable_value(variable))
return size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment