Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance Device and Precision Handling, and Improve Error Messages in DepthPro Model #35

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/depth_pro/depth_pro.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def create_backbone_model(

def create_model_and_transforms(
config: DepthProConfig = DEFAULT_MONODEPTH_CONFIG_DICT,
device: torch.device = torch.device("cpu"),
precision: torch.dtype = torch.float32,
device: torch.device = torch.device("cuda" if torch.cuda.is_available() else "cpu"),
) -> Tuple[DepthPro, Compose]:
# Determine the precision based on the device here
precision = torch.float16 if device.type == 'cuda' else torch.float32

"""Create a DepthPro model and load weights from `config.checkpoint_uri`.

Args:
Expand Down Expand Up @@ -146,7 +148,8 @@ def create_model_and_transforms(
# which we would not use. We only use the encoding.
missing_keys = [key for key in missing_keys if "fc_norm" not in key]
if len(missing_keys) != 0:
raise KeyError(f"Keys are missing when loading monodepth: {missing_keys}")
raise KeyError(f"Keys are missing when loading monodepth: {missing_keys}. "
f"Ensure the model checkpoint is compatible with the architecture or update the state dict.")

return model, transform

Expand Down