BillFSmith / TilingZoeDepth

144 stars 22 forks source link

TypeError: expected size to be one of int or Tuple #1

Closed jones873 closed 5 months ago

jones873 commented 9 months ago

Hi Bill

Loved the previous version of tiling Zoe Depth but no longer works, and your new model throws this error when I upload an image and try to run it thanks.


TypeError Traceback (most recent call last)

in process_clicked(change) 92 # Generate low resolution image 93 # low_res_depth = zoe.infer_pil(img) ---> 94 low_res_depth = dependencies['zoe'].infer_pil(img) 95 low_res_scaled_depth = 2**16 - (low_res_depth - np.min(low_res_depth)) * 2**16 / (np.max(low_res_depth) - np.min(low_res_depth)) 96 14 frames /usr/local/lib/python3.10/dist-packages/torch/nn/functional.py in interpolate(input, size, scale_factor, mode, align_corners, recompute_scale_factor, antialias) 3922 if not torch.jit.is_scripting(): 3923 if not all(_is_integer(x) for x in size): -> 3924 raise TypeError( 3925 "expected size to be one of int or Tuple[int] or Tuple[int, int] or " 3926 f"Tuple[int, int, int], but got size with types {[type(x) for x in size]}" TypeError: expected size to be one of int or Tuple[int] or Tuple[int, int] or Tuple[int, int, int], but got size with types [, ] ----------------------------------------------------------------------------------------------------------------------------------------
BillFSmith commented 9 months ago

Hi, and thanks!

Oh dear. Do you have the image so I can try to reproduce the error, or any details about it (filetype, size, bit depth)?

Rawgeek commented 9 months ago

Seems like it's a dependency issue with. Try running !python sanity.py in colab to reproduce. Might be an issue while running with torch==2.1.0, trying torch==2.0.1 now

Rawgeek commented 9 months ago

Freezing versions torch helped. Just in case also freezed other libraries:

def dependencies_clicked(change):
    !cd /content/
    !pip install --upgrade timm==0.6.7 torch==2.0.1 torchvision==0.15.2 numpy==1.23.5 pillow==9.4.0
    !git clone https://github.com/isl-org/ZoeDepth.git
    %cd ZoeDepth
    # !python sanity.py # would be nice to move to a separate button as a test that can be run optionally before the main process
BillFSmith commented 9 months ago

That's great, thanks. I've added it now to the colab

jones873 commented 9 months ago

Tried running again but still no joy, uploading a image seems a bit of a hit and miss, it shows image uploaded, but does not confirm this by showing the file name of the image, hence the script stalls and will not try to process the image.

When It does manage to correctly upload and confirm I then get this error, and tests have been done will multible images ranging from png/jpg different sizes 16bit


/content/ZoeDepth img_size [384, 512]

/usr/local/lib/python3.10/dist-packages/torch/hub.py:286: UserWarning: You are about to download and run code from an untrusted repository. In a future release, this won't be allowed. To add the repository to your trusted list, change the command to {calling_fn}(..., trust_repo=False) and a command prompt will appear asking for an explicit confirmation of trust, or load(..., trust_repo=True), which will assume that the prompt is to be answered with 'yes'. You can also use load(..., trust_repo='check') which will only prompt for confirmation if the repo is not already trusted. This will eventually be the default behaviour warnings.warn( Downloading: "https://github.com/intel-isl/MiDaS/zipball/master" to /root/.cache/torch/hub/master.zip /usr/local/lib/python3.10/dist-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3483.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]

Params passed to Resize transform: width: 512 height: 384 resize_target: True keep_aspect_ratio: True ensure_multiple_of: 32 resize_method: minimal Using pretrained resource url::https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_N.pt

Downloading: "https://github.com/isl-org/ZoeDepth/releases/download/v1.0/ZoeD_M12_N.pt" to /root/.cache/torch/hub/checkpoints/ZoeD_M12_N.pt 100%|██████████| 1.34G/1.34G [00:06<00:00, 216MB/s]

Loaded successfully Uploaded Uploaded Uploaded Uploaded Uploaded Processing Started


AssertionError Traceback (most recent call last)

in process_clicked(change) 94 # Generate low resolution image 95 # low_res_depth = zoe.infer_pil(img) ---> 96 low_res_depth = dependencies['zoe'].infer_pil(img) 97 low_res_scaled_depth = 2**16 - (low_res_depth - np.min(low_res_depth)) * 2**16 / (np.max(low_res_depth) - np.min(low_res_depth)) 98 4 frames /content/ZoeDepth/./zoedepth/models/depth_model.py in _infer_with_pad_aug(self, x, pad_input, fh, fw, upsampling_mode, padding_mode, **kwargs) 75 # assert x is nchw and c = 3 76 assert x.dim() == 4, "x must be 4 dimensional, got {}".format(x.dim()) ---> 77 assert x.shape[1] == 3, "x must have 3 channels, got {}".format(x.shape[1]) 78 79 if pad_input: AssertionError: x must have 3 channels, got 1
BillFSmith commented 9 months ago

It can be pretty sluggish on large images. I'll have a look to see if I can work out why.

The ZoeDepth algorithm downscales images anyway, so there is a limit to benefit of image size (beyond which the depth map does not become more detailed).

The 3 channels error sounds like you might not be using a colour image? It expects to have an RGB image.

jones873 commented 9 months ago

Thanks Bill you was right, I made sure this time that I only used a RGB colored imge the file size was 1mb, but as you said it would be sluggish to upload, but I aslo noticed the run time would also close and re-start hence I could not manualy restart the image process.

Anyway I reduced the image size and tryed again and your script ran as you intended many thanks and keep up the good work