feat(nodes): add InvertTensorMaskInvocation

This commit is contained in:
psychedelicious 2024-04-19 13:54:38 +10:00 committed by Kent Keirsey
parent c195094e91
commit aace364677

View File

@ -59,5 +59,30 @@ class AlphaMaskToTensorInvocation(BaseInvocation):
mask[0] = torch.tensor(np.array(image)[:, :, 3] > 0, dtype=torch.bool) mask[0] = torch.tensor(np.array(image)[:, :, 3] > 0, dtype=torch.bool)
return MaskOutput( return MaskOutput(
mask=TensorField(tensor_name=context.tensors.save(mask)), height=image.height, width=image.width mask=TensorField(tensor_name=context.tensors.save(mask)),
height=mask.shape[1],
width=mask.shape[2],
)
@invocation(
"invert_tensor_mask",
title="Invert Tensor Mask",
tags=["conditioning"],
category="conditioning",
version="1.0.0",
)
class InvertTensorMaskInvocation(BaseInvocation):
"""Inverts a tensor mask."""
mask: TensorField = InputField(description="The tensor mask to convert.")
def invoke(self, context: InvocationContext) -> MaskOutput:
mask = context.tensors.load(self.mask.tensor_name)
inverted = ~mask
return MaskOutput(
mask=TensorField(tensor_name=context.tensors.save(inverted)),
height=inverted.shape[1],
width=inverted.shape[2],
) )