-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_pretrained_weight.py
51 lines (35 loc) · 1.38 KB
/
get_pretrained_weight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from os import makedirs
from shutil import copyfileobj
import requests
def confirm(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None
def download(id, path):
base_url = 'https://drive.google.com/uc?export=download'
session = requests.Session()
res = session.get(base_url, params={'id': id}, stream=True)
token = confirm(res)
if token:
res = session.get(base_url, params={'id': id, 'confirm': token}, stream=True)
with open(path, 'wb') as f:
MAX_ITER = 10000
for content in res.iter_content(MAX_ITER):
if content:
f.write(content)
if __name__ == '__main__':
dis_id = '1IiPpRQc90rK4vycHnUQIS4rtoKehzB5o'
gen_id = '1Epo89V02NXmyVrzTKtPlWrrHNN-qcOD4'
dest_dir = 'pretrained'
makedirs(dest_dir, exist_ok=True)
dis_path = dest_dir + '/dis.npz'
gen_path = dest_dir + '/gen.npz'
print('[Message] Downloading pre trained weight (usually it may take few minutes)')
#Discriminator
print('[Message] Now downloading Discriminator\'s weight... (about 41MB)')
download(dis_id, dis_path)
#Generator
print('[Message] Now downloading Generator\'s weight... (about 76MB)')
download(gen_id, gen_path)
print('[Message] Successfully')