Skip to content

XY Input: VAE

Documentation

  • Class name: XY Input: VAE
  • Category: Efficiency Nodes/XY Inputs
  • Output node: False

The node is designed to facilitate the integration and manipulation of VAE (Variational Autoencoder) models within a generative art pipeline, specifically tailored for generating or transforming images based on VAE characteristics. It abstracts the complexities of handling VAE models, including loading, encoding, and decoding operations, to streamline the creation of visual content.

Input types

Required

  • input_mode
    • Specifies the mode of input, determining whether VAE models are loaded individually or in batches, which influences how the VAE files are processed and utilized in the pipeline.
    • Comfy dtype: COMBO[STRING]
    • Python dtype: str
  • batch_path
    • The filesystem path to a directory containing batch VAE files, used when 'input_mode' is set to batch processing, enabling the node to locate and operate on multiple VAE models.
    • Comfy dtype: STRING
    • Python dtype: str
  • subdirectories
    • A boolean flag indicating whether to include VAE files from subdirectories within 'batch_path' during batch processing, expanding the scope of VAE models to be considered.
    • Comfy dtype: BOOLEAN
    • Python dtype: bool
  • batch_sort
    • Determines the order in which VAE files are processed in batch mode, supporting ascending or descending sort orders to influence the sequence of VAE model utilization.
    • Comfy dtype: COMBO[STRING]
    • Python dtype: str
  • batch_max
    • Sets a limit on the number of VAE files to be processed in batch mode, allowing for control over the maximum number of VAE models to be included in the operation.
    • Comfy dtype: INT
    • Python dtype: int
  • vae_count
    • Specifies the number of individual VAE models to be loaded and processed when not in batch mode, guiding the node in how many VAE models to expect and handle.
    • Comfy dtype: INT
    • Python dtype: int
  • vae_name_i
    • Identifies each individual VAE model by name when not using batch mode, allowing for specific VAE models to be selected and loaded for processing.
    • Comfy dtype: COMBO[STRING]
    • Python dtype: str

Output types

  • X or Y
    • Comfy dtype: XY
    • The output represents either 'X' or 'Y' values processed or generated by the node, typically related to the VAE models' data or characteristics.
    • Python dtype: tuple

Usage tips

  • Infra type: CPU
  • Common nodes: unknown

Source code

class TSC_XYplot_VAE:

    modes = ["VAE Names", "VAE Batch"]

    @classmethod
    def INPUT_TYPES(cls):

        vaes = ["None", "Baked VAE"] + folder_paths.get_filename_list("vae")

        inputs = {
            "required": {
                        "input_mode": (cls.modes,),
                        "batch_path": ("STRING", {"default": xy_batch_default_path, "multiline": False}),
                        "subdirectories": ("BOOLEAN", {"default": False}),
                        "batch_sort": (["ascending", "descending"],),
                        "batch_max": ("INT", {"default": -1, "min": -1, "max": XYPLOT_LIM, "step": 1}),
                        "vae_count": ("INT", {"default": XYPLOT_DEF, "min": 0, "max": XYPLOT_LIM, "step": 1})
            }
        }

        for i in range(1, XYPLOT_LIM+1):
            inputs["required"][f"vae_name_{i}"] = (vaes,)

        return inputs

    RETURN_TYPES = ("XY",)
    RETURN_NAMES = ("X or Y",)
    FUNCTION = "xy_value"
    CATEGORY = "Efficiency Nodes/XY Inputs"

    def xy_value(self, input_mode, batch_path, subdirectories, batch_sort, batch_max, vae_count, **kwargs):

        xy_type = "VAE"

        if "Batch" not in input_mode:
            # Extract values from kwargs
            vaes = [kwargs.get(f"vae_name_{i}") for i in range(1, vae_count + 1)]
            xy_value = [vae for vae in vaes if vae != "None"]
        else:
            if batch_max == 0:
                return (None,)

            try:
                vaes = get_batch_files(batch_path, VAE_EXTENSIONS, include_subdirs=subdirectories)

                if not vaes:
                    print(f"{error('XY Plot Error:')} No VAE files found.")
                    return (None,)

                if batch_sort == "ascending":
                    vaes.sort()
                elif batch_sort == "descending":
                    vaes.sort(reverse=True)

                # Construct the xy_value using the obtained vaes
                xy_value = [vae for vae in vaes]

                if batch_max != -1:  # If there's a limit
                    xy_value = xy_value[:batch_max]

            except Exception as e:
                print(f"{error('XY Plot Error:')} {e}")
                return (None,)

        return ((xy_type, xy_value),) if xy_value else (None,)