-
Notifications
You must be signed in to change notification settings - Fork 1
/
mnistdoubleydata10.py
90 lines (65 loc) · 3.37 KB
/
mnistdoubleydata10.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
import numpy as np
import pickle
#from torchvision.datasets.mnist import MNIST
sr = 22050
n_mels = 128
hop_length = 512
n_iter = 32
with open('train_combined_data.pkl','rb') as f: traindata = pickle.load(f)
with open('train_combined_labels.pkl','rb') as f: trainlabels = pickle.load(f)
with open('test_combined_data.pkl','rb') as f: testdata = pickle.load(f)
with open('test_combined_labels.pkl','rb') as f: testlabels = pickle.load(f)
print(testlabels.shape)
train_combined = np.zeros((250000,2,28,28))
test_combined = np.zeros((50000,2,28,28))
train_combined_labels = np.zeros(250000)
test_combined_labels = np.zeros(50000)
for i in range(0,10):
idxtrv = np.argwhere(trainlabels == i)
idxtsv = np.argwhere(testlabels == i)
#print(idxtrv.shape)
tr1 = np.random.choice(np.squeeze(idxtrv), size = 2500, replace = False, p = None)
tr1r = np.repeat(tr1, 10)
#print(tr1r.shape)
ts1 = np.random.choice(np.squeeze(idxtsv), size = 500, replace = False, p = None)
ts2 = np.random.choice(np.squeeze(idxtsv), size = 5000, replace = True, p = None)
ts1r = np.repeat(ts1, 10)
tr2 = np.random.choice(np.squeeze(idxtrv), size = 25000, replace = True, p = None)
ttd = traindata[tr1r,0,:,:]
#print(ttd.shape)
train_combined[i*25000:(i+1)*25000,0,:,:] = traindata[tr1r,1,:,:]
train_combined[i*25000:(i+1)*25000,1,:,:] = traindata[tr2,0,:,:]
train_combined_labels[i*25000:(i+1)*25000] = i
test_combined[i*5000: (i+1)*5000,0,:,:] = testdata[ts1r,1,:,:]
test_combined[i*5000: (i+1)*5000,1,:,:] = testdata[ts2,0,:,:]
test_combined_labels[i*5000:(i+1)*5000] = i
"""
#ts2 = np.random.choice(np.squeeze(idxtsv), size = 500, replace = False, p = None)
#idxa = np.argwhere(image_labels == i)
#stra = np.random.choice(np.squeeze(idxa), size = 2500, replace = False, p = None)
#stsa = np.setxor1d(stra, np.squeeze(idxa))
trains = traindata[tr1,0,:,:]
tests = testdata[ts1,0,:,:]
for j in range(len(tr1)):
train_combined[i*2500+ (j*10) :i*2500+ (j+1)*10 ,0,:,:] = trains[j]
#print(trains[j].shape)
tr2 = np.random.choice(np.squeeze(idxtrv), size = 10, replace = False, p = None)
print(i,j,train_combined[i*2500+ (j*10) :i*2500 + (j+1)*10 ,1,:,:].shape)
train_combined[i*2500+ (j*10) :i*2500 + (j+1)*10 ,1,:,:] = traindata[tr2,0,:,:]
#train_combined[i*2500:(i+1)*2500,1,:,:] = train_set_array[tr2]
train_combined_labels[i*2500+ (j*10) :i*2500+ (j+1)*10] = i
for k in range(len(ts1)-1):
test_combined[i*500+ (k*10) :i*500+ (k+1)*10 ,0,:,:] = tests[k]
ts2 = np.random.choice(np.squeeze(idxtsv), size = 10, replace = False, p = None)
test_combined[i*500+ (k*10) :i*500+ (k+1)*10 ,1,:,:] = testdata[ts2,0,:,:]
#train_combined[i*2500:(i+1)*2500,1,:,:] = train_set_array[tr2]
test_combined_labels[i*500+ (j*10) :i*500+ (j+1)*10] = i
"""
print(test_combined_labels)
for j in range(0,10):
idx0 = test_combined_labels == j
print(j,idx0)
with open('atrain_combined10_data.pkl','wb') as f: pickle.dump(train_combined, f)
with open('atrain_combined10_labels.pkl','wb') as f: pickle.dump(train_combined_labels, f)
with open('atest_combined10_data.pkl','wb') as f: pickle.dump(test_combined, f)
with open('atest_combined10_labels.pkl','wb') as f: pickle.dump(test_combined_labels, f)