-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadData.py
More file actions
66 lines (61 loc) · 2.94 KB
/
Copy pathreadData.py
File metadata and controls
66 lines (61 loc) · 2.94 KB
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
import h5py
import numpy as np
def readH5file(dataSet='awa1',type='binary'):
filename = "./datasets/"+dataSet+"/data.h5"
file = h5py.File(filename, 'r')
#==========================================#
train_x = np.array(file['train']['X'])
train_a = np.array(file['train']['A'][type])
train_y = np.array(file['train']['Y'])
# ==========================================#
val_x = np.array(file['val']['X'])
val_y = np.array(file['val']['Y'])
val_a = np.array(file['val']['A'][type])
# ==========================================#
test_x = np.array(file['test']['unseen']['X'])
test_a = np.array(file['test']['unseen']['A'][type])
test_y = np.array(file['test']['unseen']['Y'])
return (train_x, train_y, train_a), (test_x, test_y,test_a), (val_x, val_y,val_a)
def readH5file2(dataSet='awa1',type='binary'):
filename = "./datasets/"+dataSet+"/data.h5"
file = h5py.File(filename, 'r')
#==========================================#
train_x = np.array(file['train']['X'])
train_a = np.array(file['train']['A'][type])
train_y = np.array(file['train']['Y'])
# ==========================================#
test_x = np.array(file['test']['seen']['X'])
test_a = np.array(file['test']['seen']['A'][type])
test_y = np.array(file['test']['seen']['Y'])
return (train_x, train_y, train_a), (test_x, test_y,test_a)
def readForDap(dataSet='awa1',type='binary'):
filename = "./datasets/"+dataSet+"/data.h5"
file = h5py.File(filename, 'r')
#==========================================#
train_x = np.array(file['train']['X'])
train_a = np.array(file['train']['A'][type])
train_y = np.array(file['train']['Y'])
# ==========================================#
test_xs = np.array(file['test']['seen']['X'])
test_as = np.array(file['test']['seen']['A'][type])
test_ys = np.array(file['test']['seen']['Y'])
test_x = np.array(file['test']['unseen']['X'])
test_a = np.array(file['test']['unseen']['A'][type])
test_y = np.array(file['test']['unseen']['Y'])
from keras.models import load_model
generator = load_model('./model/generator.h5', compile=False)
noise = np.random.normal(0, 1, (5685, 85))
temp_x = generator.predict([noise, test_a])
idx = np.random.randint(0, temp_x.shape[0], 300)
features, labels, attr = temp_x[idx], test_y[idx], test_a[idx]
test_x = np.concatenate((test_x, test_xs), axis=0)
test_a = np.concatenate((test_a, test_as), axis=0)
test_y = np.concatenate((test_y, test_ys), axis=0)
final_x = np.concatenate((train_x, features), axis=0)
final_a = np.concatenate((train_a, attr), axis=0)
final_y = np.concatenate((train_y, labels), axis=0)
return (final_a,final_x,final_y), (test_a,test_x, test_y)
def numberOfClass(dataSet='awa1'):
filename = "./datasets/"+dataSet+"/data.h5"
file = h5py.File(filename, 'r')
return np.unique(file['train']["Y"]).shape[0]+np.unique(file['test']['unseen']['Y']).shape[0]