-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_data_subset_bootstrap.py
121 lines (89 loc) · 5.01 KB
/
generate_data_subset_bootstrap.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
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 21 14:03:53 2017
@author: wawan
"""
import IPython
import h5py
import numpy as np
from keras.utils.io_utils import HDF5Matrix
train=h5py.File('/home/ubuntuone/Projects/data/CelebAHDF5/celeba_aligned_cropped_train_5cls.hdf5','r')
valid=h5py.File('/home/ubuntuone/Projects/data/CelebAHDF5/celeba_aligned_cropped_valid_5cls.hdf5','r')
test=h5py.File('/home/ubuntuone/Projects/data/CelebAHDF5/celeba_aligned_cropped_test_5cls.hdf5','r')
#alldata=h5py.File('/home/ubuntuone/Projects/data/CelebAHDF5/celeba_aligned_cropped.hdf5','r')
ftrain = h5py.File("celeba_aligned_cropped_train_5cls_bootstrap4.hdf5", "w")
cls4_train=train['targets'][:,4]==1
icls_train=np.where(cls4_train)[0]
# IPython.embed()
ftrain.create_dataset("features", (icls_train.shape[0],218,178,3), dtype='f')
ftrain.create_dataset("targets", (icls_train.shape[0],5), dtype='f')
print('Generate train features 4')
for i in range(icls_train.shape[0]):
ftrain['features'][i]=train['features'][icls_train[i],:,:,:]
print('Generate train targets 4')
for i in range(icls_train.shape[0]):
ftrain['targets'][i]=train['targets'][icls_train[i],0:5]
ftrain.close()
# ------------------------------------------------------------------------------------------------------------------
# ftrain = h5py.File("celeba_aligned_cropped_train_5cls_bootstrap2.hdf5", "w")
# cls2_train=train['targets'][:,2]==1
# cls4_train=train['targets'][:,4]==0
# icls_train=np.where(np.logical_and.reduce((cls2_train, cls4_train)))[0]
# ftrain.create_dataset("features", (icls_train.shape[0],218,178,3), dtype='f')
# ftrain.create_dataset("targets", (icls_train.shape[0],5), dtype='f')
# print('Generate train features 2')
# for i in range(icls_train.shape[0]):
# ftrain['features'][i]=train['features'][icls_train[i],:,:,:]
# print('Generate train targets 2')
# for i in range(icls_train.shape[0]):
# ftrain['targets'][i]=train['targets'][icls_train[i],0:5]
# ftrain.close()
# # ------------------------------------------------------------------------------------------------------------------
# ftrain = h5py.File("celeba_aligned_cropped_train_5cls_bootstrap1.hdf5", "w")
# cls1_train=train['targets'][:,1]==1
# cls2_train=train['targets'][:,2]==0
# cls4_train=train['targets'][:,4]==0
# icls_train=np.where(np.logical_and.reduce((cls1_train, cls2_train, cls4_train)))[0]
# ftrain.create_dataset("features", (icls_train.shape[0],218,178,3), dtype='f')
# ftrain.create_dataset("targets", (icls_train.shape[0],5), dtype='f')
# print('Generate train features 1')
# for i in range(icls_train.shape[0]):
# ftrain['features'][i]=train['features'][icls_train[i],:,:,:]
# print('Generate train targets 1')
# for i in range(icls_train.shape[0]):
# ftrain['targets'][i]=train['targets'][icls_train[i],0:5]
# ftrain.close()
# # ------------------------------------------------------------------------------------------------------------------
# ftrain = h5py.File("celeba_aligned_cropped_train_5cls_bootstrap3.hdf5", "w")
# cls1_train=train['targets'][:,1]==0
# cls2_train=train['targets'][:,2]==0
# cls3_train=train['targets'][:,3]==1
# cls4_train=train['targets'][:,4]==0
# icls_train=np.where(np.logical_and.reduce((cls1_train, cls2_train, cls3_train, cls4_train)))[0]
# ftrain.create_dataset("features", (icls_train.shape[0],218,178,3), dtype='f')
# ftrain.create_dataset("targets", (icls_train.shape[0],5), dtype='f')
# print('Generate train features 3')
# for i in range(icls_train.shape[0]):
# ftrain['features'][i]=train['features'][icls_train[i],:,:,:]
# print('Generate train targets 3')
# for i in range(icls_train.shape[0]):
# ftrain['targets'][i]=train['targets'][icls_train[i],0:5]
# ftrain.close()
# # ------------------------------------------------------------------------------------------------------------------
# ftrain = h5py.File("celeba_aligned_cropped_train_5cls_bootstrap0.hdf5", "w")
# cls0_train=train['targets'][:,0]==1
# cls1_train=train['targets'][:,1]==0
# cls2_train=train['targets'][:,2]==0
# cls3_train=train['targets'][:,3]==0
# cls4_train=train['targets'][:,4]==0
# icls_train=np.where(np.logical_and.reduce((cls0_train, cls1_train, cls2_train, cls3_train, cls4_train)))[0]
# ftrain.create_dataset("features", (icls_train.shape[0],218,178,3), dtype='f')
# ftrain.create_dataset("targets", (icls_train.shape[0],5), dtype='f')
# print('Generate train features 0')
# for i in range(icls_train.shape[0]):
# ftrain['features'][i]=train['features'][icls_train[i],:,:,:]
# print('Generate train targets 0')
# for i in range(icls_train.shape[0]):
# ftrain['targets'][i]=train['targets'][icls_train[i],0:5]
# ftrain.close()
# # IPython.embed()