-
Notifications
You must be signed in to change notification settings - Fork 0
/
cremiFPsplitonlyB.py
171 lines (102 loc) · 4.1 KB
/
cremiFPsplitonlyB.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
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 + 'CREMIBIGSPLITONLY_B_FP/'
#
# 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(25,30)# + 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)
bigM_cremi_file = OUTDIR+'bigM_fp.p'
if os.path.exists(bigM_cremi_file):
print 'loading bigM'
with open(bigM_cremi_file, 'rb') as f:
bigM = pickle.load(f)
bigM = bigM[25:30]
# 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:
#
#
# 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, input_image, input_prob, input_rhoana, input_gold, sureness_threshold=.00, FP=True)
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:
#
# 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, input_image, input_prob, input_rhoana, input_gold, hours=-1, FP=True)
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.'