ARM-software / ML-KWS-for-MCU

Keyword spotting on Arm Cortex-M Microcontrollers
Apache License 2.0
1.14k stars 417 forks source link

Calculate a negative value in bias_shift (shift right) #96

Closed ccnankai closed 5 years ago

ccnankai commented 5 years ago

At the final fc layer bias dec bit =10. I calculated the last layer, wx=8 , bias=10 , bias_shit=-2,bias need to be shifted right 。 But there is no option for the right shift 。 what should I do with this situation. image

ccnankai commented 5 years ago

@saichand07

90

last inputlayer * w =8bit dec bias=10 ====> bias_shit=-2

ccnankai commented 5 years ago

@saichand07 Sorry, I am busy recently. The calculation step has been told in this question #51 .Check out the quant_guide and re-read the quantization section again.The steps are simple.Discuss problems together. swdtianxia@gmail.com

saichand07 commented 5 years ago

@ccnankai

I have calculated all the bias_shifts and out_shifts layer by layer by adjusting the input and output format (using act_max ), like they explained in the quant guide. I put those values in ds_cnn.h and I also tuned the recording window, averaging window len and detection threshold. but still deployed model on board is not detecting words correctly.

could you please tell me what else I need to taken care of. how did you deal with negative shift ?

Thank you very much

ccnankai commented 5 years ago

@saichand07 Did you calculate the MFCC_DEC_BITS ? How did you calculate it.Are you calculating the other *shift parameters correctly?

saichand07 commented 5 years ago

yes, I calculated shift parameters as they explained in the quant guide, How to calculate MFCC_DEC_BITS ? Actually, I didn't change its value, I put MFCC_DEC_BITS = 1 and also changed it to 2, but still its detecting wrong words

saichand07 commented 5 years ago

@ccnankai my first layer Q5.2 weights Q-3.10 bias Q1.6 output layer Q3.4

BIAS_RSHIFT = 2+10-6 = 6 OUT_LSHIFT = 2+10-4 = 8

I calculated all layers like this,

last layer I got negative shift and I don't know how to deal with it, Pool layer act_max I took Q3.4 and last layer Q5.2 so shift of pool layer is 4-2 = 2

could you tell me whatelse I need to consider ?

ccnankai commented 5 years ago

@saichand07 I think you still have the wrong calculation of the parameters.I can see good results.

ccnankai commented 5 years ago

Weights Q-3.10 Wrong, how did you get it?

saichand07 commented 5 years ago

after running Quant_test.py the weights are generated randomly, my parameters are window size_ms 40 window_stride_ms 20 dct_coefficient_count 10

ccnankai commented 5 years ago

Weights Q-3.10 This parameter is definitely wrong. No need to change any thing in fold_batchnorm.Are you a student, is this algorithm used for experimentation??

saichand07 commented 5 years ago

yes, how can we deal with this situation ?

ccnankai commented 5 years ago

How did you get this result Weights Q-3.10,This calculation step is wrong.

saichand07 commented 5 years ago

@ccnankai thanks, I found the problem, weights were wrong now its working

weishu20 commented 5 years ago

@ccnankai thanks, I found the problem, weights were wrong now its working

hello,can you tell me how to calculate Q of input and output?I have no idea....

ccnankai commented 5 years ago

@weishu20 the first layer is input layer(mfcc)