neverbiasu / ComfyUI-SAM2

A ComfyUI extension for Segment-Anything 2
47 stars 9 forks source link

axes don't match array #5

Closed Yuliucheng closed 3 days ago

Yuliucheng commented 1 month ago

Error occurred when executing GroundingDinoSAMSegment (segment anything):

axes don't match array

File "/tmp/code/ComfyUI/execution.py", line 152, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "/tmp/code/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 "/tmp/code/ComfyUI/execution.py", line 75, in map_node_over_list results.append(getattr(obj, func)(*slice_dict(input_data_all, i))) File "/tmp/code/ComfyUI/custom_nodes/ComfyUI-SAM2/node.py", line 311, in main (images, masks) = sam_segment( File "/tmp/code/ComfyUI/custom_nodes/ComfyUI-SAM2/node.py", line 238, in sam_segment masks = np.transpose(masks, (1, 0, 2, 3)) File "/opt/conda/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 655, in transpose return _wrapfunc(a, 'transpose', axes) File "/opt/conda/lib/python3.10/site-packages/numpy/core/fromnumeric.py", line 59, in _wrapfunc return bound(args, **kwds) ![Uploading 2024828501.png…]()

neverbiasu commented 1 month ago

Could you provide the mask details by print("mask: ", mask) before the line 238 in node.py.

talhadar90 commented 1 month ago

I am facing the same issue

Heres my print("mask: ", mask)

Traceback (most recent call last): File "/home/ubuntu/ComfyUI/execution.py", line 151, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "/home/ubuntu/ComfyUI/execution.py", line 81, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) File "/home/ubuntu/ComfyUI/execution.py", line 74, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) File "/home/ubuntu/ComfyUI/custom_nodes/ComfyUI-SAM2/node.py", line 312, in main (images, masks) = sam_segment( File "/home/ubuntu/ComfyUI/custom_nodes/ComfyUI-SAM2/node.py", line 238, in sam_segment print("mask: ", mask) NameError: name 'mask' is not defined

neverbiasu commented 1 month ago

My mistake, it should be print("masks: ", masks) instead of print("mask: ", mask)

Yuliucheng commented 1 month ago

I Input it before masks = np.transpose(masks, (1, 0, 2, 3)) . The result is as follows:

Prompt executed in 15.56 seconds got prompt For numpy array image, we assume (HxWxC) format Computing image embeddings for the provided image... Image embeddings computed. !!! Exception during processing!!! local variable 'mask' referenced before assignment Traceback (most recent call last): File "/tmp/code/ComfyUI/execution.py", line 152, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "/tmp/code/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 "/tmp/code/ComfyUI/execution.py", line 75, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) File "/tmp/code/ComfyUI/custom_nodes/ComfyUI-SAM2/node.py", line 324, in main File "/tmp/code/ComfyUI/custom_nodes/ComfyUI-SAM2/node.py", line 242, in sam_segment UnboundLocalError: local variable 'mask' referenced before assignment

I run Comfyui in ubuntu22.04 and requirements versions are. : cuda12.1.0 timm version: 1.0.7 addict version: 2.4.0 yapf version: 0.40.2 torch version: 2.3.1+cu121 torchvision version: 0.18.1+cu121 numpy version: 1.25.2 tqdm version: 4.66.4 iopath version: 0.1.10 matplotlib version: 3.9.1 opencv-python version: 4.8.0

neverbiasu commented 1 month ago

My mistake, it should be print("masks: ", masks) instead of print("mask: ", mask)

print("masks: ", masks)use this

Yuliucheng commented 1 month ago

Of course, this is the result of print("masks: ", masks)

Yuliucheng commented 1 month ago

202483153346_副本

neverbiasu commented 1 month ago

let me check it, r u using autodl?

Yuliucheng commented 1 month ago

I gave up. It should be a system compatibility issue. Thank you very much for your patient answer😊. It's not autodl, but just a old and unknown cloud server

neverbiasu commented 1 month ago

U r welcome, I'm not a expert of ComfyUI, but more familiar with gradio. I might make a webui for SAM2, I will notify u if u r interested.

Kostafun commented 1 month ago

Hi, I got the same error, output with printing masks:

pip_freeze.txt ---cut--- Loaded checkpoint sucessfully final text_encoder_type: bert-base-uncased For numpy array image, we assume (HxWxC) format Computing image embeddings for the provided image... Image embeddings computed. scores: [ 0.9913] masks: [[[ 0 0 0 ... 0 0 0] [ 0 0 0 ... 0 0 0] [ 0 0 0 ... 0 0 0] ... [ 0 0 0 ... 0 0 0] [ 0 0 0 ... 0 0 0] [ 0 0 0 ... 0 0 0]]] !!! Exception during processing!!! axes don't match array Traceback (most recent call last): File "/home/kostafun/ComfyUI/execution.py", line 152, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kostafun/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 "/home/kostafun/ComfyUI/execution.py", line 75, in map_node_over_list results.append(getattr(obj, func)(*slice_dict(input_data_all, i))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kostafun/ComfyUI/custom_nodes/ComfyUI-SAM2/node.py", line 312, in main (images, masks) = sam_segment( ^^^^^^^^^^^^ File "/home/kostafun/ComfyUI/custom_nodes/ComfyUI-SAM2/node.py", line 239, in sam_segment masks = np.transpose(masks, (1, 0, 2, 3)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kostafun/miniconda3/envs/comfyui/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 655, in transpose return _wrapfunc(a, 'transpose', axes) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/kostafun/miniconda3/envs/comfyui/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 59, in _wrapfunc return bound(args, **kwds) ^^^^^^^^^^^^^^^^^^^^ ValueError: axes don't match array ---cut---

Kostafun commented 1 month ago

It is working with square image.

qiqiApink commented 1 month ago

I gave up. It should be a system compatibility issue. Thank you very much for your patient answer😊. It's not autodl, but just a old and unknown cloud server

@Yuliuchengyin You should delete the squeeze(0) in SAM2ImagePredictor.predict (line 280 - line 282 in ComfyUI-SAM2/sam2/sam2_image_predictor.py). Then it will works!