ComfyUI Extension: Universal NN Latent Upscaler for ComfyUI

Authored by DenRakEiw

Created

Updated

1 stars

A universal neural network latent upscaler that supports SD1.5, SDXL, Flux, and Wan2.2 models. Uses trained neural networks instead of simple interpolation for higher quality latent upscaling. Built upon the excellent foundation of a/Ttl's ComfyUi_NNLatentUpscale - this project extends the original work with universal model support and improved architectures.

Custom Nodes (0)

    README

    ๐Ÿš€ Universal NN Latent Upscaler for ComfyUI

    License: MIT Python 3.8+ ComfyUI WIP

    โš ๏ธ Work in Progress: This project is actively being developed. Current models work but we're training improved versions for better quality!

    A universal neural network latent upscaler that supports SD1.5, SDXL, Flux, and Wan2.2 models. Uses trained neural networks instead of simple interpolation for higher quality latent upscaling.

    Built upon the excellent foundation of Ttl's ComfyUi_NNLatentUpscale - this project extends the original work with universal model support and improved architectures.

    โœจ Features

    • ๐ŸŽฏ Universal Support: Works with SD1.5, SDXL, Flux, and Wan2.2 models
    • ๐Ÿง  Neural Network Upscaling: Significantly better quality than bilinear interpolation
    • โš™๏ธ Configurable Scale Factor: 1.0x to 2.0x upscaling with smooth interpolation
    • ๐Ÿ”„ Automatic Model Loading: Automatically detects and loads the correct model for each architecture
    • ๐Ÿ’พ Memory Efficient: Smart model loading/unloading to save VRAM
    • ๐ŸŽจ Custom Wan2.2 Model: Includes our own trained Wan2.2 upscaler (more models coming!)
    • ๐Ÿ”ง Easy Integration: Drop-in replacement for standard latent upscaling

    ๐Ÿ“ฆ Installation

    Method 1: Git Clone (Recommended)

    cd ComfyUI/custom_nodes
    git clone https://github.com/yourusername/wan_nn_latent.git
    

    Method 2: Manual Download

    1. Download the repository as ZIP
    2. Extract to ComfyUI/custom_nodes/wan_nn_latent/
    3. Restart ComfyUI

    Requirements

    • ComfyUI (latest version recommended)
    • PyTorch with CUDA support (for GPU acceleration)
    • Python 3.8+

    ๐ŸŽฏ Usage

    1. Add the node: Add Node -> latent -> Universal NN Latent Upscale
    2. Connect your latent: Connect any latent tensor as input
    3. Select model type: Choose SD 1.5, SDXL, Flux, or Wan2.2
    4. Set upscale factor: 1.0x to 2.0x (1.5x recommended)
    5. Connect output: Use the upscaled latent in your workflow

    Example Workflow

    [VAE Encode] -> [Universal NN Latent Upscale] -> [Your Model] -> [VAE Decode]
    

    ๐Ÿ“Š Current Model Performance

    Wan2.2 Results (v1.0 - Current):

    • MSE: 0.1038 (vs 0.1054 bilinear) - โœ… 1.5% improvement
    • PSNR: 9.84 dB (vs 9.77 dB bilinear) - โœ… 0.7 dB improvement
    • SSIM: 0.3247 (vs 0.2690 bilinear) - โœ… 20.7% improvement

    ๐Ÿ”ฌ In Development: Training new models with 2,852 real photo samples for significantly better quality!

    ๐Ÿ”ง Model Files

    The following model files are included:

    | Model | File | Size | Status | Quality | |-------|------|------|--------|---------| | SD1.5 | sd15_resizer.pt | 12.6MB | โœ… Stable | Good | | SDXL | sdxl_resizer.pt | 12.6MB | โœ… Stable | Good | | Flux | flux_resizer.pt | 25.3MB | โœ… Stable | Good | | Wan2.2 | wan2.2_resizer_best.pt | 3.9MB | โš ๏ธ WIP | Improving |

    ๐Ÿ“ Note: Models are automatically downloaded on first use if not present.

    โš™๏ธ Technical Details

    Scale Factors (Auto-detected):

    • SD1.5/SDXL: 0.13025 (4-channel latents)
    • Flux: 0.3611 (16-channel latents)
    • Wan2.2: 0.3604 (16-channel latents, empirically determined)

    Model Architectures:

    • SD1.5/SDXL: 4 channels โ†’ 128 hidden โ†’ 4 channels
    • Flux/Wan2.2: 16 channels โ†’ 256 hidden โ†’ 16 channels

    Neural Network Design:

    • ๐Ÿง  Encoder: 3-layer CNN feature extractor with ReLU activation
    • ๐Ÿ”„ Upsampler: Transpose convolution + refinement layers
    • โž• Skip Connections: Residual learning for detail preservation
    • ๐Ÿ“ Adaptive Scaling: Supports any scale factor between 1.0-2.0x

    ๐Ÿ”„ Example Workflows

    Basic Upscaling:

    [VAE Encode] -> [Universal NN Latent Upscale] -> [Model] -> [VAE Decode]
    

    Advanced Pipeline:

    [Load Image] -> [VAE Encode] -> [Universal NN Latent Upscale] ->
    [ControlNet/LoRA] -> [Model] -> [VAE Decode] -> [Save Image]
    

    ๐Ÿšง Development Status

    Current (v1.0):

    • โœ… Basic functionality working
    • โœ… All model types supported
    • โœ… Stable performance
    • โš ๏ธ Wan2.2 model needs improvement

    In Progress (v2.0):

    • ๐Ÿ”„ Training improved Wan2.2 model with 2,852 real photos
    • ๐Ÿ”„ 20,000 training steps with advanced loss functions
    • ๐Ÿ”„ Better detail preservation and artifact reduction
    • ๐Ÿ”„ Performance benchmarking against other methods

    Planned (v3.0):

    • ๐Ÿ“‹ Support for custom model training
    • ๐Ÿ“‹ Additional model architectures
    • ๐Ÿ“‹ Batch processing optimization
    • ๐Ÿ“‹ Advanced configuration options

    ๐Ÿ› ๏ธ Development & Contributing

    For Developers:

    Training Your Own Models:

    # Generate dataset
    python create_real_dataset.py
    
    # Train model (example for Wan2.2)
    python slow_long_training_20k.py
    
    # Test model
    python test_model_performance.py
    

    Adding New Model Types:

    1. Add configuration to MODEL_CONFIGS in latent_resizer.py
    2. Create specialized resizer class if needed
    3. Add model file path to weight_paths in nn_upscale.py
    4. Update the dropdown in INPUT_TYPES

    Contributing:

    • ๐Ÿ› Bug reports and feature requests welcome
    • ๐Ÿ”ง Pull requests for improvements appreciated
    • ๐Ÿ“Š Share your training results and model improvements
    • ๐Ÿ“ Documentation improvements always helpful

    ๐Ÿ› Troubleshooting

    Common Issues:

    | Issue | Solution | |-------|----------| | Model not found | Models auto-download on first use. Check internet connection. | | CUDA out of memory | Reduce batch size in workflow or use CPU mode | | Wrong model selected | Ensure latent type matches selected model (check channels) | | Slow performance | Enable GPU acceleration, check CUDA installation | | Quality issues | Try different scale factors, ensure correct model type |

    Debug Mode:

    # In nn_upscale.py, set:
    force_reload = True  # Reloads model on every execution
    

    Getting Help:

    1. ๐Ÿ“– Check this README and troubleshooting section
    2. ๐Ÿ› Open an issue on GitHub
    3. ๐Ÿ’ฌ Join the ComfyUI Discord community
    4. ๐Ÿ“ง Contact: [[email protected]]

    ๐Ÿ“Š Benchmarks & Comparisons

    | Method | SSIM โ†‘ | PSNR โ†‘ | MSE โ†“ | Speed | |--------|--------|--------|-------|-------| | Bilinear | 0.2690 | 9.77 dB | 0.1054 | โšกโšกโšก | | Our NN (v1.0) | 0.3247 | 9.84 dB | 0.1038 | โšกโšก | | Our NN (v2.0) | Training... | Training... | Training... | โšกโšก |

    ๐Ÿ“ˆ Higher SSIM and PSNR = better quality, Lower MSE = better accuracy

    ๐Ÿ“ License

    This project is licensed under the MIT License - see the LICENSE file for details.

    ๐Ÿ™ Acknowledgments

    • ๐ŸŽฏ Primary Foundation: Ttl's ComfyUi_NNLatentUpscale - This project builds directly upon Ttl's excellent work and neural network architecture. The core upscaling approach, model structure, and ComfyUI integration patterns are based on their pioneering implementation.
    • ๐Ÿค Additional Inspiration: naripok's contributions to the NN latent upscaling community
    • ๐Ÿ–ผ๏ธ ComfyUI Team: For the amazing framework that makes this possible
    • ๐Ÿค– Model Teams: Wan2.2, Flux, Stability AI for their incredible models
    • ๐ŸŒŸ Community: ComfyUI Discord community for feedback and support
    • ๐Ÿ“Š Datasets: DIV2K, COCO2017 for training data

    Special Thanks to Ttl

    This project would not exist without Ttl's groundbreaking work on neural network latent upscaling. Their original implementation provided:

    • The core neural network architecture for latent upscaling
    • ComfyUI node integration patterns
    • Training methodologies and loss functions
    • Proof of concept that NN upscaling significantly outperforms bilinear interpolation

    Our contribution extends this foundation with universal model support, improved training data, and enhanced architectures while maintaining compatibility with the original approach.

    ๐Ÿ”— Links


    <div align="center">

    ๐Ÿš€ Made with โค๏ธ for the ComfyUI community

    Star this repo Follow

    If this project helps you, please consider giving it a โญ!

    </div>