-
-
Save BlenderNeko/c12ec5a96438ad03809003de034121dd to your computer and use it in GitHub Desktop.
standalone preprocessor node for inpaint cnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
class Inpaint_Preprocessor: | |
@classmethod | |
def INPUT_TYPES(s): | |
return {"required": { "image": ("IMAGE",), "mask": ("MASK",)}} | |
RETURN_TYPES = ("IMAGE",) | |
FUNCTION = "preprocess" | |
CATEGORY = "preprocessors/inpaint" | |
def preprocess(self, image, mask): | |
mask = torch.nn.functional.interpolate(mask.reshape((-1, 1, mask.shape[-2], mask.shape[-1])), size=(image.shape[1], image.shape[2]), mode="bilinear") | |
mask = mask.movedim(1,-1).expand((-1,-1,-1,3)) | |
image = image.clone() | |
image[mask > 0.5] = -1.0 # set as masked pixel | |
return (image, ) | |
NODE_CLASS_MAPPINGS = { | |
"InpaintPreprocessor": Inpaint_Preprocessor, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment