ZoeDepth icon indicating copy to clipboard operation
ZoeDepth copied to clipboard

Compatibility with Torch > 2.0.1

Open AyaanShah2204 opened this issue 2 years ago • 4 comments

Hello @shariqfarooq123

We're working with the latest nightly version of torch. They seem to have added type asserts to interpolate (this commit).

This causes a runtime error because the size we pass in is of type numpy.int32. A simple int-cast should fix this without any side effects.

AyaanShah2204 avatar Aug 10 '23 20:08 AyaanShah2204

@thias15 could you please merge this? It causes issues with newer torch versions :)

AyaanShah2204 avatar Aug 29 '23 19:08 AyaanShah2204

@thias15

iamwavecut avatar Oct 20 '23 13:10 iamwavecut

Would be helpful if someone could merge this one :) @thias15 @shariqfarooq123

Edit: a different interpolate call also requires typecasting

philippwulff avatar Jan 16 '24 17:01 philippwulff

Monkey-patching interpolate may be a workaround:

# Backup the original interpolate function
original_interpolate = F.interpolate

def patched_interpolate(input, size=None, scale_factor=None, mode='nearest', align_corners=None, recompute_scale_factor=None):
    if size is not None:
        size = tuple(int(s) for s in size)
    return original_interpolate(input, size, scale_factor, mode, align_corners, recompute_scale_factor)

model = torch.hub.load("isl-org/ZoeDepth", "ZoeD_K", pretrained=True).cuda()

F.interpolate = patched_interpolate
depths_zoe = model.infer(imgs)
F.interpolate = original_interpolate

philippwulff avatar Jan 16 '24 18:01 philippwulff