google / qkeras

QKeras: a quantization deep learning library for Tensorflow Keras
Apache License 2.0
532 stars 102 forks source link

Quantization parameters #35

Closed rtspk closed 3 years ago

rtspk commented 4 years ago

Hello, Thanks a lot guys for this Qkeras library. I really like it. I have a question related to the quantization parameters.

how to really observe the difference in weights and activation values when we use these parameter (i.e. kernel_quantizer = quantized_bits(5,0,1), bias_quantizer = quantized_bits(3), quantized_relu(2) )

for example: this function quantized_model_debug(qmodel,X_test) returns some stats. i.e. the max and min values of activation functions and weights of the model. For the following layer in a model with these parameters.

qx = QDense(8, kernel_quantizer = quantized_bits(3,0,1), bias_quantizer = quantized_bits(3), name="qdense2")(qx) qx = QActivation("quantized_relu(2)", name="act_2")(qx)

output of function: qdense2 : -1.5000 1.7500 ( -0.7500 0.7500) ( 0.0000 0.2500) a( 1.000000 1.000000) act_2 : 0.0000 0.7500

But i manually check the layer's weights using model.get_weights(). the maximum and minimum value turns out be np.max(qmodel.get_weights()[2]) np.min(qmodel.get_weights()[2])

max = 0.9998701 min = -1.0

so i would like to know, how to really know what difference these parameters is making to the weights and activation output.

Thanks alot

zhuangh commented 4 years ago

Hi @srizwantariq regarding the manual checking of the weights, please use https://github.com/google/qkeras/blob/master/qkeras/utils.py#L85 and get the weights from there.

zhuangh commented 3 years ago

close it. feel free to reopen it if you have more questions.