-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpytables_read_test.py
More file actions
211 lines (177 loc) · 7.53 KB
/
Copy pathpytables_read_test.py
File metadata and controls
211 lines (177 loc) · 7.53 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
from __future__ import division
#from ipdb import set_trace as dbg
import tables
import time as t
import numpy as np
import sys
import os
from os.path import join
from itertools import izip
def print_result(start_time, inp, out, read):
print "\t#{0} Read#".format(read)
print "\tRead {1} bytes in {0:.2f}sec.".format(t.time() - start_time, sys.getsizeof(inp) + sys.getsizeof(out))
start_time = t.time()
print "\tSummed to {0} in {1:.2f}sec.\n".format(np.sum(inp) + np.sum(out), t.time() - start_time)
def read_test_zero_group_one_element_mnist(filename, index, filters=None):
print filename
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = f.root.raw.input.read()
out = f.root.raw.output.read()
print_result(start_time, inp, out, "In RAM")
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = []
out = []
for i, o in izip(f.root.raw.input, f.root.raw.output):
inp.append(i)
out.append(o)
print_result(start_time, inp, out, "Seq")
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = []
out = []
for i, o in izip(f.root.raw.input.iterrows(), f.root.raw.output.iterrows()):
inp.append(i)
out.append(o)
print_result(start_time, inp, out, "Seq - Iter")
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = []
out = []
A = f.root.raw.input
B = f.root.raw.output
for i in index:
inp.append(A[i])
out.append(B[i])
print_result(start_time, inp, out, "Random")
def read_test_one_group_multiple_element_mnist(filename, index, filters=None):
print filename
start_time = t.time()
with tables.open_file(filename, mode='r', filters=filters) as f:
print t.time() - start_time
inp = []
out = []
for i, o in izip(f.iter_nodes(f.root.raw.input), f.iter_nodes(f.root.raw.output)):
inp.append(i.read())
out.append(o.read())
print_result(start_time, inp, out, "Seq - Iter")
# with tables.open_file(filename, mode='r') as f:
# start_time = t.time()
# inp = []
# out = []
# for i, o in izip(f.iter_nodes(f.root.raw.input), f.iter_nodes(f.root.raw.output)):
# inp.append(i)
# out.append(o)
# print_result(start_time, inp, out, "SeqIter - Lazy")
start_time = t.time()
with tables.open_file(filename, mode='r', filters=filters) as f:
print t.time() - start_time
inp = []
out = []
for i, o in izip(f.walk_nodes(f.root.raw.input, 'Leaf'), f.walk_nodes(f.root.raw.output, 'Leaf')):
inp.append(i.read())
out.append(o.read())
print_result(start_time, inp, out, "Seq - Walk")
# with tables.open_file(filename, mode='r') as f:
# start_time = t.time()
# inp = []
# out = []
# for i in index:
# inp.append(f.get_node(f.root.raw.input, "m_{0}_0".format(i)).read())
# out.append(f.get_node(f.root.raw.output, "t_{0}_0".format(i)).read())
# print_result(start_time, inp, out, "Random - w/ natural naming")
start_time = t.time()
with tables.open_file(filename, mode='r', filters=filters) as f:
print t.time() - start_time
inp = []
out = []
A = f.root.raw.input
B = f.root.raw.output
for i in index:
inp.append(f.get_node(A, "m_{0}_0".format(i)).read())
out.append(f.get_node(B, "t_{0}_0".format(i)).read())
print_result(start_time, inp, out, "Random")
def read_test_mutiple_group_one_element_mnist(filename, index, filters=None):
print filename
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = []
out = []
for i, o in izip(f.root.raw.input, f.root.raw.output):
for i2, o2 in izip(i, o):
inp.append(i2.read())
out.append(o2.read())
print_result(start_time, inp, out, "Seq")
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = []
out = []
A = f.root.raw.input
B = f.root.raw.output
for i in xrange(A._v_nchildren):
inp.append(f.get_node(A, "example{0}/m_{0}_0".format(i)).read())
out.append(f.get_node(B, "target{0}/t_{0}_0".format(i)).read())
print_result(start_time, inp, out, "Seq - Naming")
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = []
out = []
for i, o in izip(f.iter_nodes(f.root.raw.input), f.iter_nodes(f.root.raw.output)):
for i2, o2 in izip(f.iter_nodes(i), f.iter_nodes(o)):
inp.append(i2.read())
out.append(o2.read())
print_result(start_time, inp, out, "Seq - Iter")
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = []
out = []
for i, o in izip(f.walk_nodes(f.root.raw.input, 'Leaf'), f.walk_nodes(f.root.raw.output, 'Leaf')):
inp.append(i.read())
out.append(o.read())
print_result(start_time, inp, out, "Seq - Walk")
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = []
out = []
A = f.root.raw.input
B = f.root.raw.output
for i in index:
inp.append(f.get_node(A, "example{0}/m_{0}_0".format(i)).read())
out.append(f.get_node(B, "target{0}/t_{0}_0".format(i)).read())
print_result(start_time, inp, out, "Random")
with tables.open_file(filename, mode='r', filters=filters) as f:
start_time = t.time()
inp = []
out = []
for i in index:
inp.append(f.get_node("/raw/input/example{0}/m_{0}_0".format(i)).read())
out.append(f.get_node("/raw/output/target{0}/t_{0}_0".format(i)).read())
print_result(start_time, inp, out, "Random - Full naming")
if __name__ == "__main__":
path = sys.argv[1] if len(sys.argv) > 1 else '.'
dataset_size = 70000
index = np.random.permutation(dataset_size)
already_completed = []
if os.path.isfile(join(path, 'done.txt')):
already_completed = open(join(path, 'done.txt')).read().split()
completed_file = open(join(path, 'done.txt'), 'a')
filenames = [f for f in os.listdir(path) if f.endswith('.h5')]
filenames = [f for f in filenames if not f in already_completed]
filenames = [f for f in filenames if not 'gzip' in f]
filenames = [f for f in filenames if not 'lzf' in f]
for f in filenames:
filters = None
if 'blosc' in f:
filters = tables.filters.Filters(complevel=9, complib='blosc')
elif 'zlib' in f:
filters = tables.filters.Filters(complevel=9, complib='zlib')
elif 'bzip2' in f:
filters = tables.filters.Filters(complevel=9, complib='bzip2')
if 'zero_group_one_element' in f:
read_test_zero_group_one_element_mnist(f, index, filters)
elif 'one_group_multiple_element' in f:
read_test_one_group_multiple_element_mnist(f, index, filters)
elif 'mutiple_group_one_element' in f:
read_test_mutiple_group_one_element_mnist(f, index, filters)
completed_file.write(f + "\n")