dlib-to-tf-keras-converter icon indicating copy to clipboard operation
dlib-to-tf-keras-converter copied to clipboard

couldn't get the same embeddings from .pb and .dat

Open arunxz98 opened this issue 5 years ago • 3 comments

First of all, thank you @ksachdeva for providing an excellent source for converting dlib_face_recognition_resnet_model_v1.dat to dlib_face_recognition_resnet_model_v1.pb. i converted the model to .pb just like you mentioned. but when i tested both .dat and .pb by giving same image as input to both models, the embeddings i get from both the models are different. the preprocessing of the image for both model inputs are the same. it would be very helpful if you could help me understand why it happens, and how to get same embeddings from both .dat and .pb. thank you.

arunxz98 avatar Apr 30 '19 06:04 arunxz98

Hi @arunxz98

I am glad you find it useful.

There are 3 main reasons for the differences in the embeddings generated using .dat and .pb

  1. The conversion process first requires to convert from .dat to .xml. This is provided by dlib library itself. However, when I do this conversion there is a change in the floating point precision. This is hardcoded in the dlib i.e. I do not have a way to control the precision from my converter. Locally I hacked it inside dlib and change it to a bigger value.

  2. The linear algebra libraries used by dlib and tensorflow are different and they contribute to the differences

  3. The target CPU/GPU contributes to the difference.

In order to see this yourself, you can create a small example for face recognition using dlib c++ toolkit. Run this example on windows and linux or osx or two different CPU architectures and you will see that the embeddings generated are different.

Hope this helps.

ksachdeva avatar Apr 30 '19 12:04 ksachdeva

thankyou @ksachdeva but does dlib_face_recognition_resnet_model_v1.dat and dlib_face_recognition_resnet_model_v1.pb perform with same accuracy?

arunxz98 avatar May 09 '19 09:05 arunxz98

thankyou @ksachdeva but does dlib_face_recognition_resnet_model_v1.dat and dlib_face_recognition_resnet_model_v1.pb perform with same accuracy?

Yes! I got the same output when I used the 'h5' model and 'pb' model to extract the features of a grope of pictures. It's quite useful.

Thanks for @ksachdeva and Davis King !

RishengZhou avatar Jul 25 '19 03:07 RishengZhou