Skip to content

Commit cd1d73e

Browse files
committed
Fix run_3dphoto_videos parameters leaking into run_depthmap
Large refactor part, may be broken
1 parent 3556223 commit cd1d73e

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

scripts/depthmap.py

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,15 @@ def main_ui_panel(is_depth_tab):
200200
inp += "mesh_occlude", gr.Checkbox(label="Remove occluded edges", value=True, visible=True)
201201
inp += "mesh_spherical", gr.Checkbox(label="Equirectangular projection", value=False, visible=True)
202202

203-
with gr.Group(visible=is_depth_tab):
204-
with gr.Row():
205-
inp += "inpaint", gr.Checkbox(
206-
label="Generate 3D inpainted mesh. (Sloooow, required for generating videos)", value=False,
207-
visible=is_depth_tab)
208-
with gr.Row(visible=False) as inpaint_options_row_0:
209-
inp += "inpaint_vids", gr.Checkbox(label="Generate 4 demo videos with 3D inpainted mesh.", value=False,
210-
visible=is_depth_tab)
203+
if is_depth_tab:
204+
with gr.Group():
205+
with gr.Row():
206+
inp += "inpaint", gr.Checkbox(
207+
label="Generate 3D inpainted mesh. (Sloooow, required for generating videos)", value=False)
208+
with gr.Group(visible=False) as inpaint_options_row_0:
209+
inp += "inpaint_vids", gr.Checkbox(
210+
label="Generate 4 demo videos with 3D inpainted mesh.", value=False)
211+
gr.HTML("More options can be found in the Generate video tab")
211212

212213
with gr.Group():
213214
with gr.Row():
@@ -408,8 +409,6 @@ def run_depthmap(processed, outpath, inputimages, inputnames, inp, background_re
408409
custom_depthmap = inp["custom_depthmap"] if "custom_depthmap" in inp else "False"
409410
custom_depthmap_img = inp["custom_depthmap_img"] if "custom_depthmap_img" in inp else None
410411
depthmap_batch_reuse = inp["depthmap_batch_reuse"] if "depthmap_batch_reuse" in inp else True
411-
fnExt = inp["fnExt"] if "fnExt" in inp else "mp4"
412-
vid_ssaa = inp["vid_ssaa"] if "vid_ssaa" in inp else 0
413412

414413
print(f"\n{scriptname} {scriptversion} ({get_commit_hash()})")
415414

@@ -923,7 +922,7 @@ def run_depthmap(processed, outpath, inputimages, inputnames, inp, background_re
923922
try:
924923
if inpaint:
925924
unload_sd_model()
926-
mesh_fi = run_3dphoto(device, inpaint_imgs, inpaint_depths, inputnames, outpath, fnExt, vid_ssaa, inpaint_vids)
925+
mesh_fi = run_3dphoto(device, inpaint_imgs, inpaint_depths, inputnames, outpath, inpaint_vids, 1, "mp4")
927926
finally:
928927
reload_sd_model()
929928
print("All done.")
@@ -968,7 +967,7 @@ def get_uniquefn(outpath, basename, ext):
968967
return basename
969968

970969

971-
def run_3dphoto(device, img_rgb, img_depth, inputnames, outpath, fnExt, vid_ssaa, inpaint_vids):
970+
def run_3dphoto(device, img_rgb, img_depth, inputnames, outpath, inpaint_vids, vid_ssaa, vid_format):
972971
mesh_fi = ''
973972
try:
974973
print("Running 3D Photo Inpainting .. ")
@@ -1094,7 +1093,7 @@ def run_3dphoto(device, img_rgb, img_depth, inputnames, outpath, fnExt, vid_ssaa
10941093
[0.00, 0.00, -0.015, -0.015],
10951094
[0.00, 0.00, -0.015, -0.00],
10961095
[-0.05, -0.05, -0.05, -0.05],
1097-
['dolly-zoom-in', 'zoom-in', 'circle', 'swing'], False, fnExt, vid_ssaa)
1096+
['dolly-zoom-in', 'zoom-in', 'circle', 'swing'], False, vid_format, vid_ssaa)
10981097

10991098
devices.torch_gc()
11001099

@@ -1111,7 +1110,7 @@ def run_3dphoto(device, img_rgb, img_depth, inputnames, outpath, fnExt, vid_ssaa
11111110

11121111

11131112
def run_3dphoto_videos(mesh_fi, basename, outpath, num_frames, fps, crop_border, traj_types, x_shift_range,
1114-
y_shift_range, z_shift_range, video_postfix, vid_dolly, fnExt, vid_ssaa):
1113+
y_shift_range, z_shift_range, video_postfix, vid_dolly, vid_format, vid_ssaa):
11151114
if platform.system() == 'Windows':
11161115
vispy.use(app='PyQt5')
11171116
elif platform.system() == 'Darwin':
@@ -1190,7 +1189,7 @@ def run_3dphoto_videos(mesh_fi, basename, outpath, num_frames, fps, crop_border,
11901189
videos_poses, video_basename, original_h, original_w,
11911190
border=border, depth=None, normal_canvas=normal_canvas,
11921191
all_canvas=all_canvas,
1193-
mean_loc_depth=mean_loc_depth, dolly=vid_dolly, fnExt=fnExt)
1192+
mean_loc_depth=mean_loc_depth, dolly=vid_dolly, fnExt=vid_format)
11941193
return fn_saved
11951194

11961195

@@ -1199,10 +1198,7 @@ def run_makevideo(fn_mesh, vid_numframes, vid_fps, vid_traj, vid_shift, vid_bord
11991198
if len(fn_mesh) == 0 or not os.path.exists(fn_mesh):
12001199
raise Exception("Could not open mesh.")
12011200

1202-
# file type
1203-
fnExt = "mp4" if vid_format == 0 else "webm"
1204-
1205-
vid_ssaa = vid_ssaa + 1
1201+
vid_ssaa = int(vid_ssaa)
12061202

12071203
# traj type
12081204
if vid_traj == 0:
@@ -1235,7 +1231,7 @@ def run_makevideo(fn_mesh, vid_numframes, vid_fps, vid_traj, vid_shift, vid_bord
12351231
fullfn = None
12361232
for i in range(500):
12371233
fn = f"{basecount + i:05}" if basename == '' else f"{basename}-{basecount + i:04}"
1238-
fullfn = os.path.join(outpath, f"{fn}_." + fnExt)
1234+
fullfn = os.path.join(outpath, f"{fn}_." + vid_format)
12391235
if not os.path.exists(fullfn):
12401236
break
12411237
basename = Path(fullfn).stem
@@ -1244,7 +1240,7 @@ def run_makevideo(fn_mesh, vid_numframes, vid_fps, vid_traj, vid_shift, vid_bord
12441240
print("Loading mesh ..")
12451241

12461242
fn_saved = run_3dphoto_videos(fn_mesh, basename, outpath, num_frames, num_fps, crop_border, vid_traj, x_shift_range,
1247-
y_shift_range, z_shift_range, [''], dolly, fnExt, vid_ssaa)
1243+
y_shift_range, z_shift_range, [''], dolly, vid_format, vid_ssaa)
12481244

12491245
return fn_saved[-1], fn_saved[-1], ''
12501246

@@ -1263,11 +1259,6 @@ def run_generate(*inputs):
12631259
imageNameArr = []
12641260
outputs = []
12651261

1266-
# TODO: this should not be here
1267-
# file type
1268-
inputs['fnExt'] = "mp4" if inputs['vid_format'] == 0 else "webm"
1269-
inputs['vid_ssaa'] = inputs['vid_ssaa'] + 1
1270-
12711262
if depthmap_mode == '0': # Single image
12721263
imageArr.append(depthmap_input_image)
12731264
imageNameArr.append(None)
@@ -1383,7 +1374,7 @@ def on_ui_tabs():
13831374
label="Skip generation and use (edited/custom) depthmaps in output directory when a file exists.",
13841375
value=True)
13851376
submit = gr.Button('Generate', elem_id="depthmap_generate", variant='primary')
1386-
inp += main_ui_panel(True)
1377+
inp += main_ui_panel(True) # Main panel is inserted here
13871378
unloadmodels = gr.Button('Unload models', elem_id="depthmap_unloadmodels")
13881379

13891380
with gr.Column(variant='panel'):
@@ -1417,8 +1408,8 @@ def on_ui_tabs():
14171408
with gr.Row():
14181409
vid_numframes = gr.Textbox(label="Number of frames", value="300")
14191410
vid_fps = gr.Textbox(label="Framerate", value="40")
1420-
inp += 'vid_format', gr.Dropdown(label="Format", choices=['mp4', 'webm'], value='mp4', type="index", elem_id="video_format")
1421-
inp += 'vid_ssaa', gr.Dropdown(label="SSAA", choices=['1', '2', '3', '4'], value='3', type="index", elem_id="video_ssaa")
1411+
vid_format = gr.Dropdown(label="Format", choices=['mp4', 'webm'], value='mp4', type="value", elem_id="video_format")
1412+
vid_ssaa = gr.Dropdown(label="SSAA", choices=['1', '2', '3', '4'], value='3', type="value", elem_id="video_ssaa")
14221413
with gr.Row():
14231414
vid_traj = gr.Dropdown(label="Trajectory", choices=['straight-line', 'double-straight-line', 'circle'], value='double-straight-line', type="index", elem_id="video_trajectory")
14241415
vid_shift = gr.Textbox(label="Translate: x, y, z", value="-0.015, 0.0, -0.05")
@@ -1475,8 +1466,8 @@ def custom_depthmap_visibility(v):
14751466
vid_shift,
14761467
vid_border,
14771468
vid_dolly,
1478-
inp['vid_format'],
1479-
inp['vid_ssaa']
1469+
vid_format,
1470+
vid_ssaa
14801471
],
14811472
outputs=[
14821473
depth_vid,

0 commit comments

Comments
 (0)