Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a model.check_trainable_weights_consistency #8234

Merged
merged 4 commits into from
Oct 25, 2017

Conversation

julienr
Copy link
Contributor

@julienr julienr commented Oct 24, 2017

This will raise a UserWarning when the user modifies model.trainable
and tries to print a model summary or launch a fit without having
called .compile.

Calling .compile() is necessary because trainable weights are collected
in compile (model._collected_trainable_weights).

Fixes #8121

This will raise a UserWarning when the user modifies model.trainable
and tries to print a model summary or launch a fit without having
called .compile.

Calling .compile() is necessary because trainable weights are collected
in compile (model._collected_trainable_weights).
fchollet
fchollet previously approved these changes Oct 24, 2017
Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a very good idea, thanks.

if not hasattr(self, '_collected_trainable_weights'):
return

if count_params(self.trainable_weights) != \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please no \

count_params(self._collected_trainable_weights):
warnings.warn(UserWarning(
'Discrepancy between trainable weights and collected trainable'
' weights, did you set model.trainable without calling'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: ` around code keywords

@@ -5,6 +5,11 @@
import numpy as np


def count_params(weights):
"""Count the total number of scalars composing the weights"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring formatting: one-line summary should end with a period; the dosctring should include a # Arguments and # Returns section.

@julienr
Copy link
Contributor Author

julienr commented Oct 25, 2017

Thanks for the quick review. I think I addressed your comments.

@@ -945,9 +946,25 @@ def handle_metrics(metrics, weights=None):
trainable_weights = self.trainable_weights
self._collected_trainable_weights = trainable_weights

def check_trainable_weights_consistency(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this method private (underscore) and make the docstring style-compliant.

@julienr julienr force-pushed the fix_trainable_weights_reporting branch from fc4581e to 7efdf99 Compare October 25, 2017 20:34
Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@fchollet fchollet merged commit cab77c8 into keras-team:master Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants