Nodes/KJNodes for ComfyUI/Get Latent Size & Count
ComfyUI Node Runs on cloud

Get Latent Size & Count

Read a latent's real dimensions

By kijai·Created 3 years ago·Updated about 14 hours ago· 2,930
Get Latent Size & Count
  • latent
  • latent
  • batch_size
  • channels
  • frames
  • height
  • width

Latents are opaque. Once your image or video is encoded into latent space, you can't see it, and you often can't easily tell how big it is or how many frames or images are riding along in the batch. GetLatentSizeAndCount cracks it open and reads out the numbers, then passes the latent through untouched so you can tap it inline without breaking the chain.

It's a utility node from kijai's KJNodes. You'll want it any time you're building something that has to react to latent dimensions, especially in video work where frame counts and the 4x temporal compression make the arithmetic easy to get wrong.

How it works

It inspects the latent tensor and reports its shape as separate integer outputs, while forwarding the latent itself unchanged from the latent output. Because it's a pass-through, you can splice it into an existing wire (KSampler → GetLatentSizeAndCount → next node) and pull the numbers off without disturbing the data flow.

The reason this matters: latent dimensions are not your pixel dimensions. The VAE downsamples spatially (typically 8x), and for video the latent is also compressed in time. So a latent's height/width are in latent units, and its frame count is the compressed count. Being able to read the true shape is what lets you wire those numbers into resize nodes, math nodes, or anything that needs to match dimensions programmatically.

The inputs and outputs that matter

  • latent (input) - the latent to measure.

Outputs:

  • latent - the same latent, passed through unchanged.
  • batch_size - how many items are in the batch (images, or the batch dimension).
  • channels - the number of latent channels.
  • frames - the temporal dimension. For a still image this is trivial; for video this is the one you'll actually use.
  • height and width - the spatial size in latent units, not pixels.

The move is to route those INT outputs into whatever needs to adapt: feed width/height into a downstream latent op, or frames into a node that has to know the clip length.

Installing it

You probably have KJNodes already. If not: ComfyUI Manager → search KJNodes for ComfyUI → install → restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/kijai/ComfyUI-KJNodes
pip install -r ComfyUI-KJNodes/requirements.txt

Restart ComfyUI. No models or heavy dependencies.

Common issues

"Height and width are way smaller than my image." Right, those are latent dimensions. With an 8x VAE, a 1024px image reads as 128 in latent space. Multiply back up by your VAE's spatial factor if you need pixel dimensions.

"Frames doesn't match the length of my video." Video VAEs compress time (Wan's compresses roughly 4x, for example), so the latent frame count is the compressed count, not the decoded one. That's expected. If you're chasing why a clip decodes to a slightly different length than you set, this temporal compression, and the off-by-a-few-frames rounding it causes, is usually the reason.

"It's not changing my latent." Correct, it's not supposed to. This is a read-only probe; the latent output is the input verbatim.

CategoryKJNodes/image

Inputs (1)

NameTypeDefaultDescription
latentLATENT

Outputs (6)

NameTypeDescription
latentLATENT
batch_sizeINT
channelsINT
framesINT
heightINT
widthINT