njvisionpower / mxnet-insightface-cpp

CPU realtime face recognition pipeline with mxnet c++ framework
128 stars 41 forks source link

different embedding from same image #8

Closed 363325971 closed 5 years ago

363325971 commented 5 years ago

the output of cv::Mat extractFeature(const cv::Mat& img) is different for running multiple times with same input image, is this a bug or there are some random factors in the model?

njvisionpower commented 5 years ago

What's your test detail?

363325971 commented 5 years ago

I just run 'extractFeature' twice with same input image, but it returns difference output embedding.. here are the outputs, the first element in the embeddings are always different.

First run: [111366.5, 3.066041e-41, 0.0095913569, -0.025121188, 0.15920584, -0.01293171, -0.031169757, -0.050265502, -0.068051614, -0.050611082, -0.0038233625, -0.055625539, -0.069868743, -0.058286775, 0.12934017, -0.036382664, -0.063158251, -0.028065389, -0.035188515, -0.0089806123, 0.10904375, -0.00041712372, 0.021233911, 0.014791017, -0.037519146, -0.17423606, 0.016600661, -0.053900454, -0.10248714, -0.07516291, 0.035337143, 0.010783359, 0.1611025, 0.06654875, -0.081317425, -0.041211765, -0.027614318, -0.037969682, -0.12447846, -0.028294429, -0.10721306, -0.049190339, 0.066431969, 0.047107641, 0.1330058, -0.054921102, -0.15594019, -0.0087330788, 0.11446479, 0.018507451, -0.091966189, -0.06319806, 0.077058062, 0.010635531, 0.070944734, -0.15560021, 0.12090917, 0.029556427, -0.049350057, 0.097370744, 0.052389003, 0.049042683, 0.057136182, -0.026889181, -0.23839961, 0.055421684, -0.16180624, -0.0034861162, -0.041280799, -0.10623907, 0.11725681, 0.092240825, 0.061277341, -0.0080011887, -0.066050552, 0.14534144, 0.077928655, -0.021857766, 0.10998425, -0.16150351, 0.048306432, -0.08206702, 0.1431445, -0.060901396, -0.047017861, 0.20277044, -0.21869926, 0.073125243, 0.055519536, -0.054281864, -0.073007934, -0.006750444, -0.062403806, -0.021631002, 0.018852875, -0.019193849, 0.0089840805, 0.080044903, 0.089006968, -0.0021176452, -0.18582074, 0.088393435, 0.018560974, -0.081636243, -0.15054362, 0.12146135, -0.055596381, -0.087262422, 0.13435136, 0.061496731, -0.01343497, -0.10638848, 0.079619132, -0.099080473, 0.15166907, 0.11664374, -0.044848815, 0.074711435, 0.022400152, -0.10689036, 0.013681017, 0.090173773, -0.18057565, 0.011257434, -0.030276416, -0.12345151, -0.011796401, 0.082795069]

Second run: [7.3419135e-14, 3.078933e-41, 0.0095913569, -0.025121188, 0.15920584, -0.01293171, -0.031169757, -0.050265502, -0.068051614, -0.050611082, -0.0038233625, -0.055625539, -0.069868743, -0.058286775, 0.12934017, -0.036382664, -0.063158251, -0.028065389, -0.035188515, -0.0089806123, 0.10904375, -0.00041712372, 0.021233911, 0.014791017, -0.037519146, -0.17423606, 0.016600661, -0.053900454, -0.10248714, -0.07516291, 0.035337143, 0.010783359, 0.1611025, 0.06654875, -0.081317425, -0.041211765, -0.027614318, -0.037969682, -0.12447846, -0.028294429, -0.10721306, -0.049190339, 0.066431969, 0.047107641, 0.1330058, -0.054921102, -0.15594019, -0.0087330788, 0.11446479, 0.018507451, -0.091966189, -0.06319806, 0.077058062, 0.010635531, 0.070944734, -0.15560021, 0.12090917, 0.029556427, -0.049350057, 0.097370744, 0.052389003, 0.049042683, 0.057136182, -0.026889181, -0.23839961, 0.055421684, -0.16180624, -0.0034861162, -0.041280799, -0.10623907, 0.11725681, 0.092240825, 0.061277341, -0.0080011887, -0.066050552, 0.14534144, 0.077928655, -0.021857766, 0.10998425, -0.16150351, 0.048306432, -0.08206702, 0.1431445, -0.060901396, -0.047017861, 0.20277044, -0.21869926, 0.073125243, 0.055519536, -0.054281864, -0.073007934, -0.006750444, -0.062403806, -0.021631002, 0.018852875, -0.019193849, 0.0089840805, 0.080044903, 0.089006968, -0.0021176452, -0.18582074, 0.088393435, 0.018560974, -0.081636243, -0.15054362, 0.12146135, -0.055596381, -0.087262422, 0.13435136, 0.061496731, -0.01343497, -0.10638848, 0.079619132, -0.099080473, 0.15166907, 0.11664374, -0.044848815, 0.074711435, 0.022400152, -0.10689036, 0.013681017, 0.090173773, -0.18057565, 0.011257434, -0.030276416, -0.12345151, -0.011796401, 0.082795069]

HarshPathakhp commented 5 years ago

Hi, I confirmed this as well. The vector's first value (at index 0) is different each time the program is run. But within the same program, the model gives same embeddings for a given image.

KirkKong commented 5 years ago

In extractFeature, a copy of output mat shall be return. code: return output.clone();

njvisionpower commented 5 years ago

In extractFeature, a copy of output mat shall be return. code: return output.clone();

Thanks for your checking. I will test and fix it asap.

njvisionpower commented 5 years ago

Hi @363325971 @HarshPathakhp @KirkKong, this bug has been fixed. You can update latest codes to try. Thanks for all your comments :)