ZoeDepth icon indicating copy to clipboard operation
ZoeDepth copied to clipboard

Are ZoeDepth models traceable?

Open ketanatzebu opened this issue 2 years ago • 4 comments

I was trying to trace ZoeD_NK model and got following error,

  File "/home/ketan/ZoeDepth/tracing.py", line 39, in <module>
    module = torch.jit.trace(model_zoe_nk, x)
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 794, in trace
    return trace_module(
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 1056, in trace_module
    module._c._create_method_from_trace(
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1488, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/ketan/ZoeDepth/zoedepth/models/zoedepth/zoedepth_v1.py", line 144, in forward
    rel_depth, out = self.core(x, denorm=denorm, return_rel_depth=True)
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1488, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 264, in forward
    x = self.prep(x)
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 188, in __call__
    return self.normalization(self.resizer(x))
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 174, in __call__
    width, height = self.get_size(*x.shape[-2:][::-1])
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 165, in get_size
    new_height = self.constrain_to_multiple_of(scale_height * height)
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 101, in constrain_to_multiple_of
    y = (np.round(x / self.__multiple_of) * self.__multiple_of).astype(int)
AttributeError: 'Tensor' object has no attribute 'astype'

I want to run this model with a cpp script.

ketanatzebu avatar Oct 27 '23 12:10 ketanatzebu

you are trying to convert string type to int type but what file are you trying to convert. mention it in parenthesis nest to int like .astype(int)(image)

Muhammad-Aqib453 avatar Jan 31 '24 07:01 Muhammad-Aqib453

I was trying to trace ZoeD_NK model and got following error,

  File "/home/ketan/ZoeDepth/tracing.py", line 39, in <module>
    module = torch.jit.trace(model_zoe_nk, x)
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 794, in trace
    return trace_module(
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/jit/_trace.py", line 1056, in trace_module
    module._c._create_method_from_trace(
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1488, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/ketan/ZoeDepth/zoedepth/models/zoedepth/zoedepth_v1.py", line 144, in forward
    rel_depth, out = self.core(x, denorm=denorm, return_rel_depth=True)
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/ketan/.local/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1488, in _slow_forward
    result = self.forward(*input, **kwargs)
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 264, in forward
    x = self.prep(x)
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 188, in __call__
    return self.normalization(self.resizer(x))
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 174, in __call__
    width, height = self.get_size(*x.shape[-2:][::-1])
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 165, in get_size
    new_height = self.constrain_to_multiple_of(scale_height * height)
  File "/home/ketan/ZoeDepth/zoedepth/models/base_models/midas.py", line 101, in constrain_to_multiple_of
    y = (np.round(x / self.__multiple_of) * self.__multiple_of).astype(int)
AttributeError: 'Tensor' object has no attribute 'astype'

I want to run this model with a cpp script.

I encountered this problem, too. Do you fix this?

huzhanming16 avatar Feb 27 '24 02:02 huzhanming16

Would this resolve your issue? by replacing .astype(int) with .int()

Benjamin-Tan avatar Mar 06 '24 05:03 Benjamin-Tan

Would this resolve your issue? by replacing .astype(int) with .int() I have solved this problem by editing the source files.

huzhanming16 avatar Mar 06 '24 05:03 huzhanming16