def call(self, inputs): quantized_kernel = quantize(self.kernel, nb=self.nb) inverse_kernel_lr_multiplier = 1. / self.kernel_lr_multiplier inputs_qnn_gradient = (inputs - (1. - 1./inverse_kernel_lr_multiplier) * K.stop_gradient(inputs))\ * inverse_kernel_lr_multiplier outputs_qnn_gradient = K.conv2d(inputs_qnn_gradient, quantized_kernel, strides=self.strides, padding=self.padding, data_format=self.data_format, dilation_rate=self.dilation_rate) outputs = (outputs_qnn_gradient - (1. - 1./self.kernel_lr_multiplier) * K.stop_gradient(outputs_qnn_gradient))\ * self.kernel_lr_multiplier #outputs = outputs*K.mean(K.abs(self.kernel)) if self.use_bias: outputs = K.bias_add(outputs, self.bias, data_format=self.data_format) if self.activation is not None: return self.activation(outputs) return outputs
def call(self, inputs): quantized_kernel = quantize(self.kernel, nb=self.nb) output = K.dot(inputs, quantized_kernel) if self.use_bias: output = K.bias_add(output, self.bias) if self.activation is not None: output = self.activation(output) return output