Skip to content

Commit e394d38

Browse files
authored
Merge pull request #233 from semjon00/main
Fixes
2 parents f42020c + 92893de commit e394d38

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

install.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ def ensure(module_name, min_version=None):
1515
if launch.is_installed(module_name):
1616
if min_version is None or Version(importlib_metadata.version(module_name)) >= Version(min_version):
1717
return
18-
cmd = f'install "{module_name}>={min_version}"' if min_version is not None else f'install {module_name}'
19-
msg = f'{module_name} {min_version + " " if min_version is not None else ""}requirement for depthmap script'
18+
requirement = f'{module_name}>={min_version}' if min_version is not None else module_name
19+
cmd = f'install "{requirement}"'
20+
msg = f'{requirement} requirement for depthmap script'
2021
launch.run_pip(cmd, msg)
2122

22-
if not launch.is_installed("timm"): #0.6.7
23+
if not launch.is_installed("timm"): #0.6.7 # For midas
2324
launch.run_pip('install --force-reinstall "timm==0.6.12"', "timm requirement for depthmap script")
2425

2526
ensure('matplotlib')

scripts/depthmap.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import vispy
3636
import trimesh
3737
import math
38+
import subprocess
3839

3940
sys.path.append('extensions/stable-diffusion-webui-depthmap-script/scripts')
4041

@@ -84,6 +85,15 @@
8485
depthmap_model_type = None
8586
depthmap_deviceidx = None
8687

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+
8797
def main_ui_panel(is_depth_tab):
8898
with gr.Blocks():
8999
with gr.Row():
@@ -296,7 +306,7 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
296306
if len(inputimages) == 0 or inputimages[0] == None:
297307
return [], []
298308

299-
print(f"\n{scriptname} {scriptversion}")
309+
print(f"\n{scriptname} {scriptversion} ({commit_hash})")
300310

301311
# unload sd model
302312
shared.sd_model.cond_stage_model.to(devices.cpu)
@@ -510,17 +520,22 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
510520

511521
# filename
512522
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:
516531
save_depth = True
517532
if inputnames[count] is not None:
518533
p = Path(inputnames[count])
519534
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
524539

525540
# override net size
526541
if (match_size):
@@ -535,11 +550,9 @@ def run_depthmap(processed, outpath, inputimages, inputnames,
535550
img = cv2.cvtColor(np.asarray(inputimages[count]), cv2.COLOR_BGR2RGB) / 255.0
536551

537552
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:
541554
# use custom depthmap
542-
dimg = Image.open(os.path.abspath(custom_depthmap_img.name))
555+
dimg = Image.open(os.path.abspath(custom_depthmap_fn))
543556
# resize if not same size as input
544557
if dimg.width != inputimages[count].width or dimg.height != inputimages[count].height:
545558
dimg = dimg.resize((inputimages[count].width, inputimages[count].height), Image.Resampling.LANCZOS)

0 commit comments

Comments
 (0)