ComfyUI Node

Randomize 2d KPS

Breaking out of identical face placement across a batch

By nosiu·Created 3 years ago·Updated about a year ago· 264
Randomize 2d KPS
  • kps_data
  • kps_data
seed0
angle_min0
angle_max0
scale_min1.00
scale_max1.00
translate_x0
translate_y0
border0

Run the same fixed KPS through a batch and every image puts the face in exactly the same spot, at exactly the same scale, at exactly the same angle - which gets monotonous fast, especially if you're generating a batch to pick the best result from rather than one careful shot. This node randomizes position, rotation, and scale of your keypoint set within ranges you control, so a batch actually looks like a batch instead of the same composition with a different seed on the diffusion side.

How it works

Everything rotates and scales around the KPS set's own center point, not the image corner - so a rotation doesn't fling the face off to one side, it turns in place. You get independent control over three kinds of randomization: rotation angle, scale, and translation (position shift), plus a border safety margin so an aggressive translate/scale combo doesn't push keypoints off the edge of the canvas entirely.

The inputs and outputs that matter

  • kps_data - required, from KpsDraw, Kps3dFromImage, or any upstream KPS node.
  • seed - tooltip: "The random seed used for randomizing KPS." Change it to get a different random draw within your ranges; keep it fixed to reproduce the exact same randomization later.
  • angle_min / angle_max (both default 0, range −180 to 180) - random rotation range around the KPS center.
  • scale_min / scale_max (both default 1, range 0.1–5) - random scale range; 1 means no scaling, so leaving both at 1 disables this axis entirely.
  • translate_x / translate_y (both default 0, range 0–16384) - this one reads a little counterintuitively: it's not an absolute shift, it's a range. Set translate_x to 200 and the node randomly picks a shift somewhere between −200 and +200, per the README's own example.
  • border (default 0) - edge threshold; if a randomized position, rotation, or scale would push the KPS too close to the image border, it gets pulled back to sit at this margin instead of clipping off-canvas.

Output: kps_data, randomized and ready for KpsMaker (or further transforms) same as any other KPS node's output.

Install

ComfyUI Manager: search comfyui-instantId-faceswap. Manual: git clone https://github.com/nosiu/comfyui-instantId-faceswap into custom_nodes/, pip install -r requirements.txt. No model dependency - pure randomization math on kps_data, nothing to download for this node specifically.

Common issues & troubleshooting

Every generation still looks identical. Check that at least one of angle_min/angle_max, scale_min/scale_max, or translate_x/translate_y is actually set away from its no-op default (0 for angle/translate, 1 for scale) - leaving everything at default makes this node a pass-through in practice. Also make sure seed is actually changing between runs if you're using a fixed value elsewhere in your workflow that might be locking it.

Face keeps ending up at the same edge or corner. That's likely border doing its job aggressively - a small border value combined with a wide translate range means a lot of your randomized draws are getting clamped to roughly the same safe position near the edge. Widen your canvas or narrow the translate range instead of raising border further.

Results look distorted rather than just repositioned. Extreme scale ranges (pushing toward the 0.1 or 5.0 limits) combined with a real face's proportions can look unnatural fast - this node doesn't know or care about facial proportions, it's just scaling points. Keep scale_min/scale_max reasonably close to 1 unless you're deliberately going for something exaggerated.

CategoryInstantId Faceswap

Inputs (9)

NameTypeDefaultDescription
kps_dataKPS_DATA
seedINT00–18446744073709550000The random seed used for randomizing KPS
angle_minINT0-180–180
angle_maxINT0-180–180
scale_minFLOAT1.000.1–5
scale_maxFLOAT1.000.1–5
translate_xINT00–16384
translate_yINT00–16384
borderINT00–16384

Outputs (1)

NameTypeDescription
kps_dataKPS_DATA