Need explanation of nn.c

Discussion related to "under the hood" OpenMV topics.
ky66111
Posts: 6
Joined: Fri May 10, 2019 4:13 am

Need explanation of nn.c

Postby ky66111 » Tue Jun 04, 2019 4:50 am

hello, here I come again. Thanks for your patience for the last several posts.
My nn model still cannot work, so I run into openmv/src/omv/nn/nn.c and want to figure out how it works.
In the nn_transform_input method,

Code: Select all

for (int y=0, i=0; y<data_layer->h; y++) {
            int sy = (y*y_ratio)>>16;
            for (int x=0; x<data_layer->w; x++, i++) {
                int sx = (x*x_ratio)>>16;
                int p = (int) IMAGE_GET_GRAYSCALE_PIXEL(img, sx+roi->x, sy+roi->y);
                input_data[i] = (q7_t)__SSAT((((p - (int) data_layer->r_mean)<<7) + (1<<(input_scale-1))) >> input_scale, 8);
            }
        }
can you give an example of

Code: Select all

input_data[i] = (q7_t)__SSAT((((p - (int) data_layer->r_mean)<<7) + (1<<(input_scale-1))) >> input_scale, 8);
?
Is this a normalization?
Thanks!
User avatar
iabdalkader
Posts: 1143
Joined: Sun May 24, 2015 3:53 pm

Re: Need explanation of nn.c

Postby iabdalkader » Tue Jun 04, 2019 9:53 am

Yes it removes the mean from every channel and scales the input in one step.
ky66111
Posts: 6
Joined: Fri May 10, 2019 4:13 am

Re: Need explanation of nn.c

Postby ky66111 » Tue Jun 04, 2019 10:12 pm

what's the range of p? in pixel metric like 0-255?
If so, input_data = ((p - mean) << 7) + (1 << (input_scale - 1)) >> input_scale equals ((242 - 90) << 7) + (1 << 8)) >> 9 when p=242, mean=90, input_scale=9.
The term including p supposes to be variance term and term of 1 << (input_scale - 1) is the bias term (I guess). But the former looks much larger than the latter term, which leads the bias term no effect. right? This is why I want you to give me an example.
User avatar
iabdalkader
Posts: 1143
Joined: Sun May 24, 2015 3:53 pm

Re: Need explanation of nn.c

Postby iabdalkader » Wed Jun 05, 2019 10:31 am

Yes the input range is 0-255 as I've told you before and you could always print the input/output values, build the code and see the values. BTW the scaling part comes from ARM ML examples, you may find more help there:

https://github.com/ARM-software/ML-examples

https://github.com/ARM-software/CMSIS_5

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 3 guests