Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to setup the pretrained model locally? #50

Closed
flydragon2018 opened this issue Dec 31, 2019 · 7 comments
Closed

how to setup the pretrained model locally? #50

flydragon2018 opened this issue Dec 31, 2019 · 7 comments

Comments

@flydragon2018
Copy link

since the internet is too slow to download and frequently disconnected.

I could get the pretained model files some other way.

so how should I set it up locally?

Thank you!

@timesler
Copy link
Owner

The pretrained weights should only need to be downloaded once, the first time you create a pretrained model. After that, they should be stored in the torch cache locally, so nothing needs to be downloaded subsequent times.

However, if the model caching isn't working for you for some reason, the pretrained weights can be downloaded from the links in the table in the repo readme.

@flydragon2018
Copy link
Author

Thank you for your reply.
due to internet problem, I can not download it any ONCE !!!!!!!!
however I could get a copied version by email or usb etc.

so what is the local cached model file setup ?????

@flydragon2018
Copy link
Author

in other words, which directory should I put these *.pt files in locally?

@timesler
Copy link
Owner

timesler commented Dec 31, 2019

The location of the pytorch model cache is different for different systems. It's easiest to just load the state dictionaries into the model in the standard pytorch way.

You can loaded the pretrained weights using:

from facenet_pytorch import InceptionResnetV1

# For VGGFace2 pretrained weights:
model = InceptionResnetV1(num_classes=8631)
model.load_state_dict(torch.load('<path to .pt file>'))

# For CASIA-webface pretrained weights:
model = InceptionResnetV1(num_classes=10575)
model.load_state_dict(torch.load('<path to .pt file>'))

@timesler
Copy link
Owner

timesler commented Dec 31, 2019

If you want to use the pytorch model cache, you will have to download the weights in their split form (they are downloaded in parts).

For VGGFace2, download the following files:
https://drive.google.com/uc?export=download&id=1cWLH_hPns8kSfMz9kKl9PsG5aNV2VSMn
https://drive.google.com/uc?export=download&id=1mAie3nzZeno9UIzFXvmVZrDG3kwML46X
rename them to vggface2_G5aNV2VSMn.pt and vggface2_DG3kwML46X.pt, respectively.

For CASIA-webface, download the following files:
https://drive.google.com/uc?export=download&id=1LSHHee_IQj5W3vjBcRyVaALv4py1XaGy
https://drive.google.com/uc?export=download&id=1QrhPgn1bGlDxAil2uc07ctunCQoDnCzT
rename them to vggface2_Lv4py1XaGy.pt and vggface2_unCQoDnCzT.pt, respectively.

Copy those files into the directory returned by the following shell command:

echo $(python -c "from facenet_pytorch.models.inception_resnet_v1 import get_torch_home; print(get_torch_home())")/checkpoints

@flydragon2018
Copy link
Author

flydragon2018 commented Dec 31, 2019

thank you. the changing names in your reply works for examples\infer.ipynb.

****Could you please explain the reason why the pt files were renamed that way?

originally I just put the .pt files in the right pathto\checkpoints, however it keeps trying to
download the files from internet.

Thank you very much.****

@timesler
Copy link
Owner

timesler commented Jan 4, 2020

The files are named that way so that the data can be versioned. The last 10 characters on the file names are taken from the unique hash generated by Google Drive.

@timesler timesler closed this as completed Jan 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants