HSE_FaceRec_tf icon indicating copy to clipboard operation
HSE_FaceRec_tf copied to clipboard

How do I train vggface2 and get my own model?

Open mingrongchen opened this issue 5 years ago • 19 comments

How do I train vggface2 and get my own pre model?

mingrongchen avatar May 31 '19 05:05 mingrongchen

Sorry for delay in answer. My notifications were not enebaled for this repository. I added an old code facerec_keras_train.py to train the baseline model on VGGFace2 dataset. This procedure is straightforward, that's why it was not presented in this repository initially.

av-savchenko avatar Jan 29 '20 10:01 av-savchenko

Hello Can you please specify the procedure for tuning age_gender model?

maria-zafar avatar Oct 06 '21 14:10 maria-zafar

Script age_gender_identity/age_gender_train.py is used to tune the age-gender model. I am not sure that it will work right now with the recent version of Keras. Nevertheless, it is necessary to prepare two folders (age and gender), each of them should contain train and val parts (see code). I simply used concatenation of IMDB-Wiki and Adience datasets. The former has some mistakes for small ages, so that I corrected them manually. The latter contains the age ranges only, so that I used the middle of this range as a ground truth label. Please see details in the paper

av-savchenko avatar Oct 06 '21 14:10 av-savchenko

Script age_gender_identity/age_gender_train.py is used to tune the age-gender model. I am not sure that it will work right now with the recent version of Keras. Nevertheless, it is necessary to prepare two folders (age and gender), each of them should contain train and val parts (see code). I simply used concatenation of IMDB-Wiki and Adience datasets. The former has some mistakes for small ages, so that I corrected them manually. The latter contains the age ranges only, so that I used the middle of this range as a ground truth label. Please see details in the paper

I am trying to do the same but it is showing errors with paths also the 2 folders you are talking about, age and gender must have images in them?

maria-zafar avatar Oct 06 '21 15:10 maria-zafar

Yes, sure, they should contain images, as they are passed to flow_from_directory() method. The errors maybe caused by some incompatibility with versions of Keras, etc. Unfortunately, I do not have enough time now to make this code fully compatible with recent Tensorflow, but I believe you could do it by yourself. It is maybe better if you could share the errors you got

6 окт. 2021 г., в 18:02, maria-zafar @.***> написал(а):

Script age_gender_identity/age_gender_train.py is used to tune the age-gender model. I am not sure that it will work right now with the recent version of Keras. Nevertheless, it is necessary to prepare two folders (age and gender), each of them should contain train and val parts (see code https://github.com/HSE-asavchenko/HSE_FaceRec_tf/blob/master/age_gender_identity/age_gender_train.py#L139). I simply used concatenation of IMDB-Wiki and Adience datasets. The former has some mistakes for small ages, so that I corrected them manually. The latter contains the age ranges only, so that I used the middle of this range as a ground truth label. Please see details in the paper https://peerj.com/articles/cs-197/ I am trying to do the same but it is showing errors with paths also the 2 folders you are talking about, age and gender must have images in them?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HSE-asavchenko/HSE_FaceRec_tf/issues/2#issuecomment-936451789, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZQMVGKYJXD7YPRS4FXUZTUFRQIJANCNFSM4HRTWV7Q. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

av-savchenko avatar Oct 06 '21 15:10 av-savchenko

Can you share your email where I can share the screenshots of error?

maria-zafar avatar Oct 06 '21 15:10 maria-zafar

It will be better if you could copy your screenshots directly here so that other users can take a look at this issues. It is possible to simply drag-n-drop any image into github tracker

av-savchenko avatar Oct 06 '21 15:10 av-savchenko

okay so this is what I am getting

image

maria-zafar avatar Oct 06 '21 15:10 maria-zafar

It simply means that there is no such folder. Check it by running something like !ls content/drive/MyDrive ... If you use Colab, I believe you need to run from google.colab import drive drive.mount('/content/gdrive/')

and then use absolute path /content/gdrive/My Drive/

av-savchenko avatar Oct 06 '21 15:10 av-savchenko

It simply means that there is no such folder. Check it by running something like !ls content/drive/MyDrive ... If you use Colab, I believe you need to run from google.colab import drive drive.mount('/content/gdrive/')

and then use absolute path /content/gdrive/My Drive/

the folder is already there if you notice the command right above %run you'll see I have given the path already

maria-zafar avatar Oct 06 '21 15:10 maria-zafar

image

maria-zafar avatar Oct 06 '21 18:10 maria-zafar

Any suggestions about how to fix this?

maria-zafar avatar Oct 06 '21 18:10 maria-zafar

This is exactly the compatibility issue. Try to change num_class to num_classes at lines 161 and 165.

av-savchenko avatar Oct 06 '21 18:10 av-savchenko

Yes this is working!

maria-zafar avatar Oct 06 '21 19:10 maria-zafar

Okay I have trained the model using age_gender_train.py and it saves models in the model folder in hdf5 extension however, for inference I have to use facial_analysis.py and in that it uses .pb so how do I create that?

maria-zafar avatar Oct 06 '21 20:10 maria-zafar

Just run the same age gender train with arguments --modelpath and path to your hdf5 file. It is still possible that there are some issues with compatibility because Tensorflow 2.x hides many pb-related methods. The same is true for facial_analysis. For example, tf.gfile.GFile should be renamed to tf.io.gfile.GFile

av-savchenko avatar Oct 07 '21 04:10 av-savchenko

yes it is constantly giving error on this. Any suggestions how to fix this tried changing versions, did with tfand keras oalone but it is not getting fixed

image

maria-zafar avatar Oct 08 '21 04:10 maria-zafar

Input class is located in tensorflow.keras ( https://www.tensorflow.org/api_docs/python/tf/keras/Input). However, this is a general part of the code. I wonder why you did not see the same error while training the model.

пт, 8 окт. 2021 г. в 07:12, maria-zafar @.***>:

yes it is constantly giving error on this. Any suggestions how to fix this tried changing versions, did with tfand keras oalone but it is not getting fixed

[image: image] https://user-images.githubusercontent.com/69984290/136497101-e03aadd0-f671-4d2c-b94f-7aed8d861e7c.png

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/HSE-asavchenko/HSE_FaceRec_tf/issues/2#issuecomment-938328127, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZQMVHVDIQMND7SP4A25JDUFZVRNANCNFSM4HRTWV7Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- С уважением, А.В. Савченко

av-savchenko avatar Oct 08 '21 05:10 av-savchenko

Input class is located in tensorflow.keras ( https://www.tensorflow.org/api_docs/python/tf/keras/Input). However, this is a general part of the code. I wonder why you did not see the same error while training the model. пт, 8 окт. 2021 г. в 07:12, maria-zafar @.***>: yes it is constantly giving error on this. Any suggestions how to fix this tried changing versions, did with tfand keras oalone but it is not getting fixed [image: image] https://user-images.githubusercontent.com/69984290/136497101-e03aadd0-f671-4d2c-b94f-7aed8d861e7c.png — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#2 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFZQMVHVDIQMND7SP4A25JDUFZVRNANCNFSM4HRTWV7Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. -- С уважением, А.В. Савченко

Basically it gives an error when the function convert_to_tf() is called in age-gender-train.py. So at first I was training without giving modelpath and it saved the models in .hdf5 only but with path I guess it shall save the model in .pb.

maria-zafar avatar Oct 08 '21 05:10 maria-zafar