comfyui_segment_anything
comfyui_segment_anything copied to clipboard
Error occurred when executing GroundingDinoSAMSegment (segment anything):
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 sam_segment 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
im getting the exact same errror, have you been able to fix it ?
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 sam_segment 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)
Same here too
samesies
I had this same error. Two things to try:
- in the SAM loader, choose a smaller SAM model, like SAM vit-b
- in SAM loader, turn off "auto" and choose "prefer GPU"
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
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:
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.
This solved the problem for me, too.