kendryte / nncase

Open deep learning compiler stack for Kendryte AI accelerators ✨
Apache License 2.0
752 stars 184 forks source link

nncase inference output not equal to k210 output #116

Closed zye1996 closed 1 year ago

zye1996 commented 4 years ago

Hi,

I am trying to deploy kmodel onto the k210 board. I used the CI version of nncase and examine the output on computer for the same kmodel I used on k210. When running on computer, the inference output is reasonally correct. But the output from k210 is not even close for the same image. I examined on the first output from model and it is included in the result

I used the script here to convert image to .h file and load the image, and print out result on from serial port.

is this due to the imcompatibility between the new nncase and kendryte standalone sdk?

Here are result I got from k210 and pc for image.

result.zip

krishnak commented 4 years ago

@zye1996 I think its not related to nncase version alone, I am using an earlier version even that is having this problem all of a sudden, can you let me know whether you have Conv2D or SeparableConv2D in your model. Also how many classes of objects are you trying to detect?

zye1996 commented 4 years ago

@zye1996 I think its not related to nncase version alone, I am using an earlier version even that is having this problem all of a sudden, can you let me know whether you have Conv2D or SeparableConv2D in your model. Also how many classes of objects are you trying to detect?

Yes I do have Conv2D in the model, and I am getting the feature map only. When I used older versions of nncase, nncase inference output does not match tflte output; using the CI verision, previous problem solved but nncase inference output does not match the k210 board output

krishnak commented 4 years ago

which version of SDK are you using, is it the latest from github or kendryte website?

zye1996 commented 4 years ago

which version of SDK are you using, is it the latest from github or kendryte website?

I am using the version 0.5.6 and it should be the lastest release version

krishnak commented 4 years ago

I meant to ask about gcc tool chain not SDK, are you using it from this link or from kendryte website.

https://github.com/kendryte/kendryte-gnu-toolchain/releases/tag/v8.2.0-20190213

zye1996 commented 4 years ago

My toolchain is 8.2.0 as with platformio

krishnak commented 4 years ago

in your K210 can you let me know how you extract the tensor values from the KPU output

zye1996 commented 4 years ago

I simply printed out through serial port as I do not have a debug tool.

krishnak commented 4 years ago

KPU outputs float with 6 decimal places in your case, there doesn't seem to be any correlation between the two

The first 10 values from your pc_result_bin is 0.007824562 0.007824562 0.011736842 0.007824562 0.007824562 0.007824562 0.011736842 0.015649123 0.015649123 0.015649123

.015649,0.011737,0.011737,0.011737,0.011737,0.011737,0.011737,0.011737,0.015649,0.015649

krishnak commented 4 years ago

the first 10 values from my model on PC are -0.6152274 0.0 0.0 -1.2304548 -0.6152274 0.6152274 -0.6152274 -0.6152274 0.0 -1.2304548

My first 10 values from KPU are -0.615224 -0.615224 0.000003 0.000003 -0.615224 0.000003 -1.230451 -0.615224 0.615231 -2.460906

In my case can you spot the difference, the first value is more or less similar, however the position in the array is jumbled. For ex: there are 4 -0.6152274 in the first 10 values in the PC as well as the KPU but their location in the array is not correct

I rechecked your output file 0.007825 is present in 22nd position in K210 output.

It appears that there is some data shift.

I will post a next message with my model which works both in PC and K210, to see what their output looks like

krishnak commented 4 years ago

KPU output of model which works in K210 and also in PC -0.343010 0.000000 -0.171505 -0.343010 0.000000 0.000000 0.000000 0.343011 0.000000 -0.514516 0.171506 -0.343010 0.171506 -0.343010 -0.171505 -0.343010 0.000000 -0.343010 0.000000 0.343011 PC output of 20 items in the array corresponding to the above K210 position -0.3430107 0.17150535 -0.17150535 -0.3430107 -0.3430107 0.0 -0.17150535 0.51451606 0.17150535 -0.6860214 0.3430107 -0.3430107 0.17150535 0.0 0.0 -0.3430107 0.0 0.0 0.17150535 0.3430107

krishnak commented 4 years ago

I am unable to conclude anything with this data, all I can see the values from PC and KPU are same in my model's case, they are present at different array index

krishnak commented 4 years ago

I just reshaped the data at a particular grid so that data make sense

[[ -0.3430107   -0.51451606  -0.17150535  -1.2005374   -6.8602138
    7.889246   -12.691396    -8.403762  ]
 [  1.3720428    0.3430107    0.3430107   -0.51451606  -8.918278
    6.002687   -12.005374    -6.8602138 ]
 [  0.8575267    1.0290321    0.17150535  -0.51451606  -9.94731
    4.80215     -8.232257    -7.37473   ]]

These are the values at grid location 0 , the above is the value from PC inference using nncase

Now on K210

Box 1
x -0.343010
y -0.343010
w -0.343010
h -1.372043
obj -7.546235
Box2
x 1.372043
y 0.514516
w 0.343011
h -0.514516
obj -9.604300
Box 3
x 0.857527
y 1.029032
w 0.171506
h -0.514516
obj -10.290320
krishnak commented 4 years ago

It is obvious that apart from Box 3 none of the values match the x,y,w,h co-ordinates, even for box 3 the objectness score is different.

For another feature map the PC value is

[[  0.18861096   0.18861096   0.          -0.3772219  -10.562214
   -0.18861096  -0.56583285  -0.3772219 ]
 [  0.3772219    0.3772219   -0.18861096   0.         -10.939435
    0.9430548   -0.18861096  -0.7544438 ]
 [  0.           0.18861096   0.           0.18861096 -10.939435
   -0.7544438   -0.56583285  -1.6974986 ]]

Box 1
x 0.188611
y 0.188611
w 0.000000
h -0.377222
obj -10.750825

Box 2
x 0.377222
y 0.188611
w -0.188611
h 0.000000
obj -11.128046

Box 3
x 0.188611
y 0.000000
w 0.000000
h 0.188611
obj -10.939435
zye1996 commented 4 years ago

In my case, I am not only seeing a jumble between values, but the whole distribution of values are not the same. I find the max values produced by k210 is very different from the result produced by pc

krishnak commented 4 years ago

@zye1996 I think nncase PC output may not match K210 output when you use an image, the reason being nncase is using opencv to transform the image to fit the model input. Where as you pre-process the input to K210, the numerical input data may not be the same in both the cases.

krishnak commented 3 years ago

Did this get investigated?