Git Product home page Git Product logo

Comments (1)

kantic avatar kantic commented on May 8, 2024

I found that, generally, the quantized values seem to not be strictly limited to valid value ranges which are assumed by the specified number of bits in the quantization methods.

Another example of this is quantized_sigmoid using 8 bits in total. In this configuration, I would normally assume that the output of quantized_sigmoid lies in the interval [0.0, 1-(2**-8)] = [0.0, 0.99609375] with a resolution (value step size) of 2**-8 = 0.00390625, because this is what can be represented by using 8 bits.
But, the following code example shows that the value range of quantized_sigmoid is equal to [0.0, 1.0]:

import qkeras as qk

qs = qk.quantized_sigmoid(8)
input_value = tf.constant(-1000.0)
output = qs(input_value).numpy()
print('Sigmoid Lower Bound: {0}'.format(output))

input_value = tf.constant(1000.0)
output = qs(input_value).numpy()
print('Sigmoid Upper Bound: {0}'.format(output))

input_value = tf.constant(-0.996)
output = qs(input_value).numpy()
print('Sigmoid Resolution: {0}'.format(output))

Output:

Sigmoid Lower Bound: 0.0
Sigmoid Upper Bound: 1.0
Sigmoid Resolution: 0.00390625

Expected Output:

Sigmoid Lower Bound: 0.0
Sigmoid Upper Bound: 0.99609375
Sigmoid Resolution: 0.00390625

Also, the min and max methods output the interval boundaries of [0.0, 1.0]:

print(qs.min())
print(qs.max())

Output:

0.0
1.0

Expected Output:

0.0
0.99609375

This leads to the fact that for these edge cases the quantization methods output values which are not representable with the specified number of bits. In order to 'encode' the current behaviour of quantized_sigmoid in hardware, it would require 9 bits in total and a special (and inefficient) encoding scheme, in which the upper boundary of 1.0 is also representable.
Similar considerations are also true for the other quantization methods.
Am I missing some details here? Is this the intended quantization scheme in QKeras?

from qkeras.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.