forked from wbond/package_control
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport-4.log
61 lines (46 loc) · 1.75 KB
/
import-4.log
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
60
61
import os
import imageio
import numpy as np
def quickdraw_npy_to_imagefile(inpath, outpath, filetype='png', subset=None):
"""
Creates a folder with subfolders for each image class
from the Quickdraw dataset (https://quickdraw.withgoogle.com)
downloaded in .npy format.
To download the .npy formatted dataset:
gsutil -m cp gs://quickdraw_dataset/full/numpy_bitmap/*.npy quickdraw-png
Usage example:
quickdraw_npy_to_imagefile('quickdraw-npy', 'quickdraw-png')
Parameters
----------
inpath : str
string specifying the path to the input directory containing
the .npy files
outpath : str
string specifying the path for the output images
subset : tuple or list (default=None)
A subset of categories to consider. E.g.
`("lollipop", "binoculars", "mouse", "basket")`
"""
if not os.path.exists(outpath):
os.mkdir(outpath)
npy_list = [i for i in os.listdir(inpath) if i.endswith('.npy')]
if subset:
npy_list = [i for i in npy_list if i.split('.npy')[0] in subset]
if not len(npy_list):
raise ValueError('No .npy files found in %s' % inpath)
npy_paths = [os.path.join(inpath, i) for i in npy_list]
for i, j in zip(npy_list, npy_paths):
label = (i.split('-')[-1]).split('.npy')[0]
folder = os.path.join(outpath, label)
if not os.path.exists(folder):
os.mkdir(folder)
X = np.load(j)
cnt = 0
for row in X:
img_array = row.reshape(28, 28)
assert cnt < 1000000
outfile = os.path.join(folder, '%s_%06d.%s' % (
label, cnt, filetype))
imageio.imwrite(outfile,
img_array[:, :])
cnt += 1