Nodes/ComfyUI_MS_Diffusion/MS_Object_img_Batch
ComfyUI Node

MS_Object_img_Batch

The Unsexy Glue Node That Makes MS-Diffusion Multi-Subject Actually Work

By smthemex·Created 2 years ago·Updated 2 years ago· 58
MS_Object_img_Batch
  • image_a
  • image_b
  • image_c
  • image_d
  • IMAGE

Every pack has a node that isn't clever, isn't impressive, and is quietly the thing that makes the whole technique work. In ComfyUI_MS_Diffusion, that node is MS_Object_img_Batch. It exists for exactly one reason: MS-Diffusion's hard rule that you need one reference image per [object] in your prompt. This node stacks up to four reference images into a single batch so the sampler gets them as one input.

It's the difference between a workflow that does "two objects" and a workflow that does "two objects and actually works." The pack ships only three nodes total - loader, sampler, and this - so when a shared MS-Diffusion workflow has a mystery IMAGE batch feeding the sampler, this is almost certainly what produced it.

How it works

Nothing fancy under the hood, and that's the point. image_a is required; image_b, image_c, and image_d are optional. Any of the extras you connect get resized to match image_a's dimensions, then everything is concatenated along the batch axis with torch.cat. What comes out is one IMAGE tensor with N frames, where N is how many objects you're personalizing.

That resizing matters, by the way: the output is always the size of image_a, so feed your biggest or most important reference in the a slot and accept that the others will be squashed to match. For portrait-style subjects the distortion is usually harmless; for anything where proportions matter, resize the rest beforehand in an upscaler so the squash is gentle.

Inputs and output

The inputs that matter are exactly the ones that sound like they matter:

  • image_a (required) - the first reference image.
  • image_b / image_c / image_d (optional) - references two through four.

Output is a single IMAGE batch, which goes straight into MSdiffusion_Sampler's image input. For a single-object workflow you can skip this node entirely and feed the sampler one image directly - this node only earns its keep at two or more subjects.

The one real limitation

The ad slots cap you at four subjects per batch. MS-Diffusion's paper demos more, but this pack's glue stops at four - if you're chasing a five-subject composition, you'll have to batch the images yourself (concatenate along the batch dimension with a batch/combine node) before they reach the sampler. Don't expect this node to grow; it does one thing and does it without options or dials.

Installing

It's part of the same pack as the other two nodes, so there's no separate install:

cd ComfyUI/custom_nodes
git clone https://github.com/smthemex/ComfyUI_MS_Diffusion
cd ComfyUI_MS_Diffusion && pip install -r requirements.txt

or via ComfyUI Manager ("ComfyUI_MS_Diffusion"), then restart. Yes, you install the whole pack for this little utility - that's the price of the trio. And yes, the thin requirements file (tensorboard, scipy, PyYAML) means you may still need pip install diffusers transformers omegaconf safetensors before the pack loads at all. It's three minutes of setup for a node whose entire job is stacking four pictures. Worth it once you see what the sampler does with them.

CategoryMSdiffusion

Inputs (4)

NameTypeDefaultDescription
image_aIMAGE
image_boptIMAGE
image_coptIMAGE
image_doptIMAGE

Outputs (1)

NameTypeDescription
IMAGEIMAGE