strand2013 / NNIE-lite

⚡️ Using NNIE as simple as using ncnn ⚡️
MIT License
183 stars 50 forks source link

NNIE_Get_Result 偶尔会输出远超4096的值 #4

Open northeastsquare opened 3 years ago

northeastsquare commented 3 years ago

网络多数时候运行是正常的,偶尔会输出远超4096的值。 https://github.com/RaySue/NNIE-lite/blob/daf0dc19f47bc1e286308d137e1e636c2ef98da7/src/nnie_core.c#L272

                for (n = 0; n < pstNnieParam->astSegData[u32SegIdx].astDst[u32NodeIdx].u32Num; n++)
                {
                    for (i = 0; i < u32Chn; i++)
                    {
                        for (j = 0; j < u32Height; j++)
                        {
                            for (k = 0; k < u32Width; k++)
                            {
                                *(tmp + k) = (*(ps32ResultAddr + k)) * 1.0f / SAMPLE_SVP_NNIE_QUANT_BASE;
                            }
                            ps32ResultAddr += u32Stride / sizeof(HI_U32);
                            tmp += t.width;
                        }
                    }
                }

对*(ps32ResultAddr + k)打印,偶尔会出现特别大的值,远超4096

northeastsquare commented 3 years ago

我跑的网络是这个,https://github.com/valencebond/Strong_Baseline_of_Pedestrian_Attribute_Recognition/blob/5363c9859dc87b79e39a2b353a6a6eb8185d5c6f/models/base_block.py#L7 主干网络是resnet50, 然后跟着average global pool, fc2048->7, batchnorm1d

northeastsquare commented 3 years ago

出现这个问题的原因,感觉和输入无关,同样的输入,多数时候也是没有问题的偶尔出问题。

northeastsquare commented 3 years ago

找到原因了,是多线程的问题,一个线程把结果给写成了float形式,另一个线程把这段内存当成HI_U32来读,就会出问题了。 那么,您写的这个nnie-lite, 对于多线程,该如何inference呢?

northeastsquare commented 3 years ago

终于找到原因了,网络的最大输出个数代码里面写的是5,而我训练的网络输出个数为7所以,最后两个偶尔会出现大于4096的值,改为7就好了。 https://github.com/RaySue/NNIE-lite/blob/master/inc/Net.hpp#L13