Real-CUGAN Models for TensorFlow.js

Hugging Face Repo License

This repository provides pre-converted models of Real-CUGAN (Real-World-Oriented Cascaded U-Net for Anime Image Super-Resolution) in the TensorFlow.js GraphModel format, ready for use in web browsers and Node.js environments.

These models are optimized for upscaling anime-style images and illustrations with high fidelity, speed, and reduced noise.

✨ Features

  • High-Quality Anime Upscaling: Specifically trained for cartoons and anime, preserving sharp lines and details.
  • Web Ready: Run directly in the browser with TensorFlow.js for client-side image processing.
  • Multiple Scales & Models: Includes various models for different upscaling factors and noise reduction levels.
  • Lightweight & Fast: CUGAN is designed to be more efficient than many larger GAN-based upscalers.

πŸš€ Usage Example

To use these models, you will need to have TensorFlow.js set up in your project.

# Using npm
npm install @tensorflow/tfjs

# Using yarn
yarn add @tensorflow/tfjs

Here is a basic example of how to load and run a model in JavaScript:

import * as tf from '@tensorflow/tfjs';

// The URL to the model.json file in this repository
const MODEL_URL = '[https://huggingface.co/shammisw/real-cugan-tensorflowjs/resolve/main/real-cugan-models/realcugan/4x-conservative-64/model.json](https://huggingface.co/shammisw/real-cugan-tensorflowjs/resolve/main/real-cugan-models/realcugan/4x-conservative-64/model.json)';

async function upscaleImage(imageElement) {
  try {
    // 1. Load the model
    console.log('Loading model...');
    const model = await tf.loadGraphModel(MODEL_URL);
    console.log('Model loaded.');

    // 2. Prepare the input tensor from an HTMLImageElement
    // Models are trained on float32 tensors, normalized to the [0, 1] range.
    const inputTensor = tf.browser.fromPixels(imageElement)
      .toFloat()
      .div(255.0)
      .expandDims(0); // Add batch dimension: [h, w, c] -> [1, h, w, c]

    // 3. Run inference
    console.log('Running inference...');
    const outputTensor = model.execute(inputTensor);

    // 4. Process the output and display it on a canvas
    const outputCanvas = document.getElementById('output-canvas');
    await tf.browser.toPixels(outputTensor.squeeze(), outputCanvas);
    console.log('Upscaling complete!');

    // 5. Clean up tensors
    tf.dispose([inputTensor, outputTensor]);

  } catch (error) {
    console.error('Failed to upscale image:', error);
  }
}

// Find your input image element and pass it to the function
const myImage = document.getElementById('my-input-image');
upscaleImage(myImage);

πŸ“‚ Available Models

This repository contains the following converted models. The number in the model name (e.g., -64) refers to the tile size used during conversion, which can affect performance and memory usage.

Model Type Scale Denoise Level Path
Conservative 2x - real-cugan-models/realcugan/2x-conservative-64/
Conservative 4x - real-cugan-models/realcugan/4x-conservative-64/
More models can be added here as they are converted.

πŸ™ Acknowledgements & Credits

This repository only contains the converted models. All credit for the research and training of the original models goes to their respective creators.

  • Original Real-CUGAN Models: The foundational research and PyTorch models were developed by Bilibili AI Lab. Their incredible work made this possible.

  • TensorFlow.js Conversion: The methodology for converting these models to TensorFlow.js format was adapted from the excellent web-realesrgan project, which provided a clear path for on-device super-resolution in the browser.


πŸ“œ License

The code and configuration in this repository are released under the Apache-2.0.

The original Real-CUGAN models are subject to their own license terms as specified in the official Real-CUGAN repository. Please ensure compliance with their license if you use these models.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support