huzey commited on
Commit
044c4c8
1 Parent(s): 2b5e956

update rec

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -206,6 +206,9 @@ def ncut_run(
206
  recursion_l2_n_eigs=50,
207
  recursion_l3_n_eigs=20,
208
  recursion_metric="euclidean",
 
 
 
209
  video_output=False,
210
  ):
211
  logging_str = ""
@@ -395,6 +398,9 @@ def run_fn(
395
  recursion_l2_n_eigs=50,
396
  recursion_l3_n_eigs=20,
397
  recursion_metric="euclidean",
 
 
 
398
  ):
399
 
400
  if images is None:
@@ -440,6 +446,9 @@ def run_fn(
440
  "recursion_l2_n_eigs": recursion_l2_n_eigs,
441
  "recursion_l3_n_eigs": recursion_l3_n_eigs,
442
  "recursion_metric": recursion_metric,
 
 
 
443
  "video_output": video_output,
444
  }
445
  # print(kwargs)
@@ -596,8 +605,7 @@ def make_output_images_section():
596
 
597
  def make_parameters_section():
598
  gr.Markdown("### Parameters <a style='color: #0044CC;' href='https://ncut-pytorch.readthedocs.io/en/latest/how_to_get_better_segmentation/' target='_blank'>Help</a>")
599
- # from ncut_pytorch.backbone import list_models, get_demo_model_names
600
- from backbone import list_models, get_demo_model_names
601
  model_names = list_models()
602
  model_names = sorted(model_names)
603
  model_dropdown = gr.Dropdown(model_names, label="Backbone", value="DiNO(dino_vitb8_448)", elem_id="model_name")
@@ -608,7 +616,7 @@ def make_parameters_section():
608
  def change_layer_slider(model_name):
609
  # SD2, UNET
610
  if "stable" in model_name.lower() and "diffusion" in model_name.lower():
611
- from backbone import SD_KEY_DICT
612
  default_layer = 'up_2_resnets_1_block' if 'diffusion-3' not in model_name else 'block_23'
613
  return (gr.Slider(1, 49, step=1, label="Diffusion: Timestep (Noise)", value=5, elem_id="layer", visible=True, info="Noise level, 50 is max noise"),
614
  gr.Dropdown(SD_KEY_DICT[model_name], label="Diffusion: Layer and Node", value=default_layer, elem_id="node_type", info="From the SD U-Net"))
@@ -760,7 +768,9 @@ with demo:
760
  l2_num_eig_slider = gr.Slider(1, 1000, step=1, label="Recursion #2: N eigenvectors", value=50, elem_id="l2_num_eig")
761
  l3_num_eig_slider = gr.Slider(1, 1000, step=1, label="Recursion #3: N eigenvectors", value=50, elem_id="l3_num_eig")
762
  metric_dropdown = gr.Dropdown(["euclidean", "cosine"], label="Recursion distance metric", value="cosine", elem_id="recursion_metric")
763
-
 
 
764
  [
765
  model_dropdown, layer_slider, node_type_dropdown, num_eig_slider,
766
  affinity_focal_gamma_slider, num_sample_ncut_slider, knn_ncut_slider,
@@ -769,6 +779,7 @@ with demo:
769
  sampling_method_dropdown
770
  ] = make_parameters_section()
771
  num_eig_slider.visible = False
 
772
  # logging text box
773
  with gr.Row():
774
  with gr.Column(scale=5, min_width=200):
@@ -802,7 +813,8 @@ with demo:
802
  embedding_method_dropdown, num_sample_tsne_slider, knn_tsne_slider,
803
  perplexity_slider, n_neighbors_slider, min_dist_slider, sampling_method_dropdown,
804
  false_placeholder, number_placeholder, true_placeholder,
805
- l2_num_eig_slider, l3_num_eig_slider, metric_dropdown,
 
806
  ],
807
  outputs=[l1_gallery, l2_gallery, l3_gallery, logging_text],
808
  api_name="API_RecursiveCut"
 
206
  recursion_l2_n_eigs=50,
207
  recursion_l3_n_eigs=20,
208
  recursion_metric="euclidean",
209
+ recursion_l1_gamma=0.5,
210
+ recursion_l2_gamma=0.5,
211
+ recursion_l3_gamma=0.5,
212
  video_output=False,
213
  ):
214
  logging_str = ""
 
398
  recursion_l2_n_eigs=50,
399
  recursion_l3_n_eigs=20,
400
  recursion_metric="euclidean",
401
+ recursion_l1_gamma=0.5,
402
+ recursion_l2_gamma=0.5,
403
+ recursion_l3_gamma=0.5,
404
  ):
405
 
406
  if images is None:
 
446
  "recursion_l2_n_eigs": recursion_l2_n_eigs,
447
  "recursion_l3_n_eigs": recursion_l3_n_eigs,
448
  "recursion_metric": recursion_metric,
449
+ "recursion_l1_gamma": recursion_l1_gamma,
450
+ "recursion_l2_gamma": recursion_l2_gamma,
451
+ "recursion_l3_gamma": recursion_l3_gamma,
452
  "video_output": video_output,
453
  }
454
  # print(kwargs)
 
605
 
606
  def make_parameters_section():
607
  gr.Markdown("### Parameters <a style='color: #0044CC;' href='https://ncut-pytorch.readthedocs.io/en/latest/how_to_get_better_segmentation/' target='_blank'>Help</a>")
608
+ from ncut_pytorch.backbone import list_models, get_demo_model_names
 
609
  model_names = list_models()
610
  model_names = sorted(model_names)
611
  model_dropdown = gr.Dropdown(model_names, label="Backbone", value="DiNO(dino_vitb8_448)", elem_id="model_name")
 
616
  def change_layer_slider(model_name):
617
  # SD2, UNET
618
  if "stable" in model_name.lower() and "diffusion" in model_name.lower():
619
+ from ncut_pytorch.backbone import SD_KEY_DICT
620
  default_layer = 'up_2_resnets_1_block' if 'diffusion-3' not in model_name else 'block_23'
621
  return (gr.Slider(1, 49, step=1, label="Diffusion: Timestep (Noise)", value=5, elem_id="layer", visible=True, info="Noise level, 50 is max noise"),
622
  gr.Dropdown(SD_KEY_DICT[model_name], label="Diffusion: Layer and Node", value=default_layer, elem_id="node_type", info="From the SD U-Net"))
 
768
  l2_num_eig_slider = gr.Slider(1, 1000, step=1, label="Recursion #2: N eigenvectors", value=50, elem_id="l2_num_eig")
769
  l3_num_eig_slider = gr.Slider(1, 1000, step=1, label="Recursion #3: N eigenvectors", value=50, elem_id="l3_num_eig")
770
  metric_dropdown = gr.Dropdown(["euclidean", "cosine"], label="Recursion distance metric", value="cosine", elem_id="recursion_metric")
771
+ l1_affinity_focal_gamma_slider = gr.Slider(0.01, 1, step=0.01, label="Recursion #1: Affinity focal gamma", value=0.5, elem_id="recursion_l1_gamma")
772
+ l2_affinity_focal_gamma_slider = gr.Slider(0.01, 1, step=0.01, label="Recursion #2: Affinity focal gamma", value=0.5, elem_id="recursion_l2_gamma")
773
+ l3_affinity_focal_gamma_slider = gr.Slider(0.01, 1, step=0.01, label="Recursion #3: Affinity focal gamma", value=0.5, elem_id="recursion_l3_gamma")
774
  [
775
  model_dropdown, layer_slider, node_type_dropdown, num_eig_slider,
776
  affinity_focal_gamma_slider, num_sample_ncut_slider, knn_ncut_slider,
 
779
  sampling_method_dropdown
780
  ] = make_parameters_section()
781
  num_eig_slider.visible = False
782
+ affinity_focal_gamma_slider.visible = False
783
  # logging text box
784
  with gr.Row():
785
  with gr.Column(scale=5, min_width=200):
 
813
  embedding_method_dropdown, num_sample_tsne_slider, knn_tsne_slider,
814
  perplexity_slider, n_neighbors_slider, min_dist_slider, sampling_method_dropdown,
815
  false_placeholder, number_placeholder, true_placeholder,
816
+ l2_num_eig_slider, l3_num_eig_slider, metric_dropdown,
817
+ l1_affinity_focal_gamma_slider, l2_affinity_focal_gamma_slider, l3_affinity_focal_gamma_slider
818
  ],
819
  outputs=[l1_gallery, l2_gallery, l3_gallery, logging_text],
820
  api_name="API_RecursiveCut"