VQ encoder diffusers (middlek)
Encode an image into VQ latent space — the quiet half of the pack's codec duo
- vq
- images
- LATENT
VQEncoder is the input half of the pack's alternative latent codec: it takes an image, pushes it through a diffusers VQModel (loaded by VQLoader), and hands you the resulting quantized latents. If the VQ path is a niche, this node is the unglamorous workhorse within it - it's what turns a product photo into the latent representation that Kandinsky-style latent composition operates on.
How it works
Straightforward wrapper with three real steps. It normalizes the image from [0,1] to [-1,1] (the range diffusers models expect), permutes it from B,H,W,C into B,C,H,W, and calls vqmodel.encode(...)["latents"]. Then it packages the result as a standard {"samples": ...} latent dict, which is what keeps it interoperable with everything else in ComfyUI. The model is moved to the compute device for the encode and back off to intermediate memory afterwards - a small VRAM courtesy.
The inputs and output
vq- theVQmodel fromVQLoader.images- anIMAGE, the thing you want encoded.- Returns a
LATENTdict - feed it toVQDecoder, or into latent-space composition likeDetailTransferLatentAdd.
Note the input name is images (plural) and it handles batches fine - handy if you're encoding a batch of product shots.
Install
cd ComfyUI/custom_nodes
git clone https://github.com/MiddleKD/ComfyUI-productfix
pip install -r requirements.txt
Restart. Requires diffusers (pack dependency) plus a VQ model already loaded via VQLoader.
Gotchas
- Not a VAE. The latents here are quantized (that's what the "Q" is for), with a different structure and resolution behavior than SD VAE latents. Don't assume a VAE decode node can read them.
- Model must be loaded first -
VQEncoderhas no fallback; ifvq_namewas never set inVQLoader, there's nothing to encode with. - Output assumes
sampleslayout - which is what the node produces, so the pair is self-consistent.
The plain truth: you will only touch this node if you've committed to the VQ composition path, and that path is deep enough that the pack's own demos barely depend on it. But as far as diffusers VQModel wrappers go, this one is clean, batched, and does exactly one job.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| vq | VQ | — | |
| images | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| LATENT | LATENT | — |