-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgeo_diff_ui.py
More file actions
1291 lines (947 loc) · 52.7 KB
/
geo_diff_ui.py
File metadata and controls
1291 lines (947 loc) · 52.7 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import gradio as gr
import os
from GeoDiffuser.utils.ui_utils import get_mask, get_depth, get_transformed_mask, get_edited_image, correct_depth, inpaint_mask, get_stitched_image, save_exp, read_exp_ui, clear_transforms, get_points, undo_point
from PIL import Image
import numpy as np
from copy import deepcopy
# def run_ui():
LENGTH=512 # length of the square area displaying/editing images
SAM_PATH = "./checkpoints/sam_vit_h_4b8939.pth"
MIDAS_DEPTH_PATH = "./weights/dpt_large-midas-2f21e586.pt"
def show_options():
return gr.Row(visible=True)
def hide_options():
return gr.Row(visible=False)
def copy_image(img):
return deepcopy(img)
def resize_image_to_size(img, h, w):
# print(type(img), type(h), type(w))
h = int(h)
w = int(w)
# print(h, w)
if img is None:
return None
input_img = np.array(Image.fromarray(img).resize((w, h), Image.NEAREST))
return input_img
def resize_image(img):
# print("Resizing image")
input_img = np.array(Image.fromarray(img).resize((LENGTH, LENGTH)))
return input_img, deepcopy(input_img)
def resize_image_bg(img):
# print("Resizing image")
original_h, original_w = img.shape[0], img.shape[1]
input_img = np.array(Image.fromarray(img).resize((LENGTH, LENGTH)))
return input_img, original_h, original_w
def resize_image_and_get_constant_depth(img):
# print("Resizing image")
original_h, original_w = img.shape[0], img.shape[1]
input_img = np.array(Image.fromarray(img).resize((LENGTH, LENGTH)))
depth = np.ones_like(input_img)
depth_image = np.ones_like(input_img)
depth, depth_im_vis = get_depth(input_img, "", depth, depth_image, depth_model = "constant_depth")
return input_img, depth, depth_im_vis, int(original_h), int(original_w)
with gr.Blocks() as demo:
# layout definition
with gr.Row():
gr.Markdown("""
# Official Implementation of Geometry Diffusion Editor: GeoDiffuser
""")
# UI components for editing real images
with gr.Tab(label="Editing Real Image"):
# mask = gr.State(value=None) # store mask
sam_path = gr.State(SAM_PATH)
depth_pt_path = gr.State(MIDAS_DEPTH_PATH)
transform_in = gr.State(value=np.eye(4).astype("float")) # store depth
depth_image = gr.State(value=None) # store depth
selected_points = gr.State([]) # store points
# input_image = gr.State(value=None) # stores unedited input image
# original_image = gr.State(value=None) # store original input image
with gr.Row():
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Input <br> Image </p>""")
input_image = gr.Image(type="numpy", label="Click Points \n",
show_label=True, height=LENGTH, width=LENGTH, interactive=True) # for points clicking
# gr.Markdown("""<p style="text-align: center; font-size: 10px">Foreground Image <br> Please set SAM checkpoint below before clicking on the image </p>""")
with gr.Row():
sam_path = gr.Textbox(label = "SAM checkpoint path. Please change accordingly.", value = SAM_PATH, interactive=True)
with gr.Row():
load_location = gr.Textbox(label = "Load exp directory", value = "/oscar/scratch/rsajnani/rsajnani/research/2023/GeometryDiffuser/dataset/large_scale_study_optimizer_sd_test/Translation_3D/34", interactive=True)
with gr.Row():
load_exp_button = gr.Button("Load Experiment")
# with gr.Row()
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Foreground Image <br> Click Points to Select Object</p>""")
click_points_image = gr.Image(type="numpy", label="Mask Image",
show_label=True, height=LENGTH, width=LENGTH, interactive=False)
with gr.Row():
point_label = gr.Radio(choices=["Positive", "Negative"], value="Positive", label="Point prompt", interactive=True)
undo_button = gr.Button("Undo point")
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Image <br> Mask</p>""")
mask_image = gr.Image(type="numpy", label="Mask Image",
show_label=True, height=LENGTH, width=LENGTH, interactive=False)
with gr.Row():
H_txt = gr.Number(label="Height", value = LENGTH, interactive=False)
W_txt = gr.Number(label="Width", value= LENGTH, interactive=False)
with gr.Row(visible=False):
background_upload = gr.Button("Show Background Image Tab")
with gr.Row(visible=False) as back_tab:
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Foreground <br> Image</p>""")
input_show_image = gr.Image(type="numpy", label="Foreground Image",
show_label=True, height=LENGTH, width=LENGTH, interactive=False)
input_image.upload(fn = resize_image, inputs=[input_image], outputs=[input_show_image, click_points_image])
input_image.change(fn = copy_image, inputs=[input_image], outputs=[click_points_image])
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Background Image for Stitching. <br> Leave Empty for Other Tasks</p>""")
background_image = gr.Image(type="numpy", label="Background Image For Stitching",
show_label=True, height=LENGTH, width=LENGTH, interactive=True)
background_image.upload(fn = resize_image_bg, inputs=[background_image], outputs=[background_image, H_txt, W_txt])
# undo_button = gr.Button("Undo point")
with gr.Row():
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Transformed Image</p>""")
transformed_image = gr.Image(type="numpy", label="Transformed Mask",
show_label=True, height=LENGTH, width=LENGTH, interactive=False) # for points clicking
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Depth Image</p>""")
depth_image_vis = gr.Image(type="numpy", label="Depth Image",
show_label=True, height=LENGTH, width=LENGTH, interactive=False)
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Depth Options </p>""")
with gr.Row():
translate_factor = gr.Slider(label='Push object depth farther away from camera [0-1]',
info='Push object depth farther away from camera [0-1]',
minimum=0,
maximum=5,
step=0.01,
value=0.7)
with gr.Row():
depth_model = gr.Dropdown(label = "Depth Estimator", choices = ["midas_depth", "depth_anything", "constant_depth", "zoe_depth"], value = "depth_anything")
depth_button = gr.Button("Get Depth")
# with gr.Row():
with gr.Row():
depth_pt_path = gr.Textbox(label = "MIDAS checkpoint path checkpoint path", value = MIDAS_DEPTH_PATH, interactive=True)
# with gr.Column():
# gr.Markdown("""<p style="text-align: center; font-size: 20px">Place holder Image</p>""")
# placeholder = gr.Image(type="numpy", label="placeholder",
# show_label=True, height=LENGTH, width=LENGTH, interactive=False)
# undo_button = gr.Button("Undo point")
with gr.Row():
with gr.Column():
with gr.Row():
translation_x = gr.Slider(label='tx',
info='Translation slider along x axis',
minimum=-0.50,
maximum=0.50,
step=0.001,
value=0.0)
translation_y = gr.Slider(label='ty',
info='Translation slider along y axis',
minimum=-0.50,
maximum=0.50,
step=0.001,
value=0.0)
translation_z = gr.Slider(label='tz',
info='Translation slider along z axis',
minimum=-0.50,
maximum=0.50,
step=0.001,
value=0.0)
with gr.Row():
clear_transforms_button = gr.Button("Clear Transforms")
with gr.Column():
with gr.Row():
rotation_x = gr.Slider(label='rx',
info='Rotation slider along x axis',
minimum=-90,
maximum=90,
step=1,
value=0.0)
rotation_y = gr.Slider(label='ry',
info='Rotation slider along y axis',
minimum=-90,
maximum=90,
step=1,
value=0.0)
rotation_z = gr.Slider(label='rz',
info='Rotation slider along z axis',
minimum=-90,
maximum=90,
step=1,
value=0.0)
with gr.Row():
transform_button = gr.Button("Check Transformed Image")
with gr.Column():
with gr.Row():
scale_x = gr.Slider(label='sx',
info='Scale x',
minimum=0.5,
maximum=1.5,
step=0.01,
value=1.0)
scale_y = gr.Slider(label='sy',
info='Scale y',
minimum=0.5,
maximum=1.5,
step=0.01,
value=1.0)
scale_z = gr.Slider(label='sz',
info='Scale z',
minimum=0.5,
maximum=1.5,
step=0.01,
value=1.0)
with gr.Row():
exp_transform_type = gr.Dropdown(label = "Experiment Type", choices = ["Mix", "Rotation_3D", "Translation_3D", "Removal", "Rotation_2D", "Translation_2D", "Scaling"], value = "Mix")
save_location = gr.Textbox(label = "Save Directory Parent Path", value = "./ui_outputs/", interactive=True)
with gr.Row():
save_button = gr.Button("Save Experiment")
with gr.Row(visible=False):
advanced_options_button = gr.Button("View Advanced Options")
# with gr.Row(visible=False):
# movement_panel_show = gr.Button("Show Geometry Editing Loss Weights for Movement")
# with gr.Row(visible=False) as advanced_options:
# with gr.Row():
with gr.Row():
with gr.Accordion("Advanced Editing Options. Open for More!", open=False):
# Not happy with this
# gr.Markdown("""<p style="text-align: center; font-size: 20px">Advanced Options</p>""")
gr.Markdown("""
### Advanced Options
""")
with gr.Row():
guidance_scale = gr.Slider(label='g_scale',
info='Guidance Scale',
minimum=0.0,
maximum=10.0,
step=0.1,
value=3.0)
cross_replace_steps = gr.Slider(label='Cross replace',
info='Cross replace',
minimum=0,
maximum=1,
step=0.01,
value=0.97)
self_replace_steps = gr.Slider(label='Self replace',
info='Self replace',
minimum=0,
maximum=1,
step=0.01,
value=0.97)
# sigma_color = gr.Slider(label='sigma_color bilateral smoothing',
# info='sigma_color bilateral smoothing',
# minimum=0,
# maximum=100,
# step=0.01,
# value=0.1)
# sigma_space = gr.Slider(label='sigma_space bilateral smoothing',
# info='sigma_space bilateral smoothing',
# minimum=0,
# maximum=100,
# step=0.01,
# value=16)
# d_bf_radius = gr.Slider(label='d radius bilateral',
# info='d radius bilateral',
# minimum=0,
# maximum=100,
# step=1,
# value=5)
with gr.Row():
skip_steps = gr.Slider(label='skip_steps',
info='Skip Steps',
minimum=0,
maximum=10,
step=1,
value=2)
latent_replace_steps = gr.Slider(label='Latent replace',
info='Latent replace',
minimum=0,
maximum=1,
step=0.01,
value=0.1)
optimize_steps = gr.Slider(label='Optimize steps',
info='optimize steps',
minimum=0,
maximum=1,
step=0.01,
value=0.65)
fast_optim_steps = gr.Slider(label='Fast Optim Steps',
info='Fast Optim Steps',
minimum=0,
maximum=1,
step=0.01,
value=0.0)
cam_focal_length = gr.Slider(label='cam_focal_length',
info='cam_focal_length',
minimum=0,
maximum=3000,
step=0.1,
value=550)
with gr.Row():
num_ddim_steps = gr.Slider(label='DDIM steps',
info='ddim steps',
minimum=25,
maximum=50,
step=1,
value=50)
num_first_optim_steps = gr.Slider(label='Num first optim steps',
info='Num first optim steps',
minimum=1,
maximum=50,
step=1,
value=1)
optim_lr = gr.Slider(label='learning rate',
info='learning rate',
minimum=0.001,
maximum=10.0,
step=0.001,
value=0.03)
splatting_radius = gr.Slider(label='splatting radius',
info='splatting radius',
minimum=0.0,
maximum=5.0,
step=0.01,
value=1.3)
splatting_tau = gr.Slider(label='splatting tau',
info='splatting tau',
minimum=1e-3,
maximum=2.0,
step=1e-3,
value=1.0)
splatting_points_per_pixel = gr.Slider(label='splatting points per pixel',
info='splatting points per pixel',
minimum=1,
maximum=30,
step=1,
value=15)
# depth_correct_button = gr.Button("Median Filter on Depth")
# with gr.Row(visible=True) as movement_options:
with gr.Row():
with gr.Accordion("Movement Loss Control", open=False):
gr.Markdown("""<p style="text-align: center; font-size: 20px">Movement loss</p>""")
with gr.Row():
movement_sim_loss_w_self = gr.Slider(label='Background loss (self)',
info='background loss (self)',
minimum=0.0,
maximum=1000,
step=0.001,
value=55.0)
movement_sim_loss_w_cross = gr.Slider(label='Background loss (cross)',
info='background loss (cross)',
minimum=0.0,
maximum=1000.0,
step=0.001,
value=45.0)
movement_removal_loss_w_self = gr.Slider(label='loss removal_scale (self)',
info='loss removal_scale (self)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=2.6)
movement_removal_loss_w_cross = gr.Slider(label='loss removal_scale (cross)',
info='loss removal_scale (cross)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=2.6)
removal_loss_adaptive_value = gr.Slider(label='Removal Loss Adaptive Value',
info='Value after which stop adaptive optimization',
minimum=-30.0,
maximum=0.0,
step=0.01,
value=-2.5)
with gr.Row():
movement_loss_w_self = gr.Slider(label='foreground preservation loss (self)',
info='foreground preservation loss (self)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=30.5)
movement_loss_w_cross = gr.Slider(label='foreground preservation loss (cross)',
info='foreground preservation loss (cross)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=30.34)
amodal_loss_w_self = gr.Slider(label='amodal loss (self)',
info='amodal loss (self)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=80.5)
amodal_loss_w_cross = gr.Slider(label='amodal loss (cross)',
info='amodal loss (cross)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=3.5)
with gr.Row():
movement_smoothness_loss_w_self = gr.Slider(label='loss movement_smoothness (self)',
info='loss movement_smoothness (self)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=30)
movement_smoothness_loss_w_cross = gr.Slider(label='loss movement_smoothness (cross)',
info='loss movement_smoothness (cross)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=15)
diffusion_correction = gr.Slider(label='Diffusion Correction',
info='Diffusion Correction vs Edit Adherance. Setting high diffusion correction (~0.6-1.0) reduces edit adherance and does not perform the edit',
minimum=0.0,
maximum=0.4,
step=0.01,
value=0.1)
with gr.Row():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Scroll Below for Input and Edited Image in Original Aspect Ratio.</p>""")
with gr.Row():
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Edited Image</p>""")
edited_image = gr.Image(type="numpy", label="Edited Image",
show_label=True, height=LENGTH, width=LENGTH, interactive=False)
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Editing Options</p>""")
with gr.Row():
prompt = gr.Textbox(info="Prompt for Editing (Optional)", value="")
# Add feature later!
with gr.Row():
diffusion_model = gr.Dropdown(label = "Diffusion Model", choices = [
"CompVis/stable-diffusion-v1-4",
"runwayml/stable-diffusion-v1-5",
"stabilityai/stable-diffusion-2-base",
"stabilityai/stable-diffusion-2-1-base"],
value = "CompVis/stable-diffusion-v1-4")
edit_button = gr.Button("Move Object")
with gr.Row():
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Input image in original aspect ratio</p>""")
download_image_input = gr.Image(type="numpy", label="Download Input Image",
show_label=True, height=LENGTH, width=LENGTH, interactive=False)
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Edited image in original aspect ratio</p>""")
download_image = gr.Image(type="numpy", label="Download Image",
show_label=True, height=LENGTH, width=LENGTH, interactive=False)
with gr.Row(visible=False) as stitching_options:
# movement_panel_hide = gr.Button("Hide Movement Panel")
gr.Markdown("""<p style="text-align: center; font-size: 20px">Stitching loss</p>""")
with gr.Column():
stitching_sim_loss_w_self = gr.Slider(label='Background preservation loss (self)',
info='background preservation loss (self)',
minimum=0.0,
maximum=1000.0,
step=0.001,
value=20.0)
stitching_sim_loss_w_cross = gr.Slider(label='Background preservation loss (cross)',
info='background preservation loss (cross)',
minimum=0.0,
maximum=1000.0,
step=0.001,
value=2.5)
stitching_sim_loss_out_w_self = gr.Slider(label='Background loss Out (self)',
info='background loss Out (self)',
minimum=0.0,
maximum=1000.0,
step=0.001,
value=120)
stitching_sim_loss_out_w_cross = gr.Slider(label='Background loss Out (cross)',
info='background loss Out (cross)',
minimum=0.0,
maximum=1000.0,
step=0.001,
value=30)
with gr.Column():
stitching_movement_loss_w_self = gr.Slider(label='movement loss (self)',
info='movement loss (self)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=40)
stitching_movement_loss_w_cross = gr.Slider(label='movement loss (cross)',
info='movement loss (cross)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=5)
stitching_movement_loss_out_w_self = gr.Slider(label='movement_out loss (self)',
info='movement_out loss (self)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=40.0)
stitching_movement_loss_out_w_cross = gr.Slider(label='movement_out loss (cross)',
info='movement_out loss (cross)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=30.0)
with gr.Column():
stitching_smoothness_loss_w_self = gr.Slider(label='loss stitching_smoothness (self)',
info='loss stitching_smoothness (self)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=2.0)
stitching_smoothness_loss_w_cross = gr.Slider(label='loss stitching_smoothness (cross)',
info='loss stitching_smoothness (cross)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=1.0)
# stitch_panel_hide = gr.Button("Hide Stitching Panel")
stitch_button = gr.Button("Stitch Image")
# with gr.Row():
# with gr.Column():
# gr.Markdown("""<p style="text-align: center; font-size: 20px">Input image in original aspect ratio</p>""")
# download_image_input = gr.Image(type="numpy", label="Download Input Image",
# show_label=True, height=LENGTH, width=LENGTH, interactive=False)
# with gr.Column():
# gr.Markdown("""<p style="text-align: center; font-size: 20px">Edited image in original aspect ratio</p>""")
# download_image = gr.Image(type="numpy", label="Download Image",
# show_label=True, height=LENGTH, width=LENGTH, interactive=False)
with gr.Tab(label="Inpainting"):
# mask = gr.State(value=None) # store mask
# transform_in = gr.State(value=np.eye(4).astype("float")) # store depth
# depth_image = gr.State(value=None) # store depth
selected_points_inpainting = gr.State([]) # store points
# original_image = gr.State(value=None) # store original input image
with gr.Row():
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Foreground <br> Image</p>""")
input_image_inpainting = gr.Image(type="numpy", label="Input Image \n",
show_label=True, height=LENGTH, width=LENGTH, interactive=True)
with gr.Row():
sam_path_inpainting = gr.Textbox(label = "SAM checkpoint path", value = SAM_PATH, interactive=True)
# depth_pt_path = gr.State(MIDAS_DEPTH_PATH)
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Foreground Image <br> Click Points to Select Object</p>""")
click_points_image_inpainting = gr.Image(type="numpy", label="Mask Image",
show_label=True, height=LENGTH, width=LENGTH, interactive=False)
input_image_inpainting.change(fn = copy_image, inputs=[input_image_inpainting], outputs=[click_points_image_inpainting])
with gr.Row():
point_label_inpainting = gr.Radio(choices=["Positive", "Negative"], value="Positive", label="Point prompt", interactive=True)
undo_button_inpainting = gr.Button("Undo point")
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Image <br> Mask</p>""")
mask_image_inpainting = gr.Image(type="numpy", label="Mask Image",
show_label=True, height=LENGTH, width=LENGTH, interactive=False)
with gr.Row():
H_txt_inpainting = gr.Number(label="Height", value = LENGTH, interactive=False)
W_txt_inpainting = gr.Number(label="Width", value=LENGTH, interactive=False)
with gr.Row(visible=False):
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Transformed Image</p>""")
transformed_image_inpainting = gr.Image(type="numpy", label="Transformed Mask",
show_label=True, height=LENGTH, width=LENGTH, interactive=False) # for points clicking
with gr.Row():
# with gr.Row(visible=False):
# inpainting_loss_button = gr.Button("Show inpainting loss weights")
# with gr.Row(visible=False):
# stitching_loss_button = gr.Button("Show stitching loss weights")
with gr.Column():
with gr.Row():
load_location_inpainting = gr.Textbox(label = "Load exp directory", value = "./ui_outputs/rotation_2/3/", interactive=True)
with gr.Row():
load_exp_button_inpainting = gr.Button("Load Experiment")
with gr.Column():
with gr.Row():
exp_transform_type_inpainting = gr.Dropdown(label = "Experiment Type", choices = ["Mix", "Rotation_3D", "Translation_3D", "Removal", "Rotation_2D", "Translation_2D", "Scaling", "Inpainting"], value = "Inpainting")
save_location_inpainting = gr.Textbox(label = "Save Directory Parent Path", value = "./ui_outputs/", interactive=True)
with gr.Row():
save_button_inpainting = gr.Button("Save Experiment")
# with gr.Row():
# advanced_options_button_inpainting = gr.Button("View Advanced Options")
with gr.Accordion("Advanced Inpainting Options. Open for More!", open=False):
# Not happy with this
# gr.Markdown("""<p style="text-align: center; font-size: 20px">Advanced Options</p>""")
gr.Markdown("""
### Advanced Options
""")
with gr.Row():
guidance_scale_inpainting = gr.Slider(label='g_scale',
info='Guidance Scale',
minimum=0.0,
maximum=10.0,
step=0.1,
value=5.0)
cross_replace_steps_inpainting = gr.Slider(label='Cross replace',
info='Cross replace',
minimum=0,
maximum=1,
step=0.01,
value=0.95)
self_replace_steps_inpainting = gr.Slider(label='Self replace',
info='Self replace',
minimum=0,
maximum=1,
step=0.01,
value=0.95)
translate_factor_inpainting = gr.Slider(label='Push object depth farther away from camera [0-1]',
info='Push object depth farther away from camera [0-1]',
minimum=0,
maximum=1,
step=0.01,
value=0.1)
# obj_edit_step_inpainting = gr.Slider(label='obj_edit_step',
# info='obj_edit_step',
# minimum=0,
# maximum=1,
# step=0.01,
# value=0.7)
# sigma_color_inpainting = gr.Slider(label='sigma_color bilateral smoothing',
# info='sigma_color bilateral smoothing',
# minimum=0,
# maximum=100,
# step=0.01,
# value=0.1)
# sigma_space_inpainting = gr.Slider(label='sigma_space bilateral smoothing',
# info='sigma_space bilateral smoothing',
# minimum=0,
# maximum=100,
# step=0.01,
# value=16)
# d_bf_radius_inpainting = gr.Slider(label='d radius bilateral',
# info='d radius bilateral',
# minimum=0,
# maximum=100,
# step=1,
# value=5)
with gr.Row():
skip_steps_inpainting = gr.Slider(label='skip_steps',
info='Skip Steps',
minimum=0,
maximum=10,
step=1,
value=2)
latent_replace_steps_inpainting = gr.Slider(label='Latent replace',
info='Latent replace',
minimum=0,
maximum=1,
step=0.01,
value=0.1)
optimize_steps_inpainting = gr.Slider(label='Optimize steps',
info='optimize steps',
minimum=0,
maximum=1,
step=0.01,
value=0.65)
fast_optim_steps_inpainting = gr.Slider(label='Fast Optim Steps',
info='Fast Optim Steps',
minimum=0,
maximum=1,
step=0.01,
value=0.0)
cam_focal_length_inpainting = gr.Slider(label='cam_focal_length',
info='cam_focal_length',
minimum=0,
maximum=3000,
step=0.1,
value=550)
with gr.Row():
num_ddim_steps_inpainting = gr.Slider(label='DDIM steps',
info='ddim steps',
minimum=25,
maximum=50,
step=1,
value=50)
num_first_optim_steps_inpainting = gr.Slider(label='Num first optim steps',
info='Num first optim steps',
minimum=1,
maximum=50,
step=1,
value=1)
optim_lr_inpainting = gr.Slider(label='learning rate',
info='learning rate',
minimum=0.001,
maximum=10.0,
step=0.001,
value=0.03)
splatting_radius_inpainting = gr.Slider(label='splatting radius',
info='splatting radius',
minimum=0.0,
maximum=5.0,
step=0.01,
value=1.3)
splatting_tau_inpainting = gr.Slider(label='splatting tau',
info='splatting tau',
minimum=1e-3,
maximum=2.0,
step=1e-3,
value=1.0)
splatting_points_per_pixel_inpainting = gr.Slider(label='splatting points per pixel',
info='splatting points per pixel',
minimum=1,
maximum=30,
step=1,
value=15)
# depth_correct_button = gr.Button("Median Filter on Depth")
# with gr.Row(visible=True) as inpainting_options:
with gr.Accordion("Inpainting Loss Control", open=False):
gr.Markdown("""<p style="text-align: center; font-size: 20px">Inpainting loss</p>""")
with gr.Row():
inpainting_sim_loss_w_self = gr.Slider(label='Background preservation loss (self)',
info='background preservation loss (self)',
minimum=0.0,
maximum=1000.0,
step=0.001,
value=55.0)
inpainting_sim_loss_w_cross = gr.Slider(label='Background preservation loss (cross)',
info='background preservation loss (cross)',
minimum=0.0,
maximum=1000.0,
step=0.001,
value=45.0)
with gr.Row():
inpainting_removal_loss_w_self = gr.Slider(label='Removal Loss (self)',
info='Removal Loss (self)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=4.6)
inpainting_removal_loss_w_cross = gr.Slider(label='Removal Loss (cross)',
info='Removal Loss (cross)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=4.6)
removal_loss_adaptive_value_inpainting = gr.Slider(label='Removal Loss Adaptive Value',
info='Value after which stop adaptive optimization',
minimum=-30.0,
maximum=0,
step=0.01,
value=-2.5)
with gr.Row():
inpainting_smoothness_loss_w_self = gr.Slider(label='loss inpainting_smoothness (self)',
info='loss inpainting_smoothness (self)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=30)
inpainting_smoothness_loss_w_cross = gr.Slider(label='loss inpainting_smoothness (cross)',
info='loss inpainting_smoothness (cross)',
minimum=0.0,
maximum=1000.0,
step=0.01,
value=15)
# with gr.Row(visible=False):
# inpaint_panel_hide = gr.Button("Hide Inpainting Panel")
with gr.Row():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Scroll Below for Input and Edited Image in Original Aspect Ratio.</p>""")
with gr.Row():
with gr.Column():
gr.Markdown("""<p style="text-align: center; font-size: 20px">Edited Image</p>""")
edited_image_inpainting = gr.Image(type="numpy", label="Edited Image",