Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to fix following error (using given sample code) #19

Open
terrencechungong opened this issue Apr 24, 2024 · 1 comment
Open

How to fix following error (using given sample code) #19

terrencechungong opened this issue Apr 24, 2024 · 1 comment

Comments

@terrencechungong
Copy link


RuntimeError Traceback (most recent call last)
Cell In[5], line 12
9 image = Image.open(img_path)
10 mask = Image.open(mask_path).convert('L')
---> 12 result = simple_lama(image, mask)
13 result.save("inpainted.png")

File /scratch0/tchungon/anaconda3/envs/samxlama/lib/python3.8/site-packages/simple_lama_inpainting/models/model.py:32, in SimpleLama.call(self, image, mask)
29 image, mask = prepare_img_and_mask(image, mask, self.device)
31 with torch.inference_mode():
---> 32 inpainted = self.model(image, mask)
34 cur_res = inpainted[0].permute(1, 2, 0).detach().cpu().numpy()
35 cur_res = np.clip(cur_res * 255, 0, 255).astype(np.uint8)

File /scratch0/tchungon/anaconda3/envs/samxlama/lib/python3.8/site-packages/torch/nn/modules/module.py:1511, in Module._wrapped_call_impl(self, *args, **kwargs)
1509 return self._compiled_call_impl(*args, **kwargs) # type: ignore[misc]
1510 else:
-> 1511 return self._call_impl(*args, **kwargs)

File /scratch0/tchungon/anaconda3/envs/samxlama/lib/python3.8/site-packages/torch/nn/modules/module.py:1520, in Module._call_impl(self, *args, **kwargs)
1515 # If we don't have any hooks, we want to skip the rest of the logic in
1516 # this function, and just call forward.
1517 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1518 or _global_backward_pre_hooks or _global_backward_hooks
...
/home/enesmsahin/.conda/envs/sdiff/lib/python3.9/site-packages/hydra/_internal/utils.py(367): _run_hydra
/home/enesmsahin/.conda/envs/sdiff/lib/python3.9/site-packages/hydra/main.py(49): decorated_main
/home/enesmsahin/enes_workspace/lama/bin/to_jit.py(78):
RuntimeError: Given groups=1, weight of size [64, 4, 7, 7], expected input[1, 5, 1054, 2462] to have 4 channels, but got 5 channels instead
Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...

@insanebai
Copy link

You need to modify the given sample code:

from simple_lama_inpainting import SimpleLama
from PIL import Image

simple_lama = SimpleLama()

img_path = "image.png"
mask_path = "mask.png"

image = Image.open(img_path).convert('RGB')
mask = Image.open(mask_path).convert('L')

result = simple_lama(image, mask)
result.save("inpainted.png")

Because the default mode of PIL package is "ARGB" and its channels are 4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants