-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
83 lines (73 loc) · 2.31 KB
/
test.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
import os
import pickle
import numpy as np
from PIL import Image
#im = Image.open('/Users/michael/test.jpg')
'''
permutations = []
for i in range(args.n_tasks):
indices = np.random.permutation(784)
print(x_tr[:, indices].shape)#(55000, 784)
permutations.append((x_tr[:, indices], y_tr, x_val[:, indices], y_val, x_te[:, indices], y_te))
f = open(args.o, "wb")
pickle.dump(permutations, f)
f.close()
'''
def to_categorical(y, num_classes=None):
y = np.array(y, dtype='int')
input_shape = y.shape
if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
input_shape = tuple(input_shape[:-1])
y = y.ravel()
if not num_classes:
num_classes = np.max(y) + 1
n = y.shape[0]
categorical = np.zeros((n, num_classes))
categorical[np.arange(n), y] = 1
output_shape = input_shape + (num_classes,)
categorical = np.reshape(categorical, output_shape)
return categorical
index = os.listdir('./Green')
index.sort()
hhh = list( range(0,10) )
pick_file=[]
for i in hhh:
temp = index[i*50: i*50+50]
train = []
train_y = []
validation = []
validation_y = []
test = []
test_y =[]
#print(temp)
for item in temp:
file = os.path.join('./Green',item)
temp1 = os.listdir(str(file))
timer = 0
for j in temp1:
a=np.asarray(Image.open(os.path.join(file,j)).convert('RGB'))
a = (a-np.mean(a))/np.std(a)
if timer<6:
train.append(a)
train_y.append(int(item)-1-50*i)
timer+=1
elif timer>=6 and timer <=8:
test.append(a)
test_y.append(int(item)-1-50*i)
timer+=1
else:
validation.append(a)
validation_y.append(int(item)-1-50*i)
timer+=1
print(np.asarray(train).shape)
print(np.asarray(train_y).shape)
print(np.asarray(validation).shape)
print(np.asarray(validation_y).shape)
print(np.asarray(test).shape)
print(np.asarray(test_y).shape)
pick_file.append((train, to_categorical(train_y), validation,to_categorical(validation_y), test,to_categorical(test_y)))
f = open('./data.pkl', "wb")
pickle.dump(pick_file, f)
f.close()
#print()
#[103.939, 116.779, 123.68]