minchul commited on
Commit
ba58d56
1 Parent(s): 16a121b

Upload directory

Browse files
Files changed (1) hide show
  1. README.md +89 -0
README.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ arxiv: 2403.14852
5
+ ---
6
+
7
+ <div align="center">
8
+ <h1>
9
+ CVLFace Pretrained Model (ADAFACE VIT BASE KPRPE WEBFACE4M)
10
+ </h1>
11
+ </div>
12
+
13
+
14
+ <p align="center">
15
+ 🌎 <a href="https://github.com/mk-minchul/CVLface" target="_blank">GitHub</a> • 🤗 <a href="https://huggingface.co/minchul" target="_blank">Hugging Face</a>
16
+ </p>
17
+
18
+
19
+ -----
20
+
21
+
22
+ ## 1. Introduction
23
+
24
+ Model Name: ADAFACE VIT BASE KPRPE WEBFACE4M
25
+
26
+ Related Paper: KeyPoint Relative Position Encoding for Face Recognition (https://arxiv.org/abs/2403.14852)
27
+
28
+ Please cite the orignal paper and follow the license of the training dataset.
29
+
30
+ ## 2. Quick Start
31
+
32
+ ```python
33
+ from transformers import AutoModel
34
+ from huggingface_hub import hf_hub_download
35
+ import shutil
36
+ import os
37
+ import torch
38
+
39
+
40
+ # helpfer function to download huggingface repo and use model
41
+ def download(repo_id, path, HF_TOKEN=None):
42
+ files_path = os.path.join(path, 'files.txt')
43
+ if not os.path.exists(files_path):
44
+ hf_hub_download(repo_id, 'files.txt', token=HF_TOKEN, local_dir=path, local_dir_use_symlinks=False)
45
+ with open(os.path.join(path, 'files.txt'), 'r') as f:
46
+ files = f.read().split('\n')
47
+ for file in [f for f in files if f] + ['config.json', 'wrapper.py', 'model.safetensors']:
48
+ full_path = os.path.join(path, file)
49
+ if not os.path.exists(full_path):
50
+ hf_hub_download(repo_id, file, token=HF_TOKEN, local_dir=path, local_dir_use_symlinks=False)
51
+
52
+
53
+ # helpfer function to download huggingface repo and use model
54
+ def load_model_from_local_path(path, HF_TOKEN=None):
55
+ cwd = os.getcwd()
56
+ os.chdir(path)
57
+ model = AutoModel.from_pretrained(path, trust_remote_code=True, token=HF_TOKEN)
58
+ os.chdir(cwd)
59
+ return model
60
+
61
+
62
+ # helpfer function to download huggingface repo and use model
63
+ def load_model_by_repo_id(repo_id, save_path, HF_TOKEN=None, force_download=False):
64
+ if force_download:
65
+ if os.path.exists(save_path):
66
+ shutil.rmtree(save_path)
67
+ download(repo_id, save_path, HF_TOKEN)
68
+ return load_model_from_local_path(save_path, HF_TOKEN)
69
+
70
+
71
+ if __name__ == '__main__':
72
+
73
+ HF_TOKEN = 'YOUR_HUGGINGFACE_TOKEN'
74
+ path = 'path/to/store/model/locally'
75
+ repo_id = 'minchul/cvlface_adaface_vit_base_kprpe_webface4m'
76
+ model = load_model_by_repo_id(repo_id, path, HF_TOKEN)
77
+
78
+ # input is a rgb image normalized.
79
+ from torchvision.transforms import Compose, ToTensor, Normalize
80
+ from PIL import Image
81
+ img = Image.open('path/to/image.jpg')
82
+ trans = Compose([ToTensor(), Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])])
83
+ input = trans(img).unsqueeze(0) # torch.randn(1, 3, 112, 112)
84
+
85
+ # KPRPE also takes keypoints locations as input
86
+ keypoints = torch.randn(1, 5, 2)
87
+ out = model(input, keypoints)
88
+ ```
89
+