BillFSmith / TilingZoeDepth

144 stars 22 forks source link

AssertionError: x must have 3 channels, got 4 #3

Closed Yatching closed 8 months ago

Yatching commented 8 months ago

Hi Bill,

I was able to run sucessfully run in early Oct and started to have this erroe 2 weeks ago. The img uploaded is 512*512 and less than 1Mb. Have tried the solution mentioned in 1#, not helping.

Here is the error code lines

Loaded successfully
Uploaded
Uploaded
Uploaded
Uploaded
Uploaded
Processing Started
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
[<ipython-input-1-776b75e72098>](https://localhost:8080/#) in process_clicked(change)
    100     # Generate low resolution image
    101     # low_res_depth = zoe.infer_pil(img)
--> 102     low_res_depth = dependencies['zoe'].infer_pil(img)
    103     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))
    104 

4 frames
[/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py](https://localhost:8080/#) in decorate_context(*args, **kwargs)
    113     def decorate_context(*args, **kwargs):
    114         with ctx_factory():
--> 115             return func(*args, **kwargs)
    116 
    117     return decorate_context

[/content/ZoeDepth/./zoedepth/models/depth_model.py](https://localhost:8080/#) in infer_pil(self, pil_img, pad_input, with_flip_aug, output_type, **kwargs)
    139         """
    140         x = transforms.ToTensor()(pil_img).unsqueeze(0).to(self.device)
--> 141         out_tensor = self.infer(x, pad_input=pad_input, with_flip_aug=with_flip_aug, **kwargs)
    142         if output_type == "numpy":
    143             return out_tensor.squeeze().cpu().numpy()

[/content/ZoeDepth/./zoedepth/models/depth_model.py](https://localhost:8080/#) in infer(self, x, pad_input, with_flip_aug, **kwargs)
    124         """
    125         if with_flip_aug:
--> 126             return self.infer_with_flip_aug(x, pad_input=pad_input, **kwargs)
    127         else:
    128             return self._infer_with_pad_aug(x, pad_input=pad_input, **kwargs)

[/content/ZoeDepth/./zoedepth/models/depth_model.py](https://localhost:8080/#) in infer_with_flip_aug(self, x, pad_input, **kwargs)
    108         """
    109         # infer with horizontal flip and average
--> 110         out = self._infer_with_pad_aug(x, pad_input=pad_input, **kwargs)
    111         out_flip = self._infer_with_pad_aug(torch.flip(x, dims=[3]), pad_input=pad_input, **kwargs)
    112         out = (out + torch.flip(out_flip, dims=[3])) / 2

[/content/ZoeDepth/./zoedepth/models/depth_model.py](https://localhost:8080/#) 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 4
BillFSmith commented 8 months ago

Interesting. Is there an alpha channel or anything other than RGB in your file?

Does the new version help? https://colab.research.google.com/drive/1Wi-1Ji_fhcoGpK-drT4dVrl5AjfVUQ5M

Yatching commented 8 months ago

Interesting. Is there an alpha channel or anything other than RGB in your file?

Does the new version help? https://colab.research.google.com/drive/1Wi-1Ji_fhcoGpK-drT4dVrl5AjfVUQ5M

Yes you are right, there is an alpha channel in the png that cause the error. All good after get rid of that channel. Not sure why pics generated by DallE3 include alpha. Thx!