kwaroran / abg-comfyui

A Anime Background Remover node for comfyui
22 stars 7 forks source link

comfyUi run more than 1 batch size at a time #2

Open arroyoDev opened 1 year ago

arroyoDev commented 1 year ago

it works great if the batch size is one, but it will break if the batch size is more than one. This prevents it being used for cleaning up the final output of an animatediff flow. That would be AWESOME.

Here is the error message:

Error occurred when executing Remove Image Background (abg):

too many values to unpack (expected 2)

File "/Users/ross/apps/ComfyUI/execution.py", line 152, in recursive_execute File "/Users/ross/apps/ComfyUI/execution.py", line 82, in get_output_data uis = []

File "/Users/ross/apps/ComfyUI/execution.py", line 75, in map_node_over_list nodes.before_node_execution() ^^^^^^^^^^^^^^^^^^^ File "/Users/ross/apps/ComfyUI/custom_nodes/abg-comfyui/init.py", line 57, in abg_remover rmb = rmbg_fn(npa) ^^^^^^^^^^^^ File "/Users/ross/apps/ComfyUI/custom_nodes/abg-comfyui/init.py", line 31, in rmbg_fn mask = get_mask(img) ^^^^^^^^^^^^^ File "/Users/ross/apps/ComfyUI/custom_nodes/abg-comfyui/init.py", line 9, in get_mask h, w = h0, w0 = img.shape[:-1] ^^^^

rzezagar commented 1 year ago

@arroyoDev Thanks for raising the issue. Have you found an alternative to work with animediff?

retrouve commented 10 months ago

Go find abg-comfyui folder in customNode, Then change RemoveImageBackgroundabg class in the init.py to

class RemoveImageBackgroundabg:
    def __init__(self):
        pass

    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": {
                "images": ("IMAGE",),
            },
        }

    RETURN_TYPES = ("IMAGE",)
    FUNCTION = "abg_remover"
    CATEGORY = "image"

    def abg_remover(self, images):
        batch_tensor = []
        for image in images:
            npa = image2nparray(image)
            print(npa.ndim)
            rmb = rmbg_fn(npa)
            image = nparray2image(rmb)
            batch_tensor.append(image)

        batch_tensor = torch.cat(batch_tensor, dim=0)
        return (batch_tensor,)

Then you will be fine.

LyazS commented 9 months ago

I fork one to do this, check this repo