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

use_bias = True Error in binary_layers.py #13

Open
miibotree opened this issue Dec 14, 2017 · 0 comments
Open

use_bias = True Error in binary_layers.py #13

miibotree opened this issue Dec 14, 2017 · 0 comments

Comments

@miibotree
Copy link

If I set use_bias = True in binarynet or xnornet, these vars are not defined:
self.output_dim
self.bias_initializer
self.bias_regularizer
self.bias_constraint

according the source code in keras layers/convolutional.py, I modify code as follows:

from keras import regularizers
class BinaryDense(Dense):
    def __init__(self, units, H=1., kernel_lr_multiplier='Glorot', bias_lr_multiplier=None,
                 bias_initializer='zeros', bias_regularizer=None, bias_constraint=None,
                 **kwargs):
        super(BinaryDense, self).__init__(units, **kwargs)
        self.H = H
        self.kernel_lr_multiplier = kernel_lr_multiplier
        self.bias_lr_multiplier = bias_lr_multiplier
        self.bias_initializer = initializers.get(bias_initializer)
        self.bias_regularizer = regularizers.get(bias_regularizer)
        self.bias_constraint = constraints.get(bias_constraint)
        ......
    def build(self, input_shape):
        assert len(input_shape) >= 2
        input_dim = input_shape[1]
        self.output_dim = self.units
       ......
    def get_config(self):
        config = {'H': self.H,
                  'kernel_lr_multiplier': self.kernel_lr_multiplier,
                  'bias_lr_multiplier': self.bias_lr_multiplier,
                  'bias_initializer': initializers.serialize(self.bias_initializer),
                  'bias_regularizer': regularizers.serialize(self.bias_regularizer),
                  'bias_constraint': constraints.serialize(self.bias_constraint)
                  }

so as class BinaryConv2D but set self.output_dim = self.filters

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

No branches or pull requests

1 participant