dlib-models icon indicating copy to clipboard operation
dlib-models copied to clipboard

How to train my own dlib_face_recognition_resnet_model_v1.dat

Open 74981 opened this issue 6 years ago • 16 comments

How to train my own dlib_face_recognition_resnet_model_v1.dat. Please help and if possible share the python api for the same.

74981 avatar Dec 27 '18 06:12 74981

@davisking I'm also interested if you're willing to release the dataset. In any case, I understand that it involved a lot of work.

nicolaerosia avatar Mar 13 '19 16:03 nicolaerosia

You can use the trillion faces or ms celeb datasets. They are already available and very large.

davisking avatar Mar 14 '19 01:03 davisking

Davis, is there a python API for training your own model? Thank you, sir! Dlib is amazing.

pdstanley avatar Mar 16 '19 14:03 pdstanley

No

davisking avatar Mar 16 '19 17:03 davisking

@davisking , I don't know how to train my dlib_face_recognition_resnet_model_v1 model, can you give me some methods!

shenjackson avatar May 03 '19 03:05 shenjackson

This example program goes into the details: http://dlib.net/dnn_metric_learning_on_images_ex.cpp.html

davisking avatar May 04 '19 11:05 davisking

@davisking Just to be sure, is that C++ code the one used to train this model? I'd like to transfer learn on my own dataset and want to be sure I'm starting from the right place

csaftoiu avatar Oct 26 '19 00:10 csaftoiu

Also we’re rhe input images aligned centered cropped etc or just resized to 150x150 with a crop from a face finding model? Also be helpful to know this just in terms of using the base model - I see the sample code that uses it does this so I presume it was trained that way As well

csaftoiu avatar Oct 26 '19 00:10 csaftoiu

The notes on how this model was trained are in the example program that shows how to use it: http://dlib.net/dnn_face_recognition_ex.cpp.html

davisking avatar Oct 31 '19 00:10 davisking

Ah thanks for that! Very helpful.

I managed to get it to train a few steps on some images of my own. However I couldn’t load it into a net_type because the saved weights have the affine layers while the net_type has batchnorm layers. Though I see it auto converts from batchnorm to affine when saving, I wasn’t able to get it to auto convert from affine to batchnorm to keep training. So I have been training the anet_type directly.

Is there a way to retrieve the net_type from the saved weights on the repo? Or are part of the batchnorm parameters lost when saving the model meaning I can’t transfer learn it?

On Thu, Oct 31, 2019 at 12:02 AM Davis E. King [email protected] wrote:

The notes on how this model was trained are in the example program that shows how to use it: http://dlib.net/dnn_face_recognition_ex.cpp.html

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/davisking/dlib-models/issues/11?email_source=notifications&email_token=AAAKQ2OQY3ISUSKPO7BLFTDQRIOC5A5CNFSM4GMJTZUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECWEUAY#issuecomment-548162051, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAKQ2IQAVDMXCVBUR3ZWQLQRIOC5ANCNFSM4GMJTZUA .

csaftoiu avatar Oct 31 '19 13:10 csaftoiu

Some things are lost when converting from batch norm to affine. Save in batch norm form when doing training.

On Thu, Oct 31, 2019 at 9:17 AM Claudiu [email protected] wrote:

Ah thanks for that! Very helpful.

I managed to get it to train a few steps on some images of my own. However I couldn’t load it into a net_type because the saved weights have the affine layers while the net_type has batchnorm layers. Though I see it auto converts from batchnorm to affine when saving, I wasn’t able to get it to auto convert from affine to batchnorm to keep training. So I have been training the anet_type directly.

Is there a way to retrieve the net_type from the saved weights on the repo? Or are part of the batchnorm parameters lost when saving the model meaning I can’t transfer learn it?

On Thu, Oct 31, 2019 at 12:02 AM Davis E. King [email protected] wrote:

The notes on how this model was trained are in the example program that shows how to use it: http://dlib.net/dnn_face_recognition_ex.cpp.html

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/davisking/dlib-models/issues/11?email_source=notifications&email_token=AAAKQ2OQY3ISUSKPO7BLFTDQRIOC5A5CNFSM4GMJTZUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECWEUAY#issuecomment-548162051 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AAAKQ2IQAVDMXCVBUR3ZWQLQRIOC5ANCNFSM4GMJTZUA

.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/davisking/dlib-models/issues/11?email_source=notifications&email_token=ABPYFR6IRGWI4PNRKTODKX3QRLLFRA5CNFSM4GMJTZUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECXXJLI#issuecomment-548369581, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPYFR3L2HVRKDUDMGM23LLQRLLFRANCNFSM4GMJTZUA .

davisking avatar Oct 31 '19 23:10 davisking

Is there any way to get the batch norm form of the model on the repo? Or is this reserved for secret sauce not for public consumption? :). I understand if it’s the latter.

If it’s not available I suppose we can’t transfer learn it as-is. If we load weights and swap out the affine for a random batch norm it seems that’d lose all the learning in first few steps. Best option seems to be to keep the affine as-is. Let me know what you think.

On Thu, Oct 31, 2019 at 11:52 PM Davis E. King [email protected] wrote:

Some things are lost when converting from batch norm to affine. Save in batch norm form when doing training.

On Thu, Oct 31, 2019 at 9:17 AM Claudiu [email protected] wrote:

Ah thanks for that! Very helpful.

I managed to get it to train a few steps on some images of my own. However I couldn’t load it into a net_type because the saved weights have the affine layers while the net_type has batchnorm layers. Though I see it auto converts from batchnorm to affine when saving, I wasn’t able to get it to auto convert from affine to batchnorm to keep training. So I have been training the anet_type directly.

Is there a way to retrieve the net_type from the saved weights on the repo? Or are part of the batchnorm parameters lost when saving the model meaning I can’t transfer learn it?

On Thu, Oct 31, 2019 at 12:02 AM Davis E. King <[email protected]

wrote:

The notes on how this model was trained are in the example program that shows how to use it: http://dlib.net/dnn_face_recognition_ex.cpp.html

— You are receiving this because you commented. Reply to this email directly, view it on GitHub <

https://github.com/davisking/dlib-models/issues/11?email_source=notifications&email_token=AAAKQ2OQY3ISUSKPO7BLFTDQRIOC5A5CNFSM4GMJTZUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECWEUAY#issuecomment-548162051

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AAAKQ2IQAVDMXCVBUR3ZWQLQRIOC5ANCNFSM4GMJTZUA

.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub < https://github.com/davisking/dlib-models/issues/11?email_source=notifications&email_token=ABPYFR6IRGWI4PNRKTODKX3QRLLFRA5CNFSM4GMJTZUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECXXJLI#issuecomment-548369581 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/ABPYFR3L2HVRKDUDMGM23LLQRLLFRANCNFSM4GMJTZUA

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/davisking/dlib-models/issues/11?email_source=notifications&email_token=AAAKQ2OIPL4XCVLKHUDYJTLQRNVVVA5CNFSM4GMJTZUKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECZS6HQ#issuecomment-548613918, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAKQ2OEDSXHAB65ZNDRVT3QRNVVVANCNFSM4GMJTZUA .

csaftoiu avatar Nov 01 '19 11:11 csaftoiu

You could copy the layer parameters into a network with batch norm layers and go in and manually fill in the missing batch norm parameters with something reasonable.

davisking avatar Nov 03 '19 17:11 davisking

Does anyone build the dlib_face_recognition_resnet_model_v1.dat with custom dataset? If Yes, Please share the method. Thanks in Advance.

ismailpolas avatar Sep 09 '20 10:09 ismailpolas

http://dlib.net/dnn_face_recognition_ex.cpp.html and http://dlib.net/dnn_metric_learning_on_images_ex.cpp.html explain all that.

On Wed, Sep 9, 2020 at 6:06 AM ismailpolas [email protected] wrote:

Does anyone build the dlib_face_recognition_resnet_model_v1.dat with custom dataset? If Yes, Please share the method. Thanks in Advance.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/davisking/dlib-models/issues/11#issuecomment-689463468, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPYFRZ4RB3SAR3D2ZM6KPDSE5HRNANCNFSM4GMJTZUA .

davisking avatar Sep 09 '20 11:09 davisking

I tried Loading a custom dataset and successfully made the resnet .dat file but I'm getting this error. ERROR: Unexpected version found while deserializing dlib::input_rgb_image_sized. Please refer to the issue link given below for more detials on this error. https://github.com/davisking/dlib/issues/2598

aishaandatt avatar Jun 15 '22 19:06 aishaandatt