Skip to content

Layer Diffuse Apply

Documentation

  • Class name: LayeredDiffusionApply
  • Category: layer_diffuse
  • Output node: False

The LayeredDiffusionApply node is designed to integrate and apply layered diffusion techniques to enhance image generation processes. It leverages multiple diffusion models to apply complex transformations and refinements to images, aiming to improve the quality and detail of the generated visuals.

Input types

Required

  • model
    • The model parameter represents the diffusion model to be patched and used for the layered diffusion process. It is crucial for defining the specific model behavior and characteristics that will be applied during the image generation.
    • Comfy dtype: MODEL
    • Python dtype: ModelPatcher
  • config
    • The config parameter determines the configuration settings for the layered diffusion model, specifying how the model should be applied and operated.
    • Comfy dtype: COMBO[STRING]
    • Python dtype: str
  • weight
    • Weight defines the influence level of the layered diffusion process on the final image output, adjusting the intensity of the applied transformations.
    • Comfy dtype: FLOAT
    • Python dtype: float

Output types

  • model
    • Comfy dtype: MODEL
    • The output model after applying the layered diffusion process, reflecting the transformations and refinements made to the original model.
    • Python dtype: ModelPatcher

Usage tips

  • Infra type: GPU
  • Common nodes: unknown

Source code

class LayeredDiffusionFG:
    """Generate foreground with transparent background."""

    @classmethod
    def INPUT_TYPES(s):
        return {
            "required": {
                "model": ("MODEL",),
                "config": ([c.config_string for c in s.MODELS],),
                "weight": (
                    "FLOAT",
                    {"default": 1.0, "min": -1, "max": 3, "step": 0.05},
                ),
            },
        }

    RETURN_TYPES = ("MODEL",)
    FUNCTION = "apply_layered_diffusion"
    CATEGORY = "layer_diffuse"
    MODELS = (
        LayeredDiffusionBase(
            model_file_name="layer_xl_transparent_attn.safetensors",
            model_url="https://huggingface.co/LayerDiffusion/layerdiffusion-v1/resolve/main/layer_xl_transparent_attn.safetensors",
            sd_version=StableDiffusionVersion.SDXL,
            injection_method=LayerMethod.ATTN,
        ),
        LayeredDiffusionBase(
            model_file_name="layer_xl_transparent_conv.safetensors",
            model_url="https://huggingface.co/LayerDiffusion/layerdiffusion-v1/resolve/main/layer_xl_transparent_conv.safetensors",
            sd_version=StableDiffusionVersion.SDXL,
            injection_method=LayerMethod.CONV,
        ),
        LayeredDiffusionBase(
            model_file_name="layer_sd15_transparent_attn.safetensors",
            model_url="https://huggingface.co/LayerDiffusion/layerdiffusion-v1/resolve/main/layer_sd15_transparent_attn.safetensors",
            sd_version=StableDiffusionVersion.SD1x,
            injection_method=LayerMethod.ATTN,
            attn_sharing=True,
        ),
    )

    def apply_layered_diffusion(
        self,
        model: ModelPatcher,
        config: str,
        weight: float,
    ):
        ld_model = [m for m in self.MODELS if m.config_string == config][0]
        assert get_model_sd_version(model) == ld_model.sd_version
        if ld_model.attn_sharing:
            return ld_model.apply_layered_diffusion_attn_sharing(model)
        else:
            return ld_model.apply_layered_diffusion(model, weight)