Home

Awesome

ComfyUI Neural network latent upscale custom node

Example 1

This repository includes a custom node for ComfyUI for upscaling the latents quickly using a small neural network without needing to decode and encode with VAE. The node can be found in "Add Node -> latent -> NNLatentUpscale".

This node is meant to be used in a workflow where the initial image is generated in lower resolution, the latent is upscaled and the upscaled latent is fed back into the stable diffusion u-net for low noise diffusion pass (high-res fix).

Compared to VAE decode -> upscale -> encode, the neural net latent upscale is about 20 - 50 times faster depending on the image resolution with minimal quality loss. Compared to direct linear interpolation of the latent the neural net upscale is slower but has much better quality. Direct latent interpolation usually has very large artifacts.

Installation

Clone this repository in ComfyUI custom_nodes directory with: git clone https://github.com/Ttl/ComfyUi_NNLatentUpscale.git.

Evaluation

Example 2

Dataset: COCO 2017 validation images center cropped to 256x256 resolution. The comparison image is linear upscale of the input image. All tests are done with fp32 precision and batch size 4.

VAE Upscale: VAE decode -> Linear interpolation -> Encode.

NN Upscale: Neural network upscale (This repository).

Latent Upscale: Linear interpolation of latent.

SDXL, 2x upscale:

MSE ↓LPIPS ↓PSNR ↑Time (ms) ↓
VAE Upscale0.0090.2226.9832
NN Upscale0.0100.2826.336
Latent Upscale0.0470.6519.50.1

SDXL, 1.5x upscale:

MSE ↓LPIPS ↓PSNR ↑Time (ms) ↓
VAE Upscale0.0090.2026.9583
NN Upscale0.0100.2626.319
Latent Upscale0.0380.5820.40.1

SD 1.5, 2x upscale:

MSE ↓LPIPS ↓PSNR ↑Time (ms) ↓
VAE Upscale0.0090.2126.7822
NN Upscale0.0080.2427.036
Latent Upscale0.0330.6120.90.1

SD 1.5, 1.5x upscale:

MSE ↓LPIPS ↓PSNR ↑Time (ms) ↓
VAE Upscale0.0100.1826.5594
NN Upscale0.0090.2126.920
Latent Upscale0.0310.5221.30.1