Jcd1230 / rembg-comfyui-node

Rembg Background Removal node for ComfyUI
124 stars 14 forks source link

Doesn't work on image batches #5

Open HaydenReeve opened 5 months ago

HaydenReeve commented 5 months ago

Implementation does what it describes with a singular image in a batch:

image

When you adjust the batch size, it fails with an array error;

Error occurred when executing Image Remove Background (rembg):

Cannot handle this data type: (1, 1, 512, 3), |u1

File "E:\AI\ComfyUI\execution.py", line 152, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\AI\ComfyUI\execution.py", line 82, in get_output_data
return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\AI\ComfyUI\execution.py", line 75, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\AI\ComfyUI\custom_nodes\rembg-comfyui-node\__init__.py", line 31, in remove_background
image = pil2tensor(remove(tensor2pil(image)))
^^^^^^^^^^^^^^^^^
File "E:\AI\ComfyUI\custom_nodes\rembg-comfyui-node\__init__.py", line 8, in tensor2pil
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Hayden\AppData\Local\Programs\Python\Python311\Lib\site-packages\PIL\Image.py", line 3092, in fromarray
raise TypeError(msg) from e

Requirements installed via pip and launch occurs with no errors or warnings.

HaydenReeve commented 5 months ago

I was able to work around the issue by providing the image to a Rebatch node as shown:

image