From b0b09d6788778541d1c0b89ca96101fc57d60e22 Mon Sep 17 00:00:00 2001 From: Leonid Kostrykin Date: Wed, 7 Feb 2024 15:17:50 +0100 Subject: [PATCH] Fix bugs --- tools/superdsm/run-superdsm.py | 36 +++++++----- tools/superdsm/superdsm.xml | 4 +- tools/superdsm/test-data/cfg-full.tsv | 68 ++++++++++++++++++++++ tools/superdsm/test-data/cfg.tsv | 84 ++++++--------------------- 4 files changed, 111 insertions(+), 81 deletions(-) create mode 100644 tools/superdsm/test-data/cfg-full.tsv diff --git a/tools/superdsm/run-superdsm.py b/tools/superdsm/run-superdsm.py index 0db11b6e..1e57cb74 100644 --- a/tools/superdsm/run-superdsm.py +++ b/tools/superdsm/run-superdsm.py @@ -17,15 +17,15 @@ hyperparameters = [ ('AF_scale', float), - ('c2f_region_analysis/min_atom_radius', float), - ('c2f_region_analysis/min_norm_energy_improvement', float), - ('c2f_region_analysis/max_atom_norm_energy', float), - ('c2f_region_analysis/max_cluster_marker_irregularity', float), + ('c2f-region-analysis/min_atom_radius', float), + ('c2f-region-analysis/min_norm_energy_improvement', float), + ('c2f-region-analysis/max_atom_norm_energy', float), + ('c2f-region-analysis/max_cluster_marker_irregularity', float), ('dsm/alpha', float), ('dsm/AF_alpha', float), - ('global_energy_minimization/pruning', str), - ('global_energy_minimization/beta', float), - ('global_energy_minimization/AF_beta', float), + ('global-energy-minimization/pruning', str), + ('global-energy-minimization/beta', float), + ('global-energy-minimization/AF_beta', float), ('postprocess/mask_max_distance', int), ('postprocess/mask_stdamp', float), ('postprocess/max_norm_energy', float), @@ -35,7 +35,7 @@ def get_param_name(key): - return key.replace('/', '_') + return key.replace('/', '_').replace('-', '_') def create_config(args): @@ -97,24 +97,32 @@ def flatten_dict(d, sep='/'): cfg = create_config(args) img = superdsm.io.imread(img_filepath) + # Create configuration if it is required: + if args.do_cfg or args.do_overlay or args.do_masks: + cfg, _ = superdsm.automation.create_config(pipeline, cfg, img) + + # Perform segmentation if it is required: + if args.do_overlay or args.do_masks: + print('Performing segmentation') + data, cfg, _ = pipeline.process_image(img, cfg) + + # Write configuration used for segmentation, or the automatically created one, otherwise: if args.do_cfg: print(f'Writing config to: {args.do_cfg}') - cfg, _ = superdsm.automation.create_config(pipeline, cfg, img) with open(args.do_cfg, 'w') as fp: tsv_out = csv.writer(fp, delimiter='\t') tsv_out.writerow(['Hyperparameter', 'Value']) - for key, value in flatten_dict(cfg.entries).items(): + rows = sorted(flatten_dict(cfg.entries).items(), key=lambda item: item[0]) + for key, value in rows: tsv_out.writerow([key, value]) - if args.do_overlay or args.do_masks: - print('Performing segmentation') - data, cfg, _ = pipeline.process_image(img, cfg) - + # Write the overlay image: if args.do_overlay: print(f'Writing overlay to: {args.do_overlay}') overlay = superdsm.render.render_result_over_image(data, border_width=args.do_overlay_border, normalize_img=False) superdsm.io.imwrite(args.do_overlay, overlay) + # Write the label map: if args.do_masks: print(f'Writing masks to: {args.do_masks}') masks = superdsm.render.rasterize_labels(data) diff --git a/tools/superdsm/superdsm.xml b/tools/superdsm/superdsm.xml index d5c3a144..814899ef 100644 --- a/tools/superdsm/superdsm.xml +++ b/tools/superdsm/superdsm.xml @@ -120,7 +120,7 @@ - + @@ -160,7 +160,7 @@ - + diff --git a/tools/superdsm/test-data/cfg-full.tsv b/tools/superdsm/test-data/cfg-full.tsv new file mode 100644 index 00000000..cbc5961f --- /dev/null +++ b/tools/superdsm/test-data/cfg-full.tsv @@ -0,0 +1,68 @@ +Hyperparameter Value +AF_scale +c2f-region-analysis/AF_min_atom_radius 0.33 +c2f-region-analysis/enabled True +c2f-region-analysis/max_atom_norm_energy 0.05 +c2f-region-analysis/max_cluster_marker_irregularity 0.2 +c2f-region-analysis/min_atom_radius 30 +c2f-region-analysis/min_norm_energy_improvement 0.1 +c2f-region-analysis/seed_connectivity 8 +dsm/AF_alpha 0.0005 +dsm/AF_background_margin 0.4 +dsm/AF_smooth_amount 0.2 +dsm/AF_smooth_subsample 0.4 +dsm/alpha 2.116 +dsm/background_margin 26 +dsm/cachesize 1 +dsm/cachetest +dsm/cp_timeout 300 +dsm/enabled True +dsm/epsilon 1.0 +dsm/gaussian_shape_multiplier 2 +dsm/init elliptical +dsm/scale 1000 +dsm/smooth_amount 13 +dsm/smooth_mat_dtype float32 +dsm/smooth_mat_max_allocations inf +dsm/smooth_subsample 26 +dsm/sparsity_tol 0 +global-energy-minimization/AF_beta 0.66 +global-energy-minimization/AF_max_seed_distance inf +global-energy-minimization/beta 2793.1200000000003 +global-energy-minimization/enabled True +global-energy-minimization/gamma 0.8 +global-energy-minimization/max_iter 5 +global-energy-minimization/max_seed_distance inf +global-energy-minimization/max_work_amount 1000000 +global-energy-minimization/pruning exact +histological False +postprocess/AF_max_object_radius inf +postprocess/AF_min_glare_radius inf +postprocess/AF_min_object_radius 0.0 +postprocess/contrast_epsilon 0.0001 +postprocess/discard_image_boundary False +postprocess/enabled True +postprocess/exterior_offset 5 +postprocess/exterior_scale 5 +postprocess/fill_holes True +postprocess/glare_detection_min_layer 0.5 +postprocess/glare_detection_num_layers 5 +postprocess/glare_detection_smoothness 3 +postprocess/mask_max_distance 1 +postprocess/mask_smoothness 3 +postprocess/mask_stdamp 2.0 +postprocess/max_boundary_eccentricity inf +postprocess/max_eccentricity 0.99 +postprocess/max_norm_energy 0.2 +postprocess/max_object_radius inf +postprocess/min_boundary_glare_radius inf +postprocess/min_boundary_obj_radius 0 +postprocess/min_contrast 1.35 +postprocess/min_glare_radius inf +postprocess/min_object_radius 0.0 +preprocess/AF_sigma2 1.0 +preprocess/enabled True +preprocess/lower_clip_mean False +preprocess/offset_clip 3 +preprocess/sigma1 1.4142135623730951 +preprocess/sigma2 65.05382386916237 diff --git a/tools/superdsm/test-data/cfg.tsv b/tools/superdsm/test-data/cfg.tsv index eaf69936..71c18cf0 100644 --- a/tools/superdsm/test-data/cfg.tsv +++ b/tools/superdsm/test-data/cfg.tsv @@ -1,78 +1,32 @@ Hyperparameter Value -c2f_region_analysis_min_norm_energy_improvement 0.1 -c2f_region_analysis_max_atom_norm_energy 0.05 -c2f_region_analysis_max_cluster_marker_irregularity 0.2 -dsm_AF_alpha 0.0005 -global_energy_minimization_AF_beta 0.66 -postprocess_mask_max_distance 1 -postprocess_mask_stdamp 2.0 -postprocess_max_norm_energy 0.2 -postprocess_min_contrast 1.35 -postprocess_min_object_radius 0.0 AF_scale -preprocess/AF_sigma2 1.0 -preprocess/sigma2 65.05382386916237 -preprocess/enabled True -preprocess/sigma1 1.4142135623730951 -preprocess/offset_clip 3 -preprocess/lower_clip_mean False +c2f-region-analysis/AF_min_atom_radius 0.33 +c2f-region-analysis/max_atom_norm_energy 0.05 +c2f-region-analysis/max_cluster_marker_irregularity 0.2 +c2f-region-analysis/min_atom_radius 30 +c2f-region-analysis/min_norm_energy_improvement 0.1 dsm/AF_alpha 0.0005 -dsm/alpha 2.116 +dsm/AF_background_margin 0.4 dsm/AF_smooth_amount 0.2 -dsm/smooth_amount 13 dsm/AF_smooth_subsample 0.4 -dsm/smooth_subsample 26 -dsm/AF_background_margin 0.4 +dsm/alpha 2.116 dsm/background_margin 26 -dsm/enabled True -dsm/cachesize 1 -dsm/cachetest -dsm/sparsity_tol 0 -dsm/init elliptical -dsm/epsilon 1.0 -dsm/scale 1000 -dsm/gaussian_shape_multiplier 2 -dsm/smooth_mat_dtype float32 -dsm/smooth_mat_max_allocations inf -dsm/cp_timeout 300 -c2f-region-analysis/AF_min_atom_radius 0.33 -c2f-region-analysis/min_atom_radius 30 -c2f-region-analysis/enabled True -c2f-region-analysis/seed_connectivity 8 -c2f-region-analysis/max_atom_norm_energy 0.05 -c2f-region-analysis/min_norm_energy_improvement 0.1 -c2f-region-analysis/max_cluster_marker_irregularity 0.2 +dsm/smooth_amount 13 +dsm/smooth_subsample 26 global-energy-minimization/AF_beta 0.66 -global-energy-minimization/beta 2793.1200000000003 global-energy-minimization/AF_max_seed_distance inf +global-energy-minimization/beta 2793.1200000000003 global-energy-minimization/max_seed_distance inf -global-energy-minimization/enabled True -global-energy-minimization/strict True -global-energy-minimization/max_iter 5 -global-energy-minimization/gamma 0.8 -global-energy-minimization/max_work_amount 1000000 -postprocess/AF_min_object_radius 0.0 -postprocess/min_object_radius 0.0 +global-energy-minimization/pruning exact postprocess/AF_max_object_radius inf -postprocess/max_object_radius inf postprocess/AF_min_glare_radius inf -postprocess/min_glare_radius inf -postprocess/enabled True +postprocess/AF_min_object_radius 0.0 +postprocess/mask_max_distance 1 +postprocess/mask_stdamp 2.0 postprocess/max_norm_energy 0.2 -postprocess/discard_image_boundary False -postprocess/min_boundary_obj_radius 0 -postprocess/max_eccentricity 0.99 -postprocess/max_boundary_eccentricity inf -postprocess/exterior_scale 5 -postprocess/exterior_offset 5 +postprocess/max_object_radius inf postprocess/min_contrast 1.35 -postprocess/contrast_epsilon 0.0001 -postprocess/mask_stdamp 2 -postprocess/mask_max_distance 1 -postprocess/mask_smoothness 3 -postprocess/fill_holes True -postprocess/glare_detection_smoothness 3 -postprocess/glare_detection_num_layers 5 -postprocess/glare_detection_min_layer 0.5 -postprocess/min_boundary_glare_radius inf -histological False +postprocess/min_glare_radius inf +postprocess/min_object_radius 0.0 +preprocess/AF_sigma2 1.0 +preprocess/sigma2 65.05382386916237