ZoeDepth icon indicating copy to clipboard operation
ZoeDepth copied to clipboard

AttributeError: 'Block' object has no attribute 'drop_path'

Open MohamedAliRashad opened this issue 3 years ago • 5 comments

I keep getting the title error, Is there a solution for it ?

MohamedAliRashad avatar Apr 14 '23 11:04 MohamedAliRashad

I've found that the bug is caused by timm version. If you install older version of timm, it will work.

FYI, I've used timm==0.6.7

leejaeyong7 avatar Apr 28 '23 19:04 leejaeyong7

That's a problem that MiDaS models have (that carries over to ZoeDepth)

ntakouris avatar May 30 '23 07:05 ntakouris

I was able to get it to work by reverting to timm=0.6.13. See the original discussion on the MiDaS repo: https://github.com/isl-org/MiDaS/issues/215

palol avatar Aug 09 '23 19:08 palol

FYI, you can also modify the source code in beit.py according to timm.models.beit.py without downgrade the timm version, i.e. change the variable names drop_path to drop_path1 and drop_path2 image

charliememory avatar Feb 18 '24 08:02 charliememory

FYI, you can also modify the source code in beit.py according to timm.models.beit.py without downgrade the timm version, i.e. change the variable names drop_path to drop_path1 and drop_path2 image

Following on from @charliememory's comment - you can set the appropriate names on MiDaS fetched from torch.hub with something along the lines of:

def block_forward(self, x, resolution, shared_rel_pos_bias: Optional[torch.Tensor] = None):
    """
    Modification of timm.models.beit.py: Block.forward to support arbitrary window sizes.
    """
    if self.gamma_1 is None:
        x = x + self.drop_path1(self.attn(self.norm1(x), resolution, shared_rel_pos_bias=shared_rel_pos_bias))
        x = x + self.drop_path1(self.mlp(self.norm2(x)))
    else:
        x = x + self.drop_path2(self.gamma_1 * self.attn(self.norm1(x), resolution,
                                                        shared_rel_pos_bias=shared_rel_pos_bias))
        x = x + self.drop_path2(self.gamma_2 * self.mlp(self.norm2(x)))
    return x

midas = torch.hub.load(
    "intel-isl/MiDaS", 'DPT_BEiT_L_384',
    pretrained=True, 
    force_reload=True, trust_repo=True,
)
for block in midas.pretrained.model.blocks:
    block.forward = types.MethodType(block_forward, block)

Works for me with timm==0.9.2.

Connah-rs avatar Feb 27 '24 12:02 Connah-rs