<jupyter_start><jupyter_text>Decide whether network is predicting depth or disparity<jupyter_code>import os
import numpy as np
import torch
import cv2
from torchvision.transforms import Compose
import matplotlib.pyplot as plt

from dpt.models import DPTDepthModel
from dpt.transforms import Resize, NormalizeImage, PrepareForNet
from data.InteriorNetDataset import InteriorNetDataset
torch.manual_seed(0)
np.random.seed(0)

# k8s paths
k8s = True
k8s_repo = r'opt/repo/dynamic-inference'
k8s_pvc = r'christh9-pvc'

# path settings
input_path = 'input'
output_path = 'output_monodepth'
model_path = 'weights/dpt_hybrid_nyu-2ce69ec7.pt'
dataset_path = 'video_inference_common/resources'
logs_path = 'train-logs'

if k8s:
    input_path = os.path.join(k8s_repo, input_path)
    output_path = os.path.join(k8s_repo, output_path)
    model_path = os.path.join(k8s_pvc, 'dpt-hybrid-nyu.pt')
#     model_path = os.path.join(k8s_pvc, 'train-logs', 'finetune7.pt')
    dataset_path = os.path.join(k8s_repo, dataset_path)
    logs_dir = os.path.join(k8s_pvc, logs_path)

os.chdir('/')
optimize = False
net_w = 640
net_h = 480
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
model = DPTDepthModel(
            path=model_path,
            scale=0.000305,
            shift=0.1378,
            invert=True,
            backbone="vitb_rn50_384",
            non_negative=True,
            enable_attention_hooks=False,
        )

normalization = NormalizeImage(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])

transform = Compose(
        [
            Resize(
                net_w,
                net_h,
                resize_target=None,
                keep_aspect_ratio=True,
                ensure_multiple_of=32,
                resize_method="minimal",
                image_interpolation_method=cv2.INTER_CUBIC,
            ),
            normalization,
            PrepareForNet(),
        ]
    )

model.eval()

if optimize == True and device == torch.device("cuda"):
    model = model.to(memory_format=torch.channels_last)
    model = model.half()

model.to(device)
print('Loaded model')
interiornet_dataset = InteriorNetDataset(dataset_path, transform=transform, subsample=True)

with torch.no_grad():
    batch = interiornet_dataset[0]
    img, depth = batch['image'], batch['depth']

    plt.imshow(np.moveaxis(img,0,2))
    plt.show()

    sample = torch.from_numpy(img).to(device).unsqueeze(0)

    if optimize == True and device == torch.device("cuda"):
        sample = sample.to(memory_format=torch.channels_last)
        sample = sample.half()

    prediction = model.forward(sample)
    print(prediction.shape)
    prediction = (
        torch.nn.functional.interpolate(
            prediction.unsqueeze(1),
            size=img.shape[1:],
            mode="bicubic",
            align_corners=False,
        )
        .squeeze()
        .cpu()
    )

    fig, axs = plt.subplots(1,2, figsize=(12,12))
    axs[0].imshow(prediction.cpu())
    axs[1].imshow(depth)
    
    plt.show()<jupyter_output>Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).<jupyter_text>Compute scale/shift for networks<jupyter_code>import os
import torch
import numpy as np

from dpt.models import DPTDepthModel
from dpt.transforms import Resize, NormalizeImage, PrepareForNet
from data.InteriorNetDataset import InteriorNetDataset

from util.validate_nyu import BadPixelMetric<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10951008645533142, 'fraction_numerical': 0.022478386167146973, 'mean_word_length': 3.1223277909738716, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '423980', 'license': 'MIT', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1189, 'n_words': 227, 'path': 'playground.ipynb', 'repo_name': 'chriswxho/dynamic-inference', 'size': '3470'}