-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflip_data.py
143 lines (91 loc) · 3.2 KB
/
flip_data.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
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
import argparse
import h5py
import progressbar
import numpy as np
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Rover HDF5 Concatenator')
parser.add_argument('--dataset', type=str, default='output.h5')
parser.add_argument('--output', type=str, default='output_flipped.h5')
args = parser.parse_args()
dataset = args.dataset
output = args.output
print '-' * 20
print dataset
print output
hdf5_file = h5py.File(dataset, 'r')
xs = hdf5_file['x_dataset']
ys = hdf5_file['y_dataset']
dataset_length = len(xs)
output_file = h5py.File(output, 'a')
output_dataset_length = dataset_length * 2
output_xs = output_file.create_dataset('x_dataset', (output_dataset_length, 240, 320, 3), dtype='int8')
output_ys = output_file.create_dataset('y_dataset', (output_dataset_length, 1), dtype='f8')
progress = progressbar.ProgressBar(maxval=output_dataset_length)
progress.start()
instance = 0
for i in range(dataset_length):
output_xs[instance] = xs[i]
output_ys[instance] = ys[i]
instance += 1
progress.update(instance)
for j in range(dataset_length):
output_xs[instance] = np.fliplr(xs[j])
output_ys[instance] = ys[j] * -1
instance += 1
progress.update(instance)
progress.finish()
# f = h5py.File('output_lowprecision.h5','a')
# images = f['x_dataset']
# angles = f['y_dataset']
# # distinct_values = {}
# # for i in range(len(angles)):
# # angle = angles[i][0]
# # if angle in distinct_values:
# # distinct_values[angle] += 1
# # else:
# # distinct_values[angle] = 0
# # count = 0
# # for i in range(len(angles)):
# # angle = angles[i][0]
# # if angle < 0.01 and angle > -0.01:
# # count+=1
# # print count
# first_image = np.fliplr(images[0])
# first_images = np.array([first_image])
# x_flipped = f.create_dataset('x_flipped',data=first_images, maxshape=(None, 240, 320, 3))
# for i in range(1, len(images)):
# image = images[i]
# new_image = np.fliplr(image)
# new_size = x_flipped.shape[0] + 1
# x_flipped.resize((new_size, 240, 320, 3))
# x_flipped[new_size - 1] = new_image
# first_angle = angles[0] * -1
# first_angles = np.array([first_angle])
# y_flipped = f.create_dataset('y_flipped',data=first_angles, maxshape=(None, 1))
# for i in range(1, len(angles)):
# new_angle = angles[i] * -1
# new_size = y_flipped.shape[0] + 1
# y_flipped.resize((new_size, 1))
# y_flipped[new_size - 1] = new_angle
# # print("Starting")
# # x_combined = f.create_dataset('x_combined',data=images, maxshape=(None, 240, 320, 3))
# # y_combined = f.create_dataset('y_combined',data=angles, maxshape=(None, 1))
# # print("Copy completed..")
# # x_flipped = f['x_flipped']
# # y_flipped = f['y_flipped']
# # for i in range(len(x_flipped)):
# # image = x_flipped[i]
# # new_size = x_combined.shape[0] + 1
# # x_combined.resize((new_size, 240, 320, 3))
# # x_combined[new_size - 1] = image
# # if i % 10000 == 0:
# # print("Images", i, "of 141746")
# # print("Images done")
# # for i in range(len(y_flipped)):
# # angle = y_flipped[i]
# # new_size = y_combined.shape[0] + 1
# # y_combined.resize((new_size, 1))
# # y_combined[new_size - 1] = angle
# # if i % 10000 == 0:
# # print("Angles", i, "of 141746")
# # print("Angles done")