MCPcopy Index your code
hub / github.com/thygate/stable-diffusion-webui-depthmap-script / estimatemidas

Function estimatemidas

src/depthmap_generation.py:455–499  ·  view source on GitHub ↗
(img, model, w, h, resize_mode, normalization, no_half, precision_is_autocast)

Source from the content-addressed store, hash-verified

453
454
455def estimatemidas(img, model, w, h, resize_mode, normalization, no_half, precision_is_autocast):
456 import contextlib
457 # init transform
458 transform = Compose(
459 [
460 Resize(
461 w,
462 h,
463 resize_target=None,
464 keep_aspect_ratio=True,
465 ensure_multiple_of=32,
466 resize_method=resize_mode,
467 image_interpolation_method=cv2.INTER_CUBIC,
468 ),
469 normalization,
470 PrepareForNet(),
471 ]
472 )
473
474 # transform input
475 img_input = transform({"image": img})["image"]
476
477 # compute
478 precision_scope = torch.autocast if precision_is_autocast and depthmap_device == torch.device(
479 "cuda") else contextlib.nullcontext
480 with torch.no_grad(), precision_scope("cuda"):
481 sample = torch.from_numpy(img_input).to(depthmap_device).unsqueeze(0)
482 if depthmap_device == torch.device("cuda"):
483 sample = sample.to(memory_format=torch.channels_last)
484 if not no_half:
485 sample = sample.half()
486 prediction = model.forward(sample)
487 prediction = (
488 torch.nn.functional.interpolate(
489 prediction.unsqueeze(1),
490 size=img.shape[:2],
491 mode="bicubic",
492 align_corners=False,
493 )
494 .squeeze()
495 .cpu()
496 .numpy()
497 )
498
499 return prediction
500
501
502# TODO: correct values for BOOST

Callers 1

get_raw_predictionMethod · 0.85

Calls 4

ResizeClass · 0.90
PrepareForNetClass · 0.90
toMethod · 0.80
forwardMethod · 0.45

Tested by

no test coverage detected