Nodes/OmniNodes/Aspect Ratio Bucket πŸ“
ComfyUI Node

Aspect Ratio Bucket πŸ“

Every image snapped to the bucket the trainer expects, no squashing

By TensorVizionΒ·Created 3 months agoΒ·Updated about 8 hours agoΒ· 0
Aspect Ratio Bucket πŸ“
  • image
  • bucketed_image
  • bucket_resolution
  • report
β—„bucket_setβ–Ύβ–Ί

LoRA and fine-tune trainers work best when every training image is a resolution the model actually knows - that's what "bucketing" is, the set of aspect ratios a model was trained on. Throw a trainer a batch of images in random shapes and you either get squashed results or silent failures at the resize step. Aspect Ratio Bucket exists for the boring, essential job of dataset prep: it snaps each image to the nearest standard SD1.5 or SDXL training bucket and resizes to that exact resolution.

Pick bucket_set:

  • sdxl - the standard SDXL multi-aspect set, 1024-area buckets: 1024Γ—1024, 1152Γ—896, 896Γ—1152, 1216Γ—832, 832Γ—1216, 1344Γ—768, 768Γ—1344, 1536Γ—640, 640Γ—1536.
  • sd15 - the same shape of set scaled to 512-area buckets for SD1.5.

The mechanism is the part that makes it correct: it compares your image's aspect ratio against the bucket table, picks the nearest, then center-crops to that exact ratio before resizing. Crop, then resize - no distortion. Excess content on the sides (or top/bottom) gets trimmed rather than squeezed into a wrong shape. For dataset prep that distinction is the whole ballgame; a trainer sees clean, undistorted crops instead of images that silently changed shape.

Outputs: bucketed_image (the fixed-up frame), bucket_resolution (the chosen WxH as a string), and report - a text summary of which bucket won and how much was cropped. The report output is your friend when eyeballing a batch; wire it to a display node and you can confirm at a glance that, say, all the 16:9 shots landed in 1536Γ—640 instead of getting mangled.

Honest context: this is a prep node, not a glamorous one, and its value is entirely "did the right thing quietly." For a single image here or there you'd just crop by hand; for a 500-image dataset you don't want to. It pairs naturally with the pack's Face Detect & Crop when prepping character datasets - crop the face, then bucket the result so it matches what the trainer expects.

The one real limitation to know: cropping is lossy by design. A strongly-off-ratio image (say a 21:9 panorama) gets a big chunk cropped off to reach a bucket, which may not be what you want. There's no "pad instead of crop" option here. If you'd rather letterbox than cut, this isn't the node - but for typical photographic material the crop is exactly what a trainer wants, because it's what the model's own training data looked like.

Install

Part of OmniNodes:

cd ComfyUI/custom_nodes
git clone https://github.com/TensorVizion/OmniNodes

Restart ComfyUI, or install "OmniNodes" via ComfyUI Manager. No extra dependencies - pure NumPy/PyTorch.

Troubleshooting

  • Images come out cropped more than expected - the input ratio is far from every bucket. Check report for the crop math; for extreme ratios, crop the source first to a ratio near a bucket.
  • Wrong bucket set for my model - sdxl and sd15 are the two presets. A modern base with a different native area isn't covered; you'd use a custom resize instead.
CategoryTensorVizion/Image

Inputs (2)

NameTypeDefaultDescription
imageIMAGEβ€”
bucket_setCOMBO2 options: sdxl, sd15

Outputs (3)

NameTypeDescription
bucketed_imageIMAGEβ€”
bucket_resolutionSTRINGβ€”
reportSTRINGβ€”