Pt To Image Transpose
For when your tensor refuses to look like an image
- tens
- image
Every PyTorch beginner hits this wall: your model hands you a tensor in CHW (channel, height, width), and ComfyUI wants HWC (height, width, channel), and the two absolutely will not agree on what "the image" looks like. Pt To Image Transpose is the node that bridges that gap properly. It casts a TENSOR to IMAGE and transposes it from CHW to HWC in one step, so what you preview actually looks like the thing you trained.
One input (tens, TENSOR), one output named image (IMAGE). For a rank-3 tensor it does permute(1, 2, 0) - moves the channel axis to the end. For rank-4 (batched) input it permutes to (B, H, W, C) and keeps the batch axis intact, which is handy when a whole batch comes out of training in one shot. Anything that isn't rank 3 or 4 raises a clear ValueError rather than producing garbage, which is more courtesy than most of the pack bothers with.
The mental model: this is the node to reach for when a tensor's shape ends in C - when the last axis is channels - and you want it in ComfyUI where the last axis is also channels but the middle axes are H and W. If your data is already in HWC (last axis is channels, 0–1 floats), you don't need the transpose; plain Pt To Image does the cast alone. The confusion between those two nodes is the single most common mistake people make here, and it's worth a second of thought every time you grab one.
Range still matters: ComfyUI expects 0–1 floats. A CHW tensor straight out of a classifier's logits, or a 0–255 byte tensor, will preview as garbage no matter how perfectly it's transposed.
Install
ComfyUI Manager (search "ComfyUI-Pt-Wrapper"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Restart ComfyUI. Heavy dependency tree (transformers, datasets, peft, accelerate, scikit-learn, pandas, seaborn, matplotlib, gensim, sentencepiece) makes the first launch slow. No model files to download.
Common issues
If your preview is still scrambled after this node, the input wasn't actually CHW - double-check the shape with a size/print node before assuming. If you get a ValueError about rank, you've fed it something with more than four dimensions or fewer than three; reshape first. And remember the transpose fixes layout, never range - normalize to 0–1 before you expect a pretty picture.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| tens | TENSOR | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |