-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_data_gen.py
104 lines (86 loc) · 3.34 KB
/
test_data_gen.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
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
## Test LMDB data
import lmdb
import numpy as np
for x in ('labels', 'frames'):
for y in ('test', 'train'):
for i in xrange(4):
db = '%s_%s_%d' % (x, y, i)
if lmdb.open(db).stat()['entries'] > 0:
print db, lmdb.open(db).stat()['entries']
offsets = np.load('offsets.npz')['offsets']
match = True
for i in xrange(4):
with lmdb.open('labels_test_%d' % i).begin() as txn:
for k, v in txn.cursor():
match = (match and int(v) == int(offsets[int(k)]))
print match
frames_correct = True
for i in xrange(4):
with lmdb.open('frames_test_%d' % i).begin() as txn, \
lmdb.open('labels_test_%d' % i).begin() as labels_txn:
for x in xrange(i * 25, (i + 1) * 25):
key = str(x)
arr = np.fromstring(txn.get(key)).reshape(180, 240, 20)
offset = int(labels_txn.get(key))
frames_correct = frames_correct and np.all(arr[:, :, offset - 1:10] == arr[:, :, 10:10 + (10 - (offset - 1))])
frames_correct = frames_correct and np.all(arr[:, :, 10 + (10 - (offset - 1)):] == 0)
print frames_correct
def view_side_by_side_lmdb():
from matplotlib import pyplot as plt
ax = []
with lmdb.open('frames_test_0').begin() as txn, \
lmdb.open('labels_test_0').begin() as labels_txn:
for u in xrange(25):
offset = labels_txn.get(str(u))
arr = np.fromstring(txn.get(str(u))).reshape(180, 240, 20)
for v in xrange(10):
ax.append(plt.subplot(2, 10, v + 1))
plt.imshow(arr[:, :, v], cmap='gray')
for y in xrange(10):
ax.append(plt.subplot(2, 10, 10 + y + 1))
plt.imshow(arr[:, :, 10 + y], cmap='gray')
for a in ax:
a.set_xticklabels([])
a.set_yticklabels([])
a.set_aspect('equal')
print 'running for key: %d, with offset %s. It matches actual data: %r' % (u, offset, int(offset) == int(offsets[u]))
plt.subplots_adjust(wspace=0, hspace=0)
plt.show()
## Test HDF5 data
import numpy as np
import h5py
local = '/Users/nicholasmoschopoulos/Documents/Classes/Semester8/CS280/project/data/clipped/hitch_hiker/offsets.npz'
ec2 = '/mnt/data/clipped/hitch_hiker/offsets.npz'
offsets = np.load(ec2)['offsets']
match = True
for i in xrange(100):
with h5py.File('frame-%06d.h5' % i, 'r') as hf:
d = np.array(hf.get('label'))
match = (match and int(d[0, 0, 0, 0]) == int(offsets[i]))
print match
frames_correct = True
for i in xrange(100):
with h5py.File('frame-%06d.h5' % i, 'r') as hf:
left_arr = np.array(hf.get('left'))
right_arr = np.array(hf.get('right'))
offset = int(offsets[i])
frames_correct = frames_correct and np.all(left_arr[0, offset - 1:10, :, :] == right_arr[0, :10 - (offset - 1), :, :])
frames_correct = frames_correct and np.all(right_arr[0, 10 - (offset - 1):, :, :] == 0)
print frames_correct
def view_side_by_side_hdf5():
from matplotlib import pyplot as plt
ax = []
with h5py.File('frame-000000.h5', 'r') as hf:
offset = np.array(hf.get('label'))[0, 0, 0, 0]
left_ims = np.array(hf.get('left'))
right_ims = np.array(hf.get('right'))
for v in xrange(10):
ax.append(plt.subplot(2, 10, v + 1))
plt.imshow(left_ims[:, :, v], cmap='gray')
ax.append(plt.subplot(2, 10, 10 + v + 1))
plt.imshow(right_ims[:, :, v], cmap='gray')
for a in ax:
a.set_xticklabels([])
a.set_yticklabels([])
plt.subplots_adjust(wspace=0, hspace=0)
plt.show()