-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateTrainingsDatasets.py
162 lines (131 loc) · 8.75 KB
/
createTrainingsDatasets.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"""Creates training datasets with all training data in one array for a given Szene"""
import numpy as np
import tensorflow as tf
import trainModel
SEQUENCE_LENGTH = 5
NUM_DIMENSIONS = 2
NUM_PARTICLE_TYPES = 2
NUM_STOPPER = 4
NUM_PATRICLES_PER_STOPPER = 40
NUM_BOUNDARY_PARTICLES = NUM_PATRICLES_PER_STOPPER*NUM_STOPPER
NUM_CARGO_PARTICLES = 35
EVERY_N = 4
DATA_PATH = "Data/Numpy/Szene1"
def main():
"""Create dataset for given Szene"""
train_examples = np.empty(shape=(1,SEQUENCE_LENGTH+1,NUM_BOUNDARY_PARTICLES+NUM_CARGO_PARTICLES,NUM_DIMENSIONS),dtype=np.float32)
train_labels = np.empty(shape=(1,NUM_BOUNDARY_PARTICLES+NUM_CARGO_PARTICLES,NUM_DIMENSIONS),dtype=np.float32)
train_examples, train_labels = getTrainingDatasetsSzene1(train_examples, train_labels)
# Convert datasets to tf Tensors of the desired shape
train_examples = train_examples.transpose([0,2,1,3])
n = (open(DATA_PATH + '/' + "TrainingDataLabels" + '.npy', 'wb'))
np.save(n, train_labels)
n = (open(DATA_PATH + '/' + "TrainingDataExamples" + '.npy', 'wb'))
np.save(n, train_examples)
def getTrainingDatasetsSzene1(train_examples, train_labels):
""" Read all training datasets for Szene1
Args:
train_examples: emtpy array with correct shape to write examples to
train_labels: emtpy array with correct shape to write labels to
Returns:
train_examples: array with all examples
train_labels: array with all labels
"""
# loop through all datasets
for angle1_deg in range(31):
angle1=(angle1_deg+30)*np.pi/180
# add positions of stopper-elements
obstacle_positions = np.empty(shape=(1,NUM_DIMENSIONS))
for i in np.linspace(-10,10,NUM_PATRICLES_PER_STOPPER):
obstacle_positions = np.vstack((obstacle_positions,[0.24+np.cos(angle1)*0.35*i/10, 1.47+np.sin(angle1)*0.35*i/10]))
obstacle_positions = obstacle_positions[1:]
# loop through all starting positions
for version in [1,2,3]:
if(not(angle1_deg==30 and version==1) or (angle1_deg==33 and version==2) or (angle1_deg==37 and version==3) or (angle1_deg==41 and version==1) or (angle1_deg==45 and version==2) or (angle1_deg==49 and version==3) or (angle1_deg==53 and version==1) or (angle1_deg==57 and version==2) or (angle1_deg==60 and version==3)):
filename = str(angle1_deg+30) + '_' + str(version)
print(filename)
with open(DATA_PATH+'/'+filename + '.npy', 'rb') as f:
datanpy = np.load(f)
data = trainModel.readData(datanpy, NUM_CARGO_PARTICLES)
k = EVERY_N #take every k-th position of dataset
# loop through all positions
for i in range(int((len(data))-7*k)):
train_data = np.vstack((np.hstack((data[[i],:],obstacle_positions[None])),np.hstack((data[[i+k],:],obstacle_positions[None])),np.hstack((data[[i+2*k],:],obstacle_positions[None])),np.hstack((data[[i+3*k],:],obstacle_positions[None])),np.hstack((data[[i+4*k],:],obstacle_positions[None])),np.hstack((data[[i+5*k],:],obstacle_positions[None]))))
train_examples = np.vstack((train_examples,train_data[None]))
train_labels = np.vstack((train_labels,np.hstack((data[[i+6*k],:],obstacle_positions[None]))))
return train_examples, train_labels
def getTrainingDatasetsSzene2(train_examples, train_labels):
""" Read all training datasets for Szene2
Args:
train_examples: emtpy array with correct shape to write examples to
train_labels: emtpy array with correct shape to write labels to
Returns:
train_examples: array with all examples
train_labels: array with all labels
"""
# loop through all datasets
for angle1_deg in range(31):
angle1=(angle1_deg+30)*np.pi/180
# add positions of stopper-elements
obstacle_positions = np.empty(shape=(1,NUM_DIMENSIONS))
for i in np.linspace(-10,10,NUM_PATRICLES_PER_STOPPER):
obstacle_positions = np.vstack((obstacle_positions,[0.24+np.cos(angle1)*0.35*i/10, 1.47+np.sin(angle1)*0.35*i/10]))
for i in np.linspace(0,1,NUM_PATRICLES_PER_STOPPER):
obstacle_positions = np.vstack((obstacle_positions,[i, 3]))
obstacle_positions = obstacle_positions[1:]
# loop throug all starting positions
for version in [1,2,3]:
if(not(angle1_deg==30 and version==1) or (angle1_deg==33 and version==2) or (angle1_deg==37 and version==3) or (angle1_deg==41 and version==1) or (angle1_deg==45 and version==2) or (angle1_deg==49 and version==3) or (angle1_deg==53 and version==1) or (angle1_deg==57 and version==2) or (angle1_deg==60 and version==3)):
filename = str(angle1_deg+30) + '_' + str(version)
print(filename)
with open(DATA_PATH+'/'+filename + '_9.npy', 'rb') as f:
datanpy = np.load(f)
data = trainModel.readData(datanpy, NUM_CARGO_PARTICLES)
k = EVERY_N #take every k-th position of dataset
# loop through all positions
for i in range(int((len(data))-7*k)):
train_data = np.vstack((np.hstack((data[[i],:],obstacle_positions[None])),np.hstack((data[[i+k],:],obstacle_positions[None])),np.hstack((data[[i+2*k],:],obstacle_positions[None])),np.hstack((data[[i+3*k],:],obstacle_positions[None])),np.hstack((data[[i+4*k],:],obstacle_positions[None])),np.hstack((data[[i+5*k],:],obstacle_positions[None]))))
train_examples = np.vstack((train_examples,train_data[None]))
train_labels = np.vstack((train_labels,np.hstack((data[[i+6*k],:],obstacle_positions[None]))))
return train_examples, train_labels
def getTrainingDatasetsSzene3(train_examples, train_labels):
""" Read all training datasets for Szene3
Args:
train_examples: emtpy array with correct shape to write examples to
train_labels: emtpy array with correct shape to write labels to
Returns:
train_examples: array with all examples
train_labels: array with all labels
"""
# loop through all datasets
for angle1_deg in range(7):
angle1=(angle1_deg*5+30)*np.pi/180
for angle2_deg in range(4):
angle2=(angle2_deg*5+45)*np.pi/180
# add positions of stopper-elements
obstacle_positions = np.empty(shape=(1,NUM_DIMENSIONS))
for i in np.linspace(-10,10,NUM_PATRICLES_PER_STOPPER):
obstacle_positions = np.vstack((obstacle_positions,[0.24+np.cos(angle1)*0.35*i/10, 1.47+np.sin(angle1)*0.35*i/10]))
for i in np.linspace(-10,10,NUM_PATRICLES_PER_STOPPER):
obstacle_positions = np.vstack((obstacle_positions,[0.65+np.cos(-angle2)*0.5*i/10, 3+np.sin(-angle2)*0.5*i/10]))
for i in np.linspace(0,1,NUM_PATRICLES_PER_STOPPER):
obstacle_positions = np.vstack((obstacle_positions,[i, 6]))
obstacle_positions = obstacle_positions[1:]
# loop throug all starting positions
for version in [2]:
if(not(angle1_deg==30 and angle2_deg == 45 and version==1) or (angle1_deg==30 and angle2_deg == 60 and version==2) or (angle1_deg==35 and angle2_deg == 50 and version==3) or (angle1_deg==40 and angle2_deg == 55 and version==1) or (angle1_deg==40 and angle2_deg == 45 and version==2) or (angle1_deg==45 and angle2_deg == 60 and version==3) or (angle1_deg==50 and angle2_deg == 50 and version==1) or (angle1_deg==55 and angle2_deg == 45 and version==2) or (angle1_deg==60 and angle2_deg == 55 and version==3)):
filename = str(angle1_deg*5+30) + '_' + str(angle2_deg*5+45) + '_' + str(version)
print(filename)
with open(DATA_PATH+'/'+filename + '_9.npy', 'rb') as f:
datanpy = np.load(f)
data = trainModel.readData(datanpy, NUM_CARGO_PARTICLES)
k = EVERY_N #take every k-th position of dataset
# loop through all positions
for i in range(int((len(data))-7*k)):
train_data = np.vstack((np.hstack((data[[i],:],obstacle_positions[None])),np.hstack((data[[i+k],:],obstacle_positions[None])),np.hstack((data[[i+2*k],:],obstacle_positions[None])),np.hstack((data[[i+3*k],:],obstacle_positions[None])),np.hstack((data[[i+4*k],:],obstacle_positions[None])),np.hstack((data[[i+5*k],:],obstacle_positions[None]))))
train_examples = np.vstack((train_examples,train_data[None]))
train_labels = np.vstack((train_labels,np.hstack((data[[i+6*k],:],obstacle_positions[None]))))
return train_examples, train_labels
if __name__ == "__main__":
tf.disable_v2_behavior()
main()