-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcylinderFP.py
146 lines (97 loc) · 3.53 KB
/
cylinderFP.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
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/cylinderNEW/'
OUTDIR = REGALDIR + 'cylinderFP/'
#
# load cnn
#
with open('nets/IPMLB_FULL.p', 'rb') as f:
cnn = pickle.load(f)
cnn.uuid = 'IPMLB'
#
# load data
#
input_image = []
input_prob = []
input_rhoana = []
input_gold = []
for z in range(250, 300):
image, prob, mask, gold, rhoana = gp.Util.read_section(DATADIR, z, verbose=False)
input_image.append(image)
input_prob.append(255.-prob)
input_rhoana.append(rhoana)
input_gold.append(gold)
original_mean_VI, original_median_VI, original_VI_s = gp.Legacy.VI(input_gold, input_rhoana)
#
# no merge errors
#
merge_errors = []
print len(merge_errors), 'merge errors'
#
# load bigM
#
bigM_cylinder_file = OUTDIR+'bigM_fp.p'
print 'loading bigM'
with open(bigM_cylinder_file, 'rb') as f:
bigM = pickle.load(f)
#
# run auto split correction
#
cylinder_vi_95_file = OUTDIR + '/cylinder_vi_95_NEW.p'
split_vis = OUTDIR + '/cylinder_split_auto95_vis.p'
split_fixes = OUTDIR + '/cylinder_split_auto95_fixes.p'
output_95 = OUTDIR + '/cylinder_auto95_output.p'
if os.path.exists(cylinder_vi_95_file):
print 'Loading split errors p > .95 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 > .5'
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=.5, 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 split correction
#
cylinder_vi_95_file = OUTDIR + '/cylinder_vi_simuser_NEW.p'
split_vis = OUTDIR + '/cylinder_split_simuser_vis.p'
split_fixes = OUTDIR + '/cylinder_split_simuser_fixes.p'
output_95 = OUTDIR + '/cylinder_simuser_output.p'
if os.path.exists(cylinder_vi_95_file):
print 'Loading split errors simuser 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.'