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

/comfyui-inpaint-nodes/util.py resize_square cannot handle w/h >= 2 or w/h <= 0.5 image #35

Closed
wchpeng opened this issue Apr 17, 2024 · 1 comment

Comments

@wchpeng
Copy link

wchpeng commented Apr 17, 2024

I use this in ComfyUI , it raise error when I input image(weigh=724, height=1448):

Argument #4: padding size should be less than the corresponding input dimension, but got: padding (0, 724) at dimension 3 of input [1,3,1448,724]

File "/mnt/sda/comfyUI/custom nodes/comfyui-inpaint-nodes/util.py", line 37, in resize_square
image = F.pad(image,(0, pad_w, 0, pad_h), mode="reflect')

I modify the 'resize_square' code and it run normally:

def resize_square(image: Tensor, mask: Tensor, size: int):
    _, _, h, w = image.shape
    pad_w, pad_h, prev_size = 0, 0, w
    if w == size and h == size:
        return image, mask, (pad_w, pad_h, prev_size)

    if w < h:
        pad_w = h - w
        prev_size = h
    elif h < w:
        pad_h = w - h
        prev_size = w

    print('###################################')
    pad_w2, pad_h2 = pad_w, pad_h
    while pad_w2 > 0 or pad_h2 > 0:
        _pad_w = w-1 if pad_w2>=w else pad_w2
        pad_w2 -= _pad_w
        _pad_h = h-1 if pad_h2>=h else pad_h2
        pad_h2 -= _pad_h

        image = F.pad(image, (0, _pad_w, 0, _pad_h), mode="reflect")
        mask = F.pad(mask, (0, _pad_w, 0, _pad_h), mode="reflect")
    #image = F.pad(image, (0, pad_w, 0, pad_h), mode="reflect")
    #mask = F.pad(mask, (0, pad_w, 0, pad_h), mode="reflect")
    print('###################################')

    if image.shape[-1] != size:
        image = F.interpolate(image, size=size, mode="nearest-exact")
        mask = F.interpolate(mask, size=size, mode="nearest-exact")

    return image, mask, (pad_w, pad_h, prev_size)
@Acly
Copy link
Owner

Acly commented Apr 17, 2024

I thought I fixed that a while ago: a7be093

Are you sure you're on latest version?

@Acly Acly closed this as completed May 21, 2024
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