Pt From Image Transpose
The bridge that makes images usable by PyTorch models
- image
- TENSOR
Here's a mismatch that quietly ruins image-classification workflows: ComfyUI thinks in (H, W, C) - height, width, channels - but PyTorch models (ResNet, CNN layers, the whole torchvision family) expect (C, H, W), channels first. Pt From Image Transpose is the bridge. Drop an image in, get a channels-first tensor out, ready for a model node.
It's the standard front door for image work in ComfyUI-Pt-Wrapper (HowToSD's no-code PyTorch training pack, the spin-off of ComfyUI-Data-Analysis). The README's dog-vs-cat classifier and the ResNet-on-CIFAR-10 example both start here: image → this node → Ptn Resnet Model → training. If you're doing any image classification inside the pack, this is where the pipeline begins.
How it works. It's a permute, not a magic conversion:
- Rank-3 input (a single
(H, W, C)image) → transposed to(C, H, W). - Rank-4 input (a batch,
(N, H, W, C)) → transposed to(N, C, H, W), keeping the batch axis in front where PyTorch expects it.
One input, image (an IMAGE from any ComfyUI image node - a Load Image, a sampler output, whatever). One output, TENSOR, in the pack's channels-first convention.
What it does not do - and this is the part that trips people up. It doesn't normalize, and it doesn't batch. ComfyUI images are floats in the 0–1 range, and most pretrained image models expect inputs scaled a specific way (mean/std normalization, sometimes 0–255). This node only rearranges axes; you handle value scaling with the pack's math nodes or your own preprocessing. Similarly, a single image in gets a rank-3 tensor out - if your model wants a (1, C, H, W) batch, you still need Pt Unsqueeze to add the batch axis. And because it only accepts rank 3 or 4, feeding it a weird-shaped tensor raises a clear "Only rank 3 or 4 tensors are supported" error - read that as "you wired an image, not a latent."
The one to watch: make sure the thing on the other side of this node is actually a PyTorch-convention consumer. If you point this at a ComfyUI-native node that wants (H, W, C), you've just transposed your image sideways and it'll look scrambled. This node is a one-way door between ComfyUI image space and pack tensor space - the return trip is a different node (Pt To Latent, or converting back to an image).
Install: ComfyUI Manager → search "ComfyUI-Pt-Wrapper", or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
then restart. No model downloads for this one - the pack's heavy requirements.txt (transformers, sklearn, sentencepiece, pinned gensim) is the only install cost.
Troubleshooting: scrambled/sideways images downstream - you fed the transposed tensor back into a ComfyUI-native image consumer; don't. Shape errors - check you're passing an actual image, not a latent or mask. "Only rank 3 or 4" - same thing; rank-2 masks and rank-1 arrays won't pass. Wrong batch behavior - remember single images stay rank 3; add the batch axis yourself.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |