-
Notifications
You must be signed in to change notification settings - Fork 0
/
cremiGP.py
210 lines (130 loc) · 5.69 KB
/
cremiGP.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import gp
import cPickle as pickle
import numpy as np
import os
HOMEDIR = '/n/home05/haehn/'
REGALDIR = '/n/regal/pfister_lab/haehn/'
DATADIR = HOMEDIR + 'data/CREMIGP/TEST/'
OUTDIR = REGALDIR + 'CREMIBIG/'
#
# load cnn
#
with open('nets/IPMLB_FULL_CREMI_FINAL.p', 'rb') as f:
cnn = pickle.load(f)
cnn.uuid = 'IPMLB'
#
# load data
#
input_image = []
input_prob = []
input_gold = []
input_rhoana = []
test_slices = range(75)# + range(25+20,50) + range(50+20,75)
for z in test_slices:
image, prob, gold, rhoana = gp.Util.read_cremi_section(os.path.expanduser('~/data/CREMIGP/TEST/'), z)
input_image.append(image)
input_prob.append(255.-prob)
input_gold.append(gold)
input_rhoana.append(rhoana)
original_mean_VI, original_median_VI, original_VI_s = gp.Legacy.VI(input_gold, input_rhoana)
# find merge errors, if we did not generate them before
# find merge errors, if we did not generate them before
merge_error_file = OUTDIR+'/merge_errors.p'
if os.path.exists(merge_error_file):
print 'Loading merge errors from file..'
with open(merge_error_file, 'rb') as f:
merge_errors = pickle.load(f)
print len(merge_errors), ' merge errors found.'
bigM_cremi_file = OUTDIR+'bigM_gp.p'
if os.path.exists(bigM_cremi_file):
print 'loading bigM'
with open(bigM_cremi_file, 'rb') as f:
bigM = pickle.load(f)
# else:
# print 'creating bigM'
# bigM = gp.Legacy.create_bigM_without_mask(cnn, input_image, input_prob, input_rhoana, verbose=True, max=1000000)
# with open(bigM_cremi_file, 'wb') as f:
# pickle.dump(bigM, f)
#
# run auto merge correction
#
cylinder_vi_95_file = OUTDIR + '/cremi_vi_00_w_merge_NEW.p'
merge_vis = OUTDIR + '/cremi_merge_auto00_vis.p'
split_vis = OUTDIR + '/cremi_split_auto00_vis.p'
merge_fixes = OUTDIR + '/cremi_merge_auto00_fixes.p'
split_fixes = OUTDIR + '/cremi_split_auto00_fixes.p'
output_95 = OUTDIR + '/cremi_auto00_output.p'
if os.path.exists(cylinder_vi_95_file):
print 'Loading merge errors p < .05 and split errors p > .00 from file..'
with open(cylinder_vi_95_file, 'rb') as f:
cylinder_vi_95 = pickle.load(f)
else:
#
# perform merge correction with p < .05
#
print 'Correcting merge errors with p < .05'
bigM_05, corrected_rhoana_05, cylinder_auto_merge_fixes, vi_s_per_step = gp.Legacy.perform_auto_merge_correction(cnn, bigM, input_image, input_prob, input_rhoana, merge_errors, .05, input_gold=input_gold)
print ' Mean VI improvement', original_mean_VI-gp.Legacy.VI(input_gold, corrected_rhoana_05)[0]
print ' Median VI improvement', original_median_VI-gp.Legacy.VI(input_gold, corrected_rhoana_05)[1]
with open(merge_vis, 'wb') as f:
pickle.dump(vi_s_per_step, f)
with open(merge_fixes, 'wb') as f:
pickle.dump(cylinder_auto_merge_fixes, f)
#
# run auto split correction
#
print 'Correcting split errors with p > .0'
bigM_cylinder_after_95, out_cylinder_volume_after_auto_95, cylinder_auto_fixes_95, cylinder_auto_vi_s_95, vi_s_per_step2 = gp.Legacy.splits_global_from_M_automatic(cnn, bigM_05, input_image, input_prob, corrected_rhoana_05, input_gold, sureness_threshold=.00)
cylinder_vi_95 = gp.Legacy.VI(input_gold, out_cylinder_volume_after_auto_95)
with open(cylinder_vi_95_file, 'wb') as f:
pickle.dump(cylinder_vi_95, f)
with open(split_vis, 'wb') as f:
pickle.dump(vi_s_per_step2, f)
with open(split_fixes, 'wb') as f:
pickle.dump(cylinder_auto_fixes_95, f)
with open(output_95, 'wb') as f:
pickle.dump(out_cylinder_volume_after_auto_95, f)
print ' Mean VI improvement', original_mean_VI-cylinder_vi_95[0]
print ' Median VI improvement', original_median_VI-cylinder_vi_95[1]
#
# run oracle merge correction
#
cylinder_vi_95_file = OUTDIR + '/cremi_vi_simuser_w_merge_NEW.p'
merge_vis = OUTDIR + '/cremi_merge_simuser_vis.p'
split_vis = OUTDIR + '/cremi_split_simuser_vis.p'
merge_fixes = OUTDIR + '/cremi_merge_simuser_fixes.p'
split_fixes = OUTDIR + '/cremi_split_simuser_fixes.p'
output_95 = OUTDIR + '/cremi_simuser_output.p'
if os.path.exists(cylinder_vi_95_file):
print 'Loading merge errors p < .05 and split errors p > .95 from file..'
with open(cylinder_vi_95_file, 'rb') as f:
cylinder_vi_95 = pickle.load(f)
else:
#
# perform merge correction with p < .05
#
print 'Correcting merge errors with oracle'
bigM_05, corrected_rhoana_05, cylinder_auto_merge_fixes, vi_s_per_step = gp.Legacy.perform_sim_user_merge_correction(cnn, bigM, input_image, input_prob, input_rhoana, input_gold, merge_errors)
print ' Mean VI improvement', original_mean_VI-gp.Legacy.VI(input_gold, corrected_rhoana_05)[0]
print ' Median VI improvement', original_median_VI-gp.Legacy.VI(input_gold, corrected_rhoana_05)[1]
with open(merge_vis, 'wb') as f:
pickle.dump(vi_s_per_step, f)
with open(merge_fixes, 'wb') as f:
pickle.dump(cylinder_auto_merge_fixes, f)
#
# run oracle split correction
#
print 'Correcting split errors with p > .95'
bigM_cylinder_after_95, out_cylinder_volume_after_auto_95, cylinder_auto_fixes_95, cylinder_auto_vi_s_95, vi_s_per_step2 = gp.Legacy.splits_global_from_M(cnn, bigM_05, input_image, input_prob, corrected_rhoana_05, input_gold, hours=-1)
cylinder_vi_95 = gp.Legacy.VI(input_gold, out_cylinder_volume_after_auto_95)
with open(cylinder_vi_95_file, 'wb') as f:
pickle.dump(cylinder_vi_95, f)
with open(split_vis, 'wb') as f:
pickle.dump(vi_s_per_step2, f)
with open(split_fixes, 'wb') as f:
pickle.dump(cylinder_auto_fixes_95, f)
with open(output_95, 'wb') as f:
pickle.dump(out_cylinder_volume_after_auto_95, f)
print ' Mean VI improvement', original_mean_VI-cylinder_vi_95[0]
print ' Median VI improvement', original_median_VI-cylinder_vi_95[1]
print 'All done.'