def run_mc(ds_train_name, ds_test_name, mc_params, save_path): assert os.path.exists(os.path.split(save_path)[0]), "Please choose an existing folder to save your results" # if you have added multiple segmentations, you can choose on which one to run # experiments with the seg_id seg_id = 0 # these strings encode the features that are used for the local features feature_list = ['raw', 'prob', 'reg'] meta.load() ds_train = meta.get_dataset(ds_train_name) ds_test = meta.get_dataset(ds_test_name) # use this for running the mc without defected slices mc_nodes, _, _, _ = multicut_workflow( ds_train, ds_test, seg_id, seg_id, feature_list, mc_params) # use this for running the mc with defected slices #mc_nodes, _, _, _ = multicut_workflow_with_defect_correction( # ds_train, ds_test, # seg_id, seg_id, # feature_list, mc_params) segmentation = ds_test.project_mc_result(seg_id, mc_nodes) vigra.writeHDF5(segmentation, save_path, 'data', compression = 'gzip')
def main(): args = process_command_line() out_folder = args.output_folder assert os.path.exists( out_folder), "Please choose an existing folder for the output" cache_folder = os.path.join(out_folder, "cache") # init the cache when running experiments the first time # if the meta set wasn't saved yet, we need to recreate the cache if not os.path.exists(os.path.join(cache_folder, "meta_dict.pkl")): init(args.data_folder, cache_folder, args.snemi_mode) meta = MetaSet(cache_folder) meta.load() ds_train = meta.get_dataset("ds_train") ds_test = meta.get_dataset("ds_test") # experiment settings exp_params = ExperimentSettings() exp_params.set_rfcache(os.path.join(cache_folder, "rf_cache")) # use extra 2d features exp_params.set_use2d(True) # parameters for learning exp_params.set_fuzzy_learning(True) exp_params.set_ntrees(500) # parameters for lifted multicut exp_params.set_lifted_neighborhood(3) # features used local_feats_list = ("raw", "prob", "reg", "topo") # we don't use the multicut feature here, because it can take too long lifted_feats_list = ("cluster", "reg") if args.snemi_mode: exp_params.set_anisotropy(5.) exp_params.set_weighting_scheme("all") exp_params.set_solver("multicut_exact") gamma = 10000. else: exp_params.set_anisotropy(25.) exp_params.set_weighting_scheme("z") exp_params.set_solver("multicut_fusionmoves") gamma = 2. seg_id = 0 if args.use_lifted: print "Starting Lifted Multicut Workflow" # have to make filters first due to cutouts... ds_train.make_filters(0, exp_params.anisotropy_factor) ds_train.make_filters(1, exp_params.anisotropy_factor) ds_test.make_filters(0, exp_params.anisotropy_factor) ds_test.make_filters(1, exp_params.anisotropy_factor) mc_node, mc_edges, mc_energy, t_inf = lifted_multicut_workflow( ds_train, ds_test, seg_id, seg_id, local_feats_list, lifted_feats_list, exp_params, gamma=gamma, weight_z_lifted=True) save_path = os.path.join(out_folder, "lifted_multicut_segmentation.tif") else: print "Starting Multicut Workflow" mc_node, mc_edges, mc_energy, t_inf = multicut_workflow( ds_train, ds_test, seg_id, seg_id, local_feats_list, exp_params) save_path = os.path.join(out_folder, "multicut_segmentation.tif") mc_seg = ds_test.project_mc_result(seg_id, mc_node) print "Saving Result to", save_path vigra.impex.writeVolume(mc_seg, save_path, '')
def run_mc(ds_train, ds_test, feature_list, mc_params): mc_nodes, _, _, _ = multicut_workflow(ds_train, ds_test, 0, 0, feature_list, mc_params) return ds_test.project_mc_result(0, mc_nodes)
def main(): args = process_command_line() out_folder = args.output_folder assert os.path.exists( out_folder), "Please choose an existing folder for the output" cache_folder = os.path.join(out_folder, "cache") # if the meta set wasn't saved yet, we need to recreate the cache if not os.path.exists(os.path.join(cache_folder, "meta_dict.pkl")): init(args.data_folder, cache_folder) meta = MetaSet(cache_folder) meta.load() ds_train = meta.get_dataset("ds_train") ds_test = meta.get_dataset("ds_test") # experiment settings exp_params = ExperimentSettings() exp_params.set_rfcache(os.path.join(cache_folder, "rf_cache")) # use extra 2d features exp_params.set_use2d(True) # parameters for learning exp_params.set_anisotropy(25.) exp_params.set_learn2d(True) exp_params.set_ignore_mask(False) exp_params.set_ntrees(500) exp_params.set_weighting_scheme("z") exp_params.set_solver("multicut_fusionmoves") local_feats_list = ("raw", "prob", "reg", "topo") lifted_feats_list = ("mc", "cluster", "reg") seg_id = 0 if args.use_lifted: print "Starting Lifted Multicut Workflow" # have to make filters first due to cutouts... ds_train.make_filters(0, exp_params.anisotropy_factor) ds_train.make_filters(1, exp_params.anisotropy_factor) ds_test.make_filters(0, exp_params.anisotropy_factor) ds_test.make_filters(1, exp_params.anisotropy_factor) mc_node, mc_edges, mc_energy, t_inf = lifted_multicut_workflow( ds_train, ds_test, seg_id, seg_id, local_feats_list, lifted_feats_list, exp_params, gamma=2., warmstart=False, weight_z_lifted=True) save_path_seg = os.path.join(out_folder, "lifted_multicut_segmentation.tif") save_path_edge = os.path.join(out_folder, "lifted_multicut_labeling.tif") else: print "Starting Multicut Workflow" mc_node, mc_edges, mc_energy, t_inf = multicut_workflow( ds_train, ds_test, seg_id, seg_id, local_feats_list, exp_params) save_path_seg = os.path.join(out_folder, "multicut_segmentation.tif") save_path_edge = os.path.join(out_folder, "multicut_labeling.tif") mc_seg = ds_test.project_mc_result(seg_id, mc_node) print "Saving Segmentation Result to", save_path_seg vigra.impex.writeVolume(mc_seg, save_path_seg, '') # need to bring results back to the isbi challenge format... edge_vol = edges_to_volume(ds_test._rag(seg_id), mc_edges) print "Saving Edge Labeling Result to", save_path_edge vigra.impex.writeVolume(edge_vol, save_path_edge, '', dtype=np.uint8)