35
35
import vispy
36
36
import trimesh
37
37
import math
38
+ import subprocess
38
39
39
40
sys .path .append ('extensions/stable-diffusion-webui-depthmap-script/scripts' )
40
41
84
85
depthmap_model_type = None
85
86
depthmap_deviceidx = None
86
87
88
+ def get_commit_hash ():
89
+ try :
90
+ hash = subprocess .check_output ([os .environ .get ('GIT' , "git" ), "rev-parse" , "HEAD" ], shell = False , encoding = 'utf8' ).strip ()
91
+ hash = hash [0 :8 ]
92
+ return hash
93
+ except Exception :
94
+ return "<none>"
95
+ commit_hash = get_commit_hash ()
96
+
87
97
def main_ui_panel (is_depth_tab ):
88
98
with gr .Blocks ():
89
99
with gr .Row ():
@@ -296,7 +306,7 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
296
306
if len (inputimages ) == 0 or inputimages [0 ] == None :
297
307
return [], []
298
308
299
- print (f"\n { scriptname } { scriptversion } " )
309
+ print (f"\n { scriptname } { scriptversion } ( { commit_hash } ) " )
300
310
301
311
# unload sd model
302
312
shared .sd_model .cond_stage_model .to (devices .cpu )
@@ -510,17 +520,22 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
510
520
511
521
# filename
512
522
basename = 'depthmap'
513
- batchdepthfn = None
514
- # filenames in batch mode
515
- if inputnames is not None :
523
+
524
+ # figuring out the name of custom DepthMap
525
+ custom_depthmap_fn = None # None means that DepthMap should be computed
526
+ # find filename if in the single image mode
527
+ if custom_depthmap and custom_depthmap_img is not None :
528
+ custom_depthmap_fn = custom_depthmap_img .name
529
+ # find filename if in batch mode
530
+ if inputnames is not None and depthmap_batch_reuse :
516
531
save_depth = True
517
532
if inputnames [count ] is not None :
518
533
p = Path (inputnames [count ])
519
534
basename = p .stem
520
- if depthmap_batch_reuse and outpath != opts .outdir_extras_samples :
521
- batchdepthfn = os .path .join (outpath , basename + '-0000.' + opts .samples_format )
522
- if not os .path .isfile (batchdepthfn ):
523
- batchdepthfn = None
535
+ if outpath != opts .outdir_extras_samples :
536
+ custom_depthmap_fn = os .path .join (outpath , basename + '-0000.' + opts .samples_format )
537
+ if not os .path .isfile (custom_depthmap_fn ):
538
+ custom_depthmap_fn = None
524
539
525
540
# override net size
526
541
if (match_size ):
@@ -535,11 +550,9 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
535
550
img = cv2 .cvtColor (np .asarray (inputimages [count ]), cv2 .COLOR_BGR2RGB ) / 255.0
536
551
537
552
skipInvertAndSave = False
538
- if (custom_depthmap and custom_depthmap_img != None ) or batchdepthfn != None :
539
- if batchdepthfn != None :
540
- custom_depthmap_img = batchdepthfn
553
+ if custom_depthmap_fn is not None :
541
554
# use custom depthmap
542
- dimg = Image .open (os .path .abspath (custom_depthmap_img . name ))
555
+ dimg = Image .open (os .path .abspath (custom_depthmap_fn ))
543
556
# resize if not same size as input
544
557
if dimg .width != inputimages [count ].width or dimg .height != inputimages [count ].height :
545
558
dimg = dimg .resize ((inputimages [count ].width , inputimages [count ].height ), Image .Resampling .LANCZOS )
0 commit comments