Nodes/WAS LMStudio Easy-Query/WAS Load Image Directory
ComfyUI Node

WAS Load Image Directory

The folder-scanning half of the batch captioning machine

By WASasquatch·Created 11 months ago·Updated 6 months ago· 19
WAS Load Image Directory
    • dataset
    directory_path
    recursivetrue
    extensions.png,.jpg,.jpeg,.webp,.bmp
    dataset_output_path
    copy_imagesfalse
    force_aspectnone
    max_size1024
    resize_modenone
    normalize_aspect_ratiosfalse

    WAS Load Image Directory doesn't talk to any model. It doesn't caption anything. It's the boring, vital data-prep half of the WAS LMStudio Easy-Query pack: it walks a folder, finds the images, and bundles them - plus every resizing and output decision for the job - into one LMSTUDIO_DATASET_IMAGES dict that the caption dataset nodes consume. If you're captioning a folder of training images, this node is step one, every time.

    It's deliberately opinionated about what it hands downstream. Because the whole point is preparing a batch for a vision model, the node can normalize the images before they ever reach LM Studio - which matters when your folder mixes 4K scans and phone crops. max_size caps the longest edge (512 to 2048), force_aspect pins images to a ratio (1:1, 16:9, 9:16, and the rest), and resize_mode decides how: crop_center crops to fit, stretch distorts, pad letterboxes, fit scales to fit. There's even a normalize_aspect_ratios toggle that analyzes the whole set, buckets images into landscape/portrait/square groups, and uses each group's median aspect ratio - the kind of thing you'd normally script yourself when a trainer wants uniform buckets.

    Inputs worth setting:

    • directory_path - absolute path to the folder. Must be under an allowed root (see below) or the node raises.
    • recursive (default on) - recurse into subfolders.
    • extensions - comma-separated list, defaults to .png,.jpg,.jpeg,.webp,.bmp.
    • dataset_output_path - optional output directory for captions. Must also be under an allowed root.
    • copy_images - with an output path that differs from the image folder, copy each image next to its caption file, so you get a clean assembled dataset without touching the originals.

    The single output, dataset, is that dict of file paths plus the metadata keys (output path, copy flag, aspect/resize settings) the caption nodes read. Wire it into either caption dataset node.

    The one thing that trips everyone up is the security gate, and it's intentional. The README is blunt: for safety, this node only touches directories explicitly whitelisted in lmstudio_config.json under allowed_root_directories. Add your dataset path, restart ComfyUI:

    "allowed_root_directories": ["/mnt/k/datasets", "/home/user/images"]
    

    Forward slashes even on Windows; subdirectories of an allowed root are automatically fine; paths are case-sensitive on Linux/Mac. Get this wrong and loading fails with a message telling you to update the config - the node isn't shy about it.

    Install it with the pack, since it ships inside:

    cd ComfyUI/custom_nodes
    git clone https://github.com/WASasquatch/ComfyUI_LMStudio_EasyQuery
    

    restart ComfyUI, and pip install lmstudio numpy Pillow for the Python side (the node itself uses Pillow and numpy for the image work, not the LM Studio SDK).

    Practical tips: keep max_size at or below what the Model node's image_max_size expects, or you'll pay for wasted pixels in context. And copy_images plus a separate dataset_output_path is the move if you're building a training set and don't want to risk touching your source folder - it's the difference between "prep" and "destructive prep" for free.

    CategoryLM Studio

    Inputs (9)

    NameTypeDefaultDescription
    directory_pathSTRINGAbsolute path to a directory containing images. Must be under an allowed root.
    recursiveBOOLEANtrueRecurse into subdirectories.
    extensionsSTRING.png,.jpg,.jpeg,.webp,.bmpComma-separated list of image file extensions to include.
    dataset_output_pathSTRINGOptional output directory for captions (and images if copy is enabled). Must be under an allowed root if provided.
    copy_imagesBOOLEANfalseIf enabled and an output path is provided that differs from the image directory, copy each image alongside its caption file.
    force_aspectCOMBOnoneForce images to a specific aspect ratio. 'none' keeps original aspect.
    max_sizeCOMBO1024Maximum resolution (longest edge) for resized images.
    resize_modeCOMBOnoneResize/crop method: 'none' (no resize), 'crop_center' (crop to aspect), 'stretch' (distort to fit), 'pad' (letterbox), 'fit' (scale to fit).
    normalize_aspect_ratiosBOOLEANfalseAutomatically normalize aspect ratios by analyzing the dataset and grouping images into landscape/portrait/square buckets with median aspect ratios.

    Outputs (1)

    NameTypeDescription
    datasetLMSTUDIO_DATASET_IMAGES