Ptv Transforms To Tensor
The image-to-tensor step every training pipeline needs
- PTVTRANSFORM
Ptv Transforms To Tensor produces the transform that converts images to PyTorch tensors - the mandatory first step in any image training pipeline. Images aren't tensors, and models only eat tensors. This is the node that bridges the two, and it's so basic you'll barely think about it, which is exactly what a foundation node should be.
It ships in ComfyUI-Pt-Wrapper, the ~200-node pack that brings PyTorch data loading and model training into ComfyUI's graph. The Ptv prefix marks the dataset side of the family: these nodes hand out PTVTRANSFORM recipes that the dataset and dataloader nodes apply to your data.
How it works
The mechanism is one torchvision transform:
transforms.Compose([transforms.ToTensor()])
The output is a PTVTRANSFORM - a recipe, not a tensor. You wire it into a dataset node, and when the dataset loads each image the transform converts it from a PIL image into a C,H,W tensor (channels first) with pixel values scaled from the usual 0-255 range down to [0.0, 1.0]. That normalization to a consistent range is important: models train dramatically better on well-scaled inputs, and this node does it for you on every image, automatically.
The difference between this node and PtvTransformsResize is simply that this one only converts - no resizing. Use this alone when your images are already the right size, or combine it with the resize transform when they're not. (Technically PtvTransformsResize already includes a ToTensor internally - so if you're resizing, you don't need both.)
Inputs and outputs
The simplest node in the pack:
- No inputs. There are genuinely zero knobs here - conversion to tensor is deterministic and needs no parameters.
PTVTRANSFORMoutput - the tensor-conversion transform, ready to wire into a dataset node.
Installing the pack
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Restart ComfyUI. Or use ComfyUI Manager → search "ComfyUI-Pt-Wrapper" → install; it's registered on the Comfy Registry, and Manager pulls the Python dependencies (pandas, scikit-learn, transformers, sentencepiece and the rest) for you. The pack's example workflows in examples/workflows/ show this node sitting between your image folder and the dataloader.
Common issues
- "Image is not a PIL image" style errors.
ToTensorexpects images in PIL format. If your dataset node hands it something else (raw arrays, a different format), you'll hit a conversion error at that spot. - Forgetting the transform entirely. The classic silent failure: dataset loads, but nothing converts to tensor, and the model errors on input type. Wiring a
PTVTRANSFORMfrom this node (or its resize sibling) into the dataset is the fix.
It's two lines of torchvision wearing a node costume. But every training pipeline that works starts with data in the right format, and this is the node that guarantees it.
Inputs (0)
No inputs
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTVTRANSFORM | PTVTRANSFORM | — |