1616g_gold_tree = None
1717g_tar_tree = None
1818g_rcn_method = None
19+ g_rcn_config = None
1920g_metric_method = None
2021g_metric_configs = None
2122
2223NEUTU_PATH = "../../../../../00_program_file/00_neutu/bin/neutu"
2324ORIGIN_PATH = "../../../data/optimation/test1/test1_test.tif"
2425GOLD_PATH = "../../../data/optimation/test1/test1_gold.swc"
25- TEST_PATH = "../../../data/optimation/output/test1_test.swc "
26- CONFIG_PATH = "../../../config/fake_reconstruction_configs/test.json "
26+ TEST_PATH = "../../../data/optimation/output/"
27+ CONFIG_PATH = "../../../config/fake_reconstruction_configs/"
2728METRIC_CONFIG_PATH = "../../../config/ssd_metric.json"
2829LOG_PATH = "../../../output/optimization/neutu_log.txt"
2930
148149# print(X.shape)
149150
150151
151- def SA_optimize (configs , lock = None ):
152- global g_gold_tree
152+ def SA_optimize (configs = None , test_name = None , lock = None ):
153153 global g_metric_method
154154 global g_metric_configs
155+ global g_rcn_config
155156
156- # # check the value of configs
157- # res = fake_gaussian(pos=configs)
157+ LOC_CONFIG_PATH = os .path .join (CONFIG_PATH , test_name + ".json" )
158+ LOC_TEST_PATH = os .path .join (TEST_PATH , test_name + ".swc" )
159+ rec_config = copy .deepcopy (g_rcn_config )
158160
159- rec_config = copy .deepcopy (g_metric_configs )
161+ if configs is not None :
162+ rec_config ["trace" ]["default" ]["minimalScoreAuto" ] = configs [0 ]
163+ rec_config ["trace" ]["default" ]["minimalScoreManual" ] = configs [1 ]
164+ rec_config ["trace" ]["default" ]["minimalScoreSeed" ] = configs [2 ]
165+ rec_config ["trace" ]["default" ]["minimalScore2d" ] = configs [3 ]
160166
161- for i in range (len (configs )):
162- configs [i ] = max (configs [i ], 0 )
163- configs [i ] = min (configs [i ], 1 )
167+ read_json .save_json (LOC_CONFIG_PATH , rec_config )
164168
165- rec_config ["trace" ]["default" ]["minimalScoreAuto" ] = configs [0 ]
166- rec_config ["trace" ]["default" ]["minimalScoreManual" ] = configs [1 ]
167- rec_config ["trace" ]["default" ]["minimalScoreSeed" ] = configs [2 ]
168- rec_config ["trace" ]["default" ]["minimalScore2d" ] = configs [3 ]
169-
170- # save new configs
171- if lock is not None :
172- lock .acquire ()
173- try :
174- read_json .save_json (json_file_path = CONFIG_PATH , data = rec_config )
175- finally :
176- if lock is not None :
177- lock .release ()
178169 REC_CMD = "{} --command --trace {} -o {} --config {} > {}" .format (
179- NEUTU_PATH , ORIGIN_PATH , TEST_PATH , CONFIG_PATH , LOG_PATH
170+ NEUTU_PATH , ORIGIN_PATH , LOC_TEST_PATH , LOC_CONFIG_PATH , LOG_PATH
180171 )
181172 try :
182173 os .system (REC_CMD )
@@ -185,7 +176,7 @@ def SA_optimize(configs, lock=None):
185176
186177 res_tree = swc_node .SwcTree ()
187178 gold_tree = swc_node .SwcTree ()
188- res_tree .load (TEST_PATH )
179+ res_tree .load (os . path . join ( TEST_PATH , test_name + ".swc" ) )
189180 gold_tree .load (GOLD_PATH )
190181
191182 if lock is not None :
@@ -195,25 +186,26 @@ def SA_optimize(configs, lock=None):
195186 finally :
196187 if lock is not None :
197188 lock .release ()
189+ score = (main_score ["recall" ] + main_score ["precision" ])/ 2
190+ print ("[Info: ] ssd loss = {}" .format (score ))
198191
199- print ("[Info: ] ssd loss = {}" .format (
200- (main_score ["recall" ] + main_score ["precision" ])/ 2 )
201- )
202-
203- return - (main_score ["recall" ] + main_score ["precision" ])/ 2
192+ return configs , - score
204193
205194
206195def main ():
207196 global g_metric_configs
208197 global g_metric_method
198+ global g_rcn_config
209199 g_metric_method = ssd_metric .ssd_metric
210200 g_metric_configs = read_json .read_json (METRIC_CONFIG_PATH )
201+ g_rcn_config = read_json .read_json (os .path .join (CONFIG_PATH , "test.json" ))
202+
211203 # optimize with SA
212204 # configs here is the config of the reconstruction
213205 configs = (0.3 , 0.3 , 0.35 , 0.5 )
214206 start = time .time ()
215207 sa_fast = SAFast (func = SA_optimize ,
216- x0 = configs , T_max = 0.01 , T_min = 1e-5 , q = 0.96 , L = 30 , max_stay_counter = 20 , upper = 1 , lower = 0 )
208+ x0 = configs , T_max = 0.01 , T_min = 1e-5 , q = 0.96 , L = 20 , max_stay_counter = 30 , upper = 1 , lower = 0 )
217209 best_configs , best_value = sa_fast .run ()
218210 print ("[Info: ]best configs:\n "
219211 " origin minimalScoreAuto = {}\n "
@@ -224,6 +216,11 @@ def main():
224216 " time = {}\n " .format (
225217 best_configs [0 ], best_configs [1 ], best_configs [2 ], best_configs [3 ], best_value , time .time () - start
226218 ))
219+ g_rcn_config ["trace" ]["default" ]["minimalScoreAuto" ] = best_configs [0 ]
220+ g_rcn_config ["trace" ]["default" ]["minimalScoreManual" ] = best_configs [1 ]
221+ g_rcn_config ["trace" ]["default" ]["minimalScoreSeed" ] = best_configs [2 ]
222+ g_rcn_config ["trace" ]["default" ]["minimalScore2d" ] = best_configs [3 ]
223+ read_json .save_json (os .path .join (CONFIG_PATH , "best_x_{}.json" .format (time .time ())), g_rcn_config )
227224 # plot the result.
228225 plt .plot (pd .DataFrame (sa_fast .best_y_history ).cummin (axis = 0 ))
229226 plt .xlabel ("iterations" )
@@ -234,3 +231,9 @@ def main():
234231
235232if __name__ == "__main__" :
236233 main ()
234+
235+ # g_metric_method = ssd_metric.ssd_metric
236+ # g_metric_configs = read_json.read_json(METRIC_CONFIG_PATH)
237+ # g_rcn_config = read_json.read_json(os.path.join(CONFIG_PATH, "test3best.json"))
238+ #
239+ # SA_optimize(test_name="test3best")
0 commit comments