KJNodes/imagegenerated

Shuffle Image Batch(ShuffleImageBatch)

This node technically accepts a four-dimensional tensor as input, with a shape of `(B, H, W, C)`, representing batch size, image height, width, and number of channels respectively.

Shuffle Image Batch

images
IMAGE
seed
123
KJNodes

The Shuffle Image Batch node technically receives a four-dimensional tensor as input, with a shape of (B, H, W, C), representing batch size, image height, width, and number of channels respectively.

The Shuffle Image Batch node is a tool for randomly shuffling the order of an image batch. Its core function is to receive a batch containing multiple images and rearrange them in a random order. This helps introduce randomness into the image processing pipeline, avoiding potential patterns caused by a fixed order.

Node Function

This node technically receives a four-dimensional tensor as input, with a shape of (B, H, W, C), representing batch size, image height, width, and number of channels respectively. Internally, the node uses PyTorch's torch.randperm function to generate a randomly permuted index based on the seed provided by the user. It then reorders the images along the batch dimension according to this index, ultimately outputting a new batch with the same shape but with the image order shuffled.

Node Parameter Description - Shuffle Image Batch

Connection Inputs (Inputs)

Parameter NameData TypeRequiredDefault ValueValue Range/OptionsDescription
imagesIMAGEYes--images (input parameter): The input image batch whose order needs to be shuffled. The parameter type is IMAGE, there is no default value, and it must be connected.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueValue Range/OptionsDescription
seedINTYes1230 - 18446744073709552000 (Step: 1)seed (input parameter): The seed value that controls the random shuffling order. The parameter type is INT, the default value is 123, the value range is 0 to 18446744073709552000, and the step size is 1.

Output

Parameter NameData TypeDescription
IMAGEIMAGEIMAGE (output parameter): The output image batch whose order has been randomly shuffled.

Usage Scenarios

In practical applications, this node is often used for data augmentation or creating diverse preview galleries. For example, in a batch image generation pipeline, after merging the outputs of multiple generators, using this node to shuffle the order before feeding them into subsequent preview or filtering nodes allows for a fairer comparison of results under different generation conditions or prepares randomized samples for a training set.

Notes

Please note that this node only changes the order of images within the batch and does not modify the pixel content of any single image. Its randomness is entirely controlled by the seed parameter; using the same seed will always produce the same shuffle order.

The Shuffle Image Batch node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…