-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergepatchesCREMI.py
70 lines (51 loc) · 1.71 KB
/
mergepatchesCREMI.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
import numpy as np
#
#
#
basedir = '/n/regal/pfister_lab/haehn/CREMIBIG/'
trainA = basedir + 'train_0_100.npz.npy'
trainA_targets = basedir + 'train_0_100_targets.npz.npy'
trainB = basedir + 'train_100_200.npz.npy'
trainB_targets = basedir + 'train_100_200_targets.npz.npy'
trainC = basedir + 'train_200_298.npz.npy'
trainC_targets = basedir + 'train_200_298_targets.npz.npy'
counter = 0
trainA = np.load(trainA, mmap_mode='r')
trainA_count = trainA.shape[0]
trainB = np.load(trainB, mmap_mode='r')
trainB_count = trainB.shape[0]
trainC = np.load(trainC, mmap_mode='r')
trainC_count = trainC.shape[0]
all_count = trainA_count + trainB_count + trainC_count
#
# allocate large array
#
PATCH_BYTES = 75*75
NO_PATCHES = all_count
P_SIZE = (NO_PATCHES, 4, 75,75) # rather than raveled right now
p_rgba = np.zeros(P_SIZE, dtype=np.float32)
p_rgba[0:trainA_count] = trainA
p_rgba[trainA_count:trainA_count+trainB_count] = trainB
p_rgba[trainB_count:trainB_count+trainC_count] = trainC
# now store this bad boy
np.save(basedir+'train.npy', p_rgba)
# print 'STORED BIG BOY!'
p_rgba = None # free them all
#
# same for targets
#
trainA_targets = np.load(trainA_targets)
trainA_count = trainA_targets.shape[0]
trainB_targets = np.load(trainB_targets)
trainB_count = trainB_targets.shape[0]
trainC_targets = np.load(trainC_targets)
trainC_count = trainC_targets.shape[0]
all_count = trainA_count + trainB_count + trainC_count
NO_PATCHES = all_count
p_target = np.zeros(NO_PATCHES)
p_target[0:trainA_count] = trainA_targets
p_target[trainA_count:trainA_count+trainB_count] = trainB_targets
p_target[trainB_count:trainB_count+trainC_count] = trainC_targets
# now store this lady boy
np.save(basedir+'train_targets.npy', p_target)
print 'ALL DONE!'