-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreprocess.py
56 lines (46 loc) · 1.15 KB
/
preprocess.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
import numpy as np
import matplotlib.pyplot as plt
import os
import pickle
import json
data_dir = ["none","fist","hand","one","peace"]
allX=None
allY=None
for i in range(len(data_dir)):
path = "data/"+data_dir[i]+"/"
data_list = os.listdir(path)
data_list.remove('y.txt')
X = np.empty((len(data_list),1,50,50))
y = np.ones(len(data_list))*i
for num in range(len(data_list)):
X[num,0,:,:] = plt.imread(path+data_list[num])
if allX is None:
allX=X
allY=y
else:
allX = np.concatenate((allX,X),0)
allY = np.concatenate((allY,y),0)
s = range(allX.shape[0])
np.random.shuffle(s)
allX = allX[s]
allY = allY[s]
mean_px = np.mean(allX)
std_px = np.std(allX)
#print(mean_im.shape)
allX = (allX - mean_px)/std_px
print(allY)
trainX = allX[:3000]
trainY = allY[:3000]
validationX = allX[3000:3500]
validationY = allY[3000:3500]
testX = allX[3500:]
testY = allY[3500:]
data = {
"trainX":trainX.tolist(),
"trainY":trainY.tolist(),
"validX":validationX.tolist(),
"validY":validationY.tolist(),
"testX":testX.tolist(),
"testY":testY.tolist()
}
json.dump(data,open("data/data2.json","wb"))