Git Product home page Git Product logo

Comments (3)

lcit avatar lcit commented on June 2, 2024

I realized that the weights in the C++ code are much larger then the ones of QKeras. In fact by a factor 64. Is this correct?

//Numpy array shape [3, 3, 1, 1]
//Min -0.669433593750
//Max 0.915435791016
//Number of zeros 0

#ifndef W2_H_
#define W2_H_

#ifndef __SYNTHESIS__
weight2_t w2[9];
#else
weight2_t w2[9] = {-29.462890625, 22.447265625, 58.587890625, 26.078125000, -19.662109375, -8.080078125, -23.574218750, -42.843750000, -10.302734375};
#endif

#endif

from hls4ml.

lcit avatar lcit commented on June 2, 2024

I found the reason for the scaled weights. In QKeras, if the quantizer's alpha is none, the weights are scaled by a certain factor equal to the data type scale. And hls4ml puts this layer to normalize the scaling factor:

nnet::normalize<layer2_t, result_t, config4>(layer2_out, layer4_out, s4, b4); // fused_convbn_0_alpha

However, the fact that the scaling creates the overflow seems a bug to me.

To avoid this I specifically set alpha=1: quantized_bits(16,6,alpha=1)

from hls4ml.

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.