minchul commited on
Commit
f4a7259
·
verified ·
1 Parent(s): 1815847

Upload directory

Browse files
Files changed (1) hide show
  1. README.md +79 -0
README.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ arxiv: 1801.07698
5
+ ---
6
+
7
+ <div align="center">
8
+ <h1>
9
+ CVLFace Pretrained Model (ARCFACE IR101 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: ARCFACE IR101 WEBFACE4M
25
+
26
+ Related Paper: ArcFace: Additive Angular Margin Loss for Deep Face Recognition (https://arxiv.org/abs/1801.07698)
27
+
28
+ Please cite the orignal paper and 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
+ HF_TOKEN = 'YOUR_HUGGINGFACE_TOKEN'
73
+ path = 'path/to/store/model/locally'
74
+ repo_id = 'minchul/cvlface_arcface_ir101_webface4m'
75
+ model = load_model_by_repo_id(repo_id, path, HF_TOKEN)
76
+ input = torch.randn(1, 3, 112, 112)
77
+ out = model(input)
78
+ ```
79
+