google / qkeras

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

Change The kernel_range of QLayers #4

Closed Guyume closed 4 years ago

Guyume commented 4 years ago

Thanks for your works, it's quite convenient for us who want to quantizate model. But some things I get confused when I use it, so I hope to get your help if possible.

That is, I find the the config of Qlayers like QDense has the item named "kernel_range=1.0", does it constrain the weight within the range or something else?

https://github.com/google/qkeras/blob/92ec6d37c97c27a5ac9d59e0629ced0ddc432a20/qkeras/qlayers.py#L736 kernel_range=1.0,

Second is quantized_bit. the code make the max(x)=1, min(x)=-1, but mine max(x) and min(x) are much smaller than 1 or -1, and varies by layers, I think if make them 1 and -1 then make quantization will loss many quantization levels unused, so I want to know is there any way to change the max(x) or min(x) by layers, e.g pass it in q_dict like /examples/example_keras_to_qkeras.py?

https://github.com/google/qkeras/blob/92ec6d37c97c27a5ac9d59e0629ced0ddc432a20/qkeras/qlayers.py#L202 1) max(x) = +1, min(x) = -1 2) max(x) = -min(x)

Thanks again!

I think I have solved the issue, thanks again for your amazing library