Giter VIP home page Giter VIP logo

Comments (8)

majianjia avatar majianjia commented on May 26, 2024

Hi passiduck,
Thanks for your interest. The simple answer is you have to use bias in both conv/dense layers.
This is restricted by the backend which is the CMSIS-NN.
Any reason you dont want to use bias? I might add this feature later if it is necessary.
Thanks,
Jianjia

from nnom.

passingduck avatar passingduck commented on May 26, 2024

Thanks for the quick reply.
I tried to use an existing trained model. Also beta in BatchNormalization works the same way, I read that no bias is needed.
If it is added in the future, I would appreciate it. Have a nice day.
Thanks!

from nnom.

passingduck avatar passingduck commented on May 26, 2024

Hi jianjia.
I used nnom after I added bias,But I had same issues.
Can you infer any possible reason for this problem to occur?
Before generate_model image
image
After generate_model image
image

After using generate_model function, the first layer's weights changes like this. Could this be a problem?
Before
image
After
image

Thanks, Have a great weekend!
passingduck

from nnom.

majianjia avatar majianjia commented on May 26, 2024

The generate_model() will destroy the Keras's model, because the quantisation is working on the same instance. So you might copy the model before passing it to generate_model() or reload it from file.
Hope it helps

from nnom.

piyush-das avatar piyush-das commented on May 26, 2024

Hi @majianjia For support of legacy models, would it be possible to add support for having a no bias in the Conv Layer, or alternatively if their is a hacky way to implement the same, could you please give pointers.

Thanks.

from nnom.

majianjia avatar majianjia commented on May 26, 2024

nnom doesn't support bias because the backends must have one to work properly currently.

You must add it somewhere. There are 2 ways to do it.

  1. modify nnom conv layers, when there isn't bias available, malloc a chunk of memory at the size of output, set it to 0. use it as bias.
  2. In python code, after loading model (the model after training.). Add a bias tensor to the layer that doesn't have bias. Set it to the correct shape with all values zero.

Hope it helps

from nnom.

piyush-das avatar piyush-das commented on May 26, 2024

Thanks for the pointers.
I tried option 2. However, it resulted in

File "/home/xyz/nnom/scripts/nnom.py", line 216, in find_dec_bits_max_min
  int_bits = int(np.ceil(np.log2(max(max_val, min_val))))
OverflowError: cannot convert float infinity to integer

Then just for cleaning the flow , I also introduced a bias_initializer as "random_normal", so that the max_val, min_val don't reduce to 0 for the bias layers. However, then I got the following error :

File "/home/xyz/nnom/scripts/nnom.py", line 731, in quantize_weights
    f.write('#define ' + layer.name.upper() + '_BIAS_LSHIFT '+to_cstyle(bias_shift) +'\n\n')
UnboundLocalError: local variable 'bias_shift' referenced before assignment

Trying to figure out the reason for the above.

from nnom.

piyush-das avatar piyush-das commented on May 26, 2024

It appears that nnom uses the name of the layers instead of the instance type. In the case that the layers have a different nomenclature, then the bias_shift variable doesn't get assigned.

from nnom.

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.