storyicon / comfyui_segment_anything

Based on GroundingDino and SAM, use semantic strings to segment any element in an image. The comfyui version of sd-webui-segment-anything.
Apache License 2.0
530 stars 67 forks source link

Error occurred when executing GroundingDinoSAMSegment (segment anything): #36

Open xjmxxxx opened 6 months ago

xjmxxxx commented 6 months ago

Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument mat2 in method wrapper_CUDA_mm)

File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/execution.py", line 153, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/execution.py", line 83, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/execution.py", line 76, in map_node_over_list results.append(getattr(obj, func)(slice_dict(input_data_all, i))) File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/custom_nodes/comfyui_segment_anything/node.py", line 314, in main (images, masks) = sam_segment( File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/custom_nodes/comfyui_segment_anything/node.py", line 236, in samsegment masks, , _ = predictor.predict_torch( File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context return func(*args, *kwargs) File "/root/autodl-tmp/stable-diffusion-webui/extensions/sd-webui-comfyui/ComfyUI/custom_nodes/comfyui_segment_anything/sam_hq/predictor.py", line 114, in predict_torch sparse_embeddings, dense_embeddings = self.model.prompt_encoder( File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl return forward_call(args, kwargs) File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/segment_anything/modeling/prompt_encoder.py", line 158, in forward box_embeddings = self._embed_boxes(boxes) File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/segment_anything/modeling/prompt_encoder.py", line 97, in _embed_boxes corner_embedding = self.pe_layer.forward_with_coords(coords, self.input_image_size) File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/segment_anything/modeling/prompt_encoder.py", line 214, in forward_with_coords return self._pe_encoding(coords.to(torch.float)) # B x N x C File "/root/miniconda3/envs/xl_env/lib/python3.10/site-packages/segment_anything/modeling/prompt_encoder.py", line 189, in _pe_encoding coords = coords @ self.positional_encoding_gaussian_matrix

Nebuluss commented 6 months ago

im getting the exact same errror, have you been able to fix it ?

Nebuluss commented 6 months ago

2023-12-30 12:14:30,636 - root - ERROR - !!! Exception during processing !!! 2023-12-30 12:14:30,637 - root - ERROR - Traceback (most recent call last): File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\execution.py", line 153, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\execution.py", line 83, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\execution.py", line 76, in map_node_over_list results.append(getattr(obj, func)(slice_dict(input_data_all, i))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui_segment_anything\node.py", line 325, in main (images, masks) = sam_segment( ^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui_segment_anything\node.py", line 247, in samsegment masks, , _ = predictor.predict_torch( ^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context return func(*args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\ComfyUI\custom_nodes\comfyui_segment_anything\sam_hq\predictor.py", line 114, in predict_torch sparse_embeddings, dense_embeddings = self.model.prompt_encoder( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl return self._call_impl(args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\segment_anything\modeling\prompt_encoder.py", line 158, in forward box_embeddings = self._embed_boxes(boxes) ^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\segment_anything\modeling\prompt_encoder.py", line 97, in _embed_boxes corner_embedding = self.pe_layer.forward_with_coords(coords, self.input_image_size) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\segment_anything\modeling\prompt_encoder.py", line 214, in forward_with_coords return self._pe_encoding(coords.to(torch.float)) # B x N x C ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "E:\ComfyNENE\ComfyUI_windows_portable\python_embeded\Lib\site-packages\segment_anything\modeling\prompt_encoder.py", line 189, in _pe_encoding coords = coords @ self.positional_encoding_gaussian_matrix


RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument mat2 in method wrapper_CUDA_mm)
RamonGuthrie commented 5 months ago

Same here too

qdesp commented 5 months ago

samesies

LankyPoet commented 5 months ago

I had this same error. Two things to try: 1) in the SAM loader, choose a smaller SAM model, like SAM vit-b 2) in SAM loader, turn off "auto" and choose "prefer GPU"

AugmentedRealityCat commented 4 months ago

Solution given by ttulttul, posted as a reply to a similar issue:

Make sure you are using SAMModelLoader (Segment Anything) rather than "SAM Model Loader". Doing so resolved this issue for me. Must be something about how the two model loaders deliver the model data.

https://github.com/storyicon/comfyui_segment_anything/issues/10#issuecomment-1795181782

puke3615 commented 1 month ago

Same issue, and I found the reason is, there are two nodes: One is "SAM Model Loader", from "WS Node Suite", DO NOT USE THIS; The other is "SAMModelLoader", from "segment anything", DO USE THIS;

See this picture: image

fdtory commented 2 weeks ago

Solution given by ttulttul, posted as a reply to a similar issue:

Make sure you are using SAMModelLoader (Segment Anything) rather than "SAM Model Loader". Doing so resolved this issue for me. Must be something about how the two model loaders deliver the model data.

#10 (comment)

This solved the problem for me, too.

image