Nodes/ComfyUI-Pt-Wrapper/Pt Interpolate By Scale Factor
ComfyUI Node

Pt Interpolate By Scale Factor

2x upscale any tensor, not just images

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Interpolate By Scale Factor
  • tens
  • TENSOR
scale_factor2.00
mode

This is torch.nn.functional.interpolate with a multiplier instead of a target size. You give it a tensor and a scale_factor of, say, 2, and it resizes along the spatial dimensions. It's the sibling of Pt Interpolate To Size - that one takes exact height and width, this one takes a ratio. If you're resizing image tensors after converting them into the pack's world, or scaling feature maps up before feeding them somewhere, this is the node.

How it works

The input tensor must be (c, h, w) or (b, c, h, w) - note the channel-first layout. If you feed a rank-3 tensor it quietly unsqueezes to a batch of one, interpolates, then squeezes the batch axis back off. The resize itself is F.interpolate(..., scale_factor=scale_factor, mode=mode).

The scale_factor slider runs 0.01 to 100 (default 2), so it downscales too, not just up. mode is a dropdown with the four torch modes: nearest-exact, bilinear, bicubic, nearest. For image-like data, bicubic is the good-looking one; nearest is the fast blocky one you want for segmentation maps or labels, where smearing colors between classes would be wrong. bilinear is the middle ground.

The input that trips everyone up

The layout. This pack's tensors are channel-first, but ComfyUI images arrive as (b, h, w, c) - height, width, then channels. Feed a raw converted image straight in and you're interpolating along the wrong axes. The pack's own docs spell out the fix: convert with Pt From Image, then transpose with Pt Permute using (0, 2, 3, 1) to get (b, c, h, w). When you're done, Pt Permute (0, 3, 1, 2) plus Pt To Image takes you back.

Also worth knowing: bilinear and bicubic expect floating-point tensors. If your data is int, convert it first - interpolate isn't shy about complaining.

Installing

This node ships in the HowToSD/ComfyUI-Pt-Wrapper pack under the "Data Analysis" menu. Install once, get ~200 nodes. ComfyUI Manager: search ComfyUI-Pt-Wrapper, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

The pack's requirements list is big (transformers, datasets, peft, accelerate…), but those serve the model-training side. Interpolation only needs PyTorch, already present, so skip the pip line if you're here for tensor math. No models to download.

And the pack's standing gotcha: its TENSOR type is separate from ComfyUI's IMAGE/LATENT. Bridge with Pt From Image / Pt To Image as described above, or the wires simply won't connect.

CategoryData Analysis

Inputs (3)

NameTypeDefaultDescription
tensTENSOR
scale_factorFLOAT2.000.01–100
modeCOMBO4 options: nearest-exact, bilinear, bicubic, nearest

Outputs (1)

NameTypeDescription
TENSORTENSOR