ComfyUI Node

P2LDGAN

Clean lineart from any photo, without the preprocessor roulette

By jamesWalker55·Created 3 years ago·Updated 2 years ago· 17
P2LDGAN
  • images
  • IMAGE
resolution1024
deep_samplingyes
invert_outputyes

The P2LDGAN node is a one-trick pony, and the trick is a good one: feed it a photo and it hands back a clean line drawing - black lines on white, ready to drive a ControlNet lineart model or a coloring workflow. Most people first meet lineart in ComfyUI via the ControlNet Auxiliary Preprocessors' lineart_realistic or lineart_anime nodes, which are fast heuristic edge detectors. P2LDGAN is a different animal: it's an actual GAN, trained for 200 epochs on photo-to-line-drawing pairs, and it tends to produce straighter, cleaner, more deliberately "drawn" lines than the heuristic preprocessors - especially on faces and organic subjects, where Canny goes haywire.

P2LDGAN is a research model from cnyvfang's repo, and jamesWalker55 - the same author behind comfyui-various and a pile of other JWW nodes - wrapped it into this single node. The name is accurate and the node is boring in the best way: no API, no key, no extra dependencies. One output, four inputs, that's it.

How it works

The node loads p2ldgan_generator_200.pth (the 200-epoch checkpoint), normalizes your image to the [-1, 1] range, and pushes it through the generator once to get the initial line drawing. Then, if deep_sampling is on (it is by default), it feeds the output back through the model twice more, mixing in the original image each pass, which refines and stabilizes the lines. That's three forward passes total - the model is small, so even the full run is quick, but set deep_sampling to "no" if you want it snappier and don't care about the polish.

The inputs that matter

  • images - any IMAGE tensor. It handles batches, so wiring in a folder-load of reference photos works fine.
  • resolution - default 1024. The longest side of each image is resized (LANCZOS) to this before the model runs. Set it to 0 to skip resizing entirely and use your source at native size.
  • deep_sampling - yes/no; the two refinement passes above.
  • invert_output - yes/no, default yes. "yes" flips the output to black-lines-on-white, which is what ControlNet lineart models expect. If your lines come out ghosted or the conditioned generation looks washed out, this toggle is usually the culprit.

The single output is an IMAGE, and it plugs straight into a ControlNet lineart conditioner - pair it with a lineart ControlNet model and you get structure-faithful generations from a photo reference. It's also the right tool for anime cel/coloring pipelines where you want a stable sketch to fill. Nothing downstream-specific about it: it's a preprocessing node, so it can feed anything that wants an image.

Installing it

Easiest path is ComfyUI Manager - search for "P2LDGAN" (or the pack title). Or clone it manually:

cd ComfyUI/custom_nodes
git clone https://github.com/jamesWalker55/comfyui-p2ldgan

Then restart ComfyUI. Here's the one gotcha: the pack ships no checkpoint, and there are no pip packages to install - it rides on torch/torchvision/PIL that ComfyUI already bundles. You have to grab p2ldgan_generator_200.pth yourself from the original P2LDGAN repository and drop it in:

ComfyUI/custom_nodes/comfyui-p2ldgan/checkpoints/p2ldgan_generator_200.pth

Troubleshooting

  • "Failed to find 'p2ldgan_generator_200.pth'" - the checkpoint isn't where the node looks. The filename must be exact and it must live in checkpoints/.
  • "Input image dimensions must be divisible by 16!" - the generator's convolutions demand dimensions divisible by 16. Set resolution to something like 1024, 896, or 768 (or 0 and make sure your source images are clean), and this error stops biting.

That's the whole thing. If your current lineart preprocessors already serve you, you probably don't need this node. But if you're chasing that hand-drawn line quality on portraits or organic subjects, P2LDGAN is worth the ten minutes of setup.

CategoryjamesWalker55

Inputs (4)

NameTypeDefaultDescription
imagesIMAGE
resolutionINT1024
deep_samplingCOMBOyes2 options: yes, no
invert_outputCOMBOyes2 options: yes, no

Outputs (1)

NameTypeDescription
IMAGEIMAGE