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 option to pass kernel_* and bias_* regularizers to Coral layer #17

Closed
gmgeorg opened this issue Mar 3, 2022 · 3 comments · Fixed by #19
Closed

Add option to pass kernel_* and bias_* regularizers to Coral layer #17

gmgeorg opened this issue Mar 3, 2022 · 3 comments · Fixed by #19

Comments

@gmgeorg
Copy link
Collaborator

gmgeorg commented Mar 3, 2022

CORN layer inherits fromDense, so it all usual **kwargs can be passed.

Coral layer inherits from Layer, so kernel_regualizer/bias_regularizer (and other kwargs that would make sense for Coral) dont work as expected (passing them fails init since Layer does not recognized those kwarggs)

@ck37
Copy link
Owner

ck37 commented Mar 3, 2022 via email

@gmgeorg
Copy link
Collaborator Author

gmgeorg commented Mar 3, 2022

I don't think that will be as trivial, since AFAIU the point of the CORAL layer is that it is a specific (constrained) structure of a fully connected dense layer (which is what CORN solves), which requires overwriting the build method anyway -- so might as well just add the arguments to the inherited Layer class

Looking at Dense() layer implementation, it should be straightforward to pass kernel_regularizer and bias_regularizer as arguments to the CoralOrdinalLayer init, set them as self.kernel_regularizer=regularizers.get(kernel_regularizer) and then pass them to self.add_weight(..., regularizer=self.{kernel|bias}_regularizer) for self.kernel and self.bias respectively.

See https://github.com/keras-team/keras/blob/v2.8.0/keras/layers/core/dense.py#L147

This is mostly to support the same function signagure as a typical Dense layer that has bias/kernel weights.

@ck37
Copy link
Owner

ck37 commented Mar 13, 2022

Belated response but thanks for the explanation on this!

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 a pull request may close this issue.

2 participants