-
Notifications
You must be signed in to change notification settings - Fork 1
/
Spare Parts.py
191 lines (180 loc) · 7.69 KB
/
Spare Parts.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
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
def convert128(testSkel):
global y, nSkel, nLabel
y = int(skel.shape[0]/64)-2
nSkel = np.empty([y, 128, 17, 2])
nLabel = np.empty([y, 1])
for i in range(0, y):
nSkel[i] = skel[(i*64):(i*64)+128,:,:]
nLabel[i] = int(st.mode(label.flatten()[(i*64):(i*64)+128]))
print(f'Skeleton data shape: {nSkel.shape}')
print(f'Label data shape: {nLabel.shape}')
def convert64(testSkel, testLabel, spSkel, spLabel):
global y, nSkel, nLabel
c=0
print("=======================================================")
print(f'original skel shape: {testSkel.shape}')
print(f'original label shape: {testLabel.shape}')
nSkel = 0
nLabel = 0
while testSkel.shape[0]%64 != 0:
testSkel = np.delete(testSkel, -1, axis=0)
testLabel = np.delete(testLabel, -1, axis = 0)
c += 1
y = int(testSkel.shape[0]/32)-1
nSkel = np.empty([y, 64, 12, 2])
nLabel = np.empty([y, 1])
for i in range(0, y):
nSkel[i] = testSkel[(i*32):(i*32)+64,:,:]
nLabel[i] = int(st.median(testLabel.flatten()[(i*32):(i*32)+64]))
nSkel = nSkel[:100, :, :, :]
nLabel = nLabel[:100, :]
print(f'new shape (skel): {nSkel.shape}')
print(f'new shape (label): {nLabel.shape}')
print(f'A total of {c} elements have been removed')
np.save(spLabel, nLabel)
np.save(spSkel, nSkel)
print("=======================================================")
#return y, nSkel, nLabel
def convertO64(testSkel, testLabel, spSkel, spLabel):
global y, nSkel, nLabel
c=0
print("=======================================================")
print(f'original skel shape: {testSkel.shape}')
print(f'original label shape: {testLabel.shape}')
nSkel = 0
nLabel = 0
while testSkel.shape[0]%64 != 0:
testSkel = np.delete(testSkel, -1, axis=0)
testLabel = np.delete(testLabel, -1, axis = 0)
c += 1
y = int(testSkel.shape[0]/32)-1
nSkel = np.empty([y, 64, 12, 2])
nLabel = np.empty([y, 1])
for i in range(0, y):
nSkel[i] = testSkel[(i*32):(i*32)+64,:,:]
nLabel[i] = int(st.median(testLabel.flatten()[(i*32):(i*32)+64]))
print(f'new shape (skel): {nSkel.shape}')
print(f'new shape (label): {nLabel.shape}')
print(f'A total of {c} elements have been removed')
np.save(spLabel, nLabel)
np.save(spSkel, nSkel)
print("=======================================================")
#return y, nSkel, nLabel
#Apply the same random rotation to all groups of 32 coordinates
"""rotated_coordinates = rotateAugment(tx_train, max_angle=10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=-10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=-10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=-10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))"""
"""rotated_coordinates = rotateAugment(tx_train, max_angle=10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=-10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=-10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))
rotated_coordinates = rotateAugment(tx_train, max_angle=-10)
x_train = np.concatenate((x_train, rotated_coordinates))
y_train = np.concatenate((y_train, ty_train))"""
"""
rotated_coordinates = rotateAugment(tx_test, max_angle=10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=-10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=-10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=-10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=-10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=-10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
rotated_coordinates = rotateAugment(tx_test, max_angle=-10)
x_test = np.concatenate((x_test, rotated_coordinates))
y_test = np.concatenate((y_test, ty_test))
"""
"""def stretch(coordinates):
#640, 360
#384, 288
if coordinates[0] > 640 and coordinates[1] > 360:
#botton right
x = 1280 - 0.5*(1280 - coordinates[0])
y = 720 - 0.5*(720 - coordinates[1])
return (int(x), int(y))
elif coordinates[0] > 640 and coordinates[1] < 360:
#top right
x = 1280 - 0.5*(1280 - coordinates[0])
y = 0.5*coordinates[1]
return (int(x), int(y))
elif coordinates[0] < 640 and coordinates[1] > 360:
#bottom left
x = 0.5*coordinates[0]
y = 720 - 0.5*(720 - coordinates[1])
return (int(x), int(y))
elif coordinates[0] < 640 and coordinates[1] < 360:
#top left
return (coordinates[0]*0.5, coordinates[1]*0.5)
else:
print("error")"""
"""def stretch(coordinates):
#640, 360
#420, 288
if coordinates[0] > 300 and coordinates[1] > 360:
#botton right
x = 1280 - 0.6*(1280 - coordinates[0])
y = 720 - 0.6*(720 - coordinates[1])
return (int(x), int(y))
elif coordinates[0] > 300 and coordinates[1] < 360:
#top right
x = 1280 - 0.6*(1280 - coordinates[0])
y = 0.6*coordinates[1]
return (int(x), int(y))
elif coordinates[0] < 300:
# left
#x = 0.5*coordinates[0]
#y = 720 - 0.5*(720 - coordinates[1])
return (int(coordinates[0]), int(0.8* coordinates[1]))
else:
print("error")"""