def build(self, input_shape): # input_shape (None,40) print(input_shape) input_dim = input_shape[1] self.kernel = self.add_weight(shape=(input_dim, self.units), initializer=self.kernel_initializer, name='kernel', regularizer=self.kernel_regularizer, constraint=self.kernel_constraint) if self.H == 'Glorot': self.H = np.float32(np.sqrt(1.5 / (int(input_dim) + self.units))) # print('Glorot H: {}'.format(self.H)) if self.kernel_lr_multiplier == 'Glorot': self.kernel_lr_multiplier = np.float32( 1. / np.sqrt(1.5 / (int(input_dim) + self.units))) # print('Glorot learning rate multiplier: {}'.format(self.kernel_lr_multiplier)) if self.use_bias: pass else: self.lr_multipliers = [self.kernel_lr_multiplier] self.bias = None self.input_spec = InputSpec(min_ndim=2, axes={-1: input_dim}) self.built = True self.binary = binarize(self.kernel, H=self.H)
def build(self, input_shape): # input_shape (None,40) print(input_shape) input_dim = input_shape[1] if self.H == 'Glorot': self.H = np.float32(np.sqrt(1.5 / (int(input_dim) + self.units))) #print('Glorot H: {}'.format(self.H)) if self.w_lr_multiplier == 'Glorot': self.w_lr_multiplier = np.float32( 1. / np.sqrt(1.5 / (int(input_dim) + self.units))) #print('Glorot learning rate multiplier: {}'.format(self.kernel_lr_multiplier)) self.w_constraint = Clip(-self.H, self.H) #self.w_initializer = initializers.RandomUniform(-self.H, self.H) self.w_initializer = initializers.Ones() self.w_regularizer = regularizers.l2(0.01) self.w = self.add_weight(shape=(input_dim, self.units), initializer=self.w_initializer, name='w', regularizer=self.w_regularizer, constraint=self.w_constraint) #self.bw=self.add_weight(shape=(input_dim,self.units), # initializer=self.w_initializer, # name='bw', # regularizer=self.w_regularizer, # constraint=self.w_constraint) #self.bw = binarize(self.w, H=self.H) if self.use_bias: self.lr_multipliers = [ self.w_lr_multiplier, self.bias_lr_multiplier ] self.bias = self.add_weight( shape=(self.units, ), # is this shape right??? # 假设这个weight每一个都不一样好了先! initializer=self.w_initializer, name='bias') #regularizer=self.bias_regularizer, #constraint=self.bias_constraint) else: self.lr_multipliers = [self.w_lr_multiplier] self.bias = None self.input_spec = InputSpec(min_ndim=2, axes={-1: input_dim}) self.built = True self.binary = binarize(self.w, H=self.H)