Skip to content

Commit c5ecd23

Browse files
fix: Fix bug when mask not on same device (CORE-181) (Comfy-Org#13801)
1 parent 9864f5a commit c5ecd23

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

comfy/bg_removal_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def encode_image(self, image):
4747
out = self.model(pixel_values=pixel_values)
4848
out = torch.nn.functional.interpolate(out, size=(H, W), mode="bicubic", antialias=False)
4949

50-
mask = out.sigmoid()
50+
mask = out.sigmoid().to(device=comfy.model_management.intermediate_device(), dtype=comfy.model_management.intermediate_dtype())
5151
if mask.ndim == 3:
5252
mask = mask.unsqueeze(0)
5353
if mask.shape[1] != 1:

comfy_extras/nodes_compositing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def define_schema(cls):
203203
@classmethod
204204
def execute(cls, image: torch.Tensor, alpha: torch.Tensor) -> io.NodeOutput:
205205
batch_size = max(len(image), len(alpha))
206-
alpha = 1.0 - resize_mask(alpha, image.shape[1:])
206+
alpha = 1.0 - resize_mask(alpha.to(image), image.shape[1:])
207207
alpha = comfy.utils.repeat_to_batch_size(alpha, batch_size)
208208
image = comfy.utils.repeat_to_batch_size(image, batch_size)
209209
return io.NodeOutput(torch.cat((image[..., :3], alpha.unsqueeze(-1)), dim=-1))

0 commit comments

Comments
 (0)