-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathdownload.py
More file actions
59 lines (47 loc) · 1.81 KB
/
download.py
File metadata and controls
59 lines (47 loc) · 1.81 KB
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
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
from __future__ import print_function, division
import argparse
from os.path import join
import subprocess
from urllib.request import Request, urlopen
__author__ = 'Fisher Yu'
__email__ = 'fy@cs.princeton.edu'
__license__ = 'MIT'
def list_categories():
url = 'http://dl.yf.io/lsun/categories.txt'
with urlopen(Request(url)) as response:
return response.read().decode().strip().split('\n')
def download(out_dir, category, set_name):
url = 'http://dl.yf.io/lsun/scenes/{category}_' \
'{set_name}_lmdb.zip'.format(**locals())
if set_name == 'test':
out_name = 'test_lmdb.zip'
url = 'http://dl.yf.io/lsun/scenes/{set_name}_lmdb.zip'
else:
out_name = '{category}_{set_name}_lmdb.zip'.format(**locals())
out_path = join(out_dir, out_name)
cmd = ['curl', '-C', '-', url, '-o', out_path]
print('Downloading', category, set_name, 'set')
subprocess.call(cmd)
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--out_dir', default='')
parser.add_argument('-c', '--category', default=None)
args = parser.parse_args()
categories = list_categories()
if args.category is None:
print('Downloading', len(categories), 'categories')
for category in categories:
download(args.out_dir, category, 'train')
download(args.out_dir, category, 'val')
download(args.out_dir, '', 'test')
else:
if args.category == 'test':
download(args.out_dir, '', 'test')
elif args.category not in categories:
print('Error:', args.category, "doesn't exist in", 'LSUN release')
else:
download(args.out_dir, args.category, 'train')
download(args.out_dir, args.category, 'val')
if __name__ == '__main__':
main()