-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathload_data.py
39 lines (30 loc) · 1.03 KB
/
load_data.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
import h5py
import numpy as np
def loading_data(path):
print '******************************************************'
print 'dataset:{0}'.format(path)
print '******************************************************'
file = h5py.File(path)
images = file['images'][:].transpose(0,3,2,1)
labels = file['LAll'][:].transpose(1,0)
tags = file['YAll'][:].transpose(1,0)
file.close()
return images, tags, labels
def split_data(images, tags, labels, QUERY_SIZE, TRAINING_SIZE, DATABASE_SIZE):
X = {}
index_all = np.random.permutation(QUERY_SIZE+DATABASE_SIZE)
ind_Q = index_all[0:QUERY_SIZE]
ind_T = index_all[QUERY_SIZE:TRAINING_SIZE + QUERY_SIZE]
ind_R = index_all[QUERY_SIZE:DATABASE_SIZE + QUERY_SIZE]
X['query'] = images[ind_Q, :, :, :]
X['train'] = images[ind_T, :, :, :]
X['retrieval'] = images[ind_R, :, :, :]
Y = {}
Y['query'] = tags[ind_Q, :]
Y['train'] = tags[ind_T, :]
Y['retrieval'] = tags[ind_R, :]
L = {}
L['query'] = labels[ind_Q, :]
L['train'] = labels[ind_T, :]
L['retrieval'] = labels[ind_R, :]
return X, Y, L