-
Notifications
You must be signed in to change notification settings - Fork 19.6k
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
Refactor regularizers and add add_weight method. #4703
Conversation
losses = to_list(losses) | ||
if not hasattr(self, 'losses'): | ||
self.losses = [] | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The right way to check if a class attribute is a property is:
is_property = isinstance(type(obj).attribute, property)
So here it would be:
if not isinstance(type(self).losses, property):
self.losses += losses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fairly sure property is just a wrong word in comment. See for example https://github.com/fchollet/keras/blob/master/keras/layers/core.py#L736
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't actually want to skip the case "is property", because we may well have a property with a getter, in which case appending to list would be the right behavior (e.g. this how trainable_weights
currently work).
We explicitly want to skip the case "not settable", distinct from "is property". It isn't clear what is the best way to check if an attribute is settable, by try/except seems like a good candidate: http://stackoverflow.com/questions/6102747/checking-if-property-is-settable-deletable-in-python
# Update self.updates | ||
updates = to_list(updates) | ||
if not hasattr(self, 'updates'): | ||
self.updates = [] | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too
It would be better to warn all deprecations at call site. See https://docs.python.org/3/library/warnings.html#warnings.warn for example. Basically just add Also it would be less painful for everyone involved to add a hard remove version. |
I added an explicit removal date for the deprecated attributes/methods. |
In general, these breaking changes are "fine", because:
|
If I load the weights of an old model (prior to this PR) with an L2 regularization of X into a new version of Keras with the same L2 regularization of X, then the loss is much higher for the new model than the old on the same dataset (22.0 vs. 3.4). I've tried turning off the L2 regularization, which then makes the losses similar. @fchollet @farizrahman4u Has the underlying definition of the regularization changed with this implementation or why are the losses suddenly different? |
Using Keras model in another application (distributed tensorflow as in : https://gist.github.com/fchollet/2c9b029f505d94e6b8cd7f8a5e244a4e
If I understand well, now I should do
It crashed when I do that. Any help please? |
This PR does a few things:
add_weight
methods to create weights. This removes a lot of boilerplate and complexity.Warning about custom user code:
Custom regularizers may no longer work.
Custom layers may see their regularizers disabled (if they were using regularizers).
We raise appropriate warnings, so these issues should be noticed by the target users.
Additionally, no code would be crashing as a result of these changes.
Feedback welcome.