ZoeDepth icon indicating copy to clipboard operation
ZoeDepth copied to clipboard

Hacky way to run ZoeDepth with modern timm (e.g. timm==0.9.8)

Open ducha-aiki opened this issue 1 year ago • 4 comments

Instead of

import torch

repo = "isl-org/ZoeDepth"
model_zoe_nk = torch.hub.load(repo, "ZoeD_NK", pretrained=True)

Run the following monkey-patching code:

import torch
import torch.nn as nn

repo = "isl-org/ZoeDepth"
model_zoe_nk = torch.hub.load(repo, "ZoeD_NK", pretrained=False)
pretrained_dict = torch.hub.load_state_dict_from_url('https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_NK.pt', map_location='cpu')
model_zoe_nk.load_state_dict(pretrained_dict['model'], strict=False)
for b in model_zoe_nk.core.core.pretrained.model.blocks:
    b.drop_path = nn.Identity()

Tested with timm==0.9.8

ducha-aiki avatar Oct 23 '23 13:10 ducha-aiki

I'm getting an error running this:

"name 'nn' is not defined"

decamun avatar Oct 25 '23 18:10 decamun

OK, this is working for me with:

import torch

repo = "isl-org/ZoeDepth"
model_zoe_nk = torch.hub.load(repo, "ZoeD_NK", pretrained=False)
pretrained_dict = torch.hub.load_state_dict_from_url('https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_NK.pt', map_location='cpu')
model_zoe_nk.load_state_dict(pretrained_dict['model'], strict=False)
for b in model_zoe_nk.core.core.pretrained.model.blocks:
    b.drop_path = torch.nn.Identity()

decamun avatar Oct 25 '23 18:10 decamun

@decamun thanks for the catch, I forgot import torch.nn as nn. Your solution is works as well, obviously.

ducha-aiki avatar Oct 25 '23 18:10 ducha-aiki

Hey @ducha-aiki, any chance you know of a workaround for the issue I'm having in #84?

decamun avatar Oct 26 '23 23:10 decamun