Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:AUTOMATIC1111 Stable diffusion webui Postprocessing input selection

From Leeroopedia


Knowledge Sources
Domains Image Processing, Software Architecture, Pipeline Design
Last Updated 2026-02-08 00:00 GMT

Overview

Postprocessing input selection is the principle of dispatching image postprocessing operations across multiple input modes -- single image, batch upload, and batch directory -- through a unified processing interface.

Description

In image generation workflows, users commonly need to apply postprocessing operations (upscaling, face restoration, caption editing) to images that arrive from fundamentally different sources. A single image may come from a just-completed generation, a set of uploaded files may come from a user's local machine, or an entire directory of images may need batch processing on a server.

The mode dispatch pattern solves this by normalizing all three input sources into a common iterator of (image, filename) pairs. Regardless of whether the source is a single PIL Image, a list of uploaded file handles, or a directory path, the downstream pipeline receives the same interface. This decouples the input acquisition logic from the postprocessing logic, following the principle of separation of concerns.

The three canonical modes in image postprocessing pipelines are:

  • Mode 0 -- Single Image: A single PIL Image object is provided directly. No filename is associated with it; the output naming follows automatic sequencing conventions.
  • Mode 1 -- Batch Upload: A collection of uploaded image files (typically from a web UI file selector). Each file carries an original filename that can be preserved in the output.
  • Mode 2 -- Batch Directory: A filesystem path to a directory containing images. The pipeline enumerates all valid image files in the directory and processes them sequentially. An optional output directory can be specified separately from the default output path.

Usage

Use the postprocessing input selection pattern when:

  • Building an image processing interface that must accept images from multiple sources (web upload, filesystem, API)
  • Implementing batch processing pipelines where the user may provide anything from a single image to thousands of files
  • Designing a system where postprocessing scripts should be agnostic to how input images were acquired
  • Creating server-side batch workflows that process entire directories while preserving original filenames

Theoretical Basis

The mode dispatch pattern is a specialization of the Strategy pattern, where the input acquisition strategy is selected by a mode identifier. In pseudocode:

def get_images(mode, single_image, uploaded_files, input_dir):
    if mode == SINGLE:
        yield (single_image, None)
    elif mode == BATCH_UPLOAD:
        for file in uploaded_files:
            image = load_image(file)
            yield (image, file.original_name)
    elif mode == BATCH_DIRECTORY:
        for path in list_image_files(input_dir):
            yield (path, path)  # lazy loading: path resolved later

Key design properties of this pattern:

  • Lazy loading: In directory mode, images are not all loaded into memory at once. File paths are yielded first and resolved to PIL Image objects only when the processing loop reaches them, enabling processing of directories with thousands of images.
  • Filename preservation: Batch modes carry original filenames through the pipeline so output files can maintain meaningful names (using the use_original_name_batch option).
  • Interruption support: The processing loop checks for user-initiated interruption or skip signals between each image, enabling responsive cancellation even during large batch operations.
  • Job tracking: The total number of images is determined upfront (by materializing the iterator into a list) so that progress reporting can show "N of M" completion status.

The tradeoff of materializing the full list upfront (rather than streaming) is acceptable because the list contains only file paths or lightweight references, not the full image data.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment