KJNodes/latentsgenerated

Get Latents From Batch Indexed(GetLatentsFromBatchIndexed)

This node supports three different latent data formats: BCHW, BTCHW, and BCTHW

Get Latents From Batch Indexed

latents
LATENT
indexes
0, 1, 2
latent_format
BCHW
KJNodes

The Get Latents From Batch Indexed node supports three different latent data formats: BCHW, BTCHW, and BCTHW.

The Get Latents From Batch Indexed node is a tool for processing latent space data. Its core function is to precisely select one or more specific latent vectors from a batch containing multiple latent vectors based on user-specified index positions and output them as a new batch.

Node Functionality

This node supports three different latent data formats: BCHW, BTCHW, and BCTHW. The user specifies the dimensional structure of the input data via the latent_format parameter. Internally, the node parses the batch dimension according to this format and uses PyTorch's tensor indexing functionality to extract the latent vectors specified by the indexes parameter from the input latents. Its core mechanism involves converting the user-input, comma-separated index string into a list of integers and performing data slicing accordingly.

Node Parameter Description - Get Latents From Batch Indexed

Connection Inputs (Inputs)

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
latentsLATENTYes--The input data containing a batch of latent vectors. The node will extract samples at the specified indices from this data.

Control Parameters (Parameters)

Parameter NameData TypeRequiredDefault ValueRange/OptionsDescription
latent_formatCOMBOYesBCHW"BCHW", "BTCHW", "BCTHW"Specifies the format of the input latent data: "BCHW" (Batch, Channel, Height, Width), "BTCHW" (Batch, Time, Channel, Height, Width), or "BCTHW" (Batch, Channel, Time, Height, Width). The node will determine the batch dimension based on this format and perform indexing operations.
indexesSTRINGYes0, 1, 2-Specifies the index positions of the latent vectors to be extracted from the batch. The input format is a comma-separated string of integers, e.g., "0, 2, 5".

Output

Parameter NameData TypeDescription
LATENTLATENTOutputs a new batch of data containing only the latent vectors corresponding to the selected indices.

Usage Scenarios

This node is very useful in workflows for video generation or image sequence processing. For example, after using a batch processing node to generate a sequence of latent vectors containing multiple timesteps (frames), you can use this node to quickly extract the 1st, 3rd, and 5th frames from the sequence for subsequent individual editing or analysis, thereby achieving fine-grained control over the generated content.

Notes

Please note that the input index values must be integers within the valid range of the input batch and separated by commas. Specifying an index that exceeds the actual size of the batch may cause a runtime error.

The Get Latents From Batch Indexed node is from the ComfyUI-KJNodes node package.

Comments

Sign in with GitHub to join the discussion.

Loading comments…