shammisw commited on
Commit
d0c4233
Β·
1 Parent(s): adecea0

Update README file

Browse files
Files changed (1) hide show
  1. README.md +102 -1
README.md CHANGED
@@ -1,3 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
- license: apache-2.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Real-CUGAN Models for TensorFlow.js
2
+
3
+ [![Hugging Face Repo](https://img.shields.io/badge/πŸ€—%20Hugging%20Face-Repo-yellow)](https://huggingface.co/shammisw/real-cugan-tensorflowjs)
4
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
+
6
+ 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.
7
+
8
+ These models are optimized for upscaling anime-style images and illustrations with high fidelity, speed, and reduced noise.
9
+
10
+ ## ✨ Features
11
+
12
+ * **High-Quality Anime Upscaling:** Specifically trained for cartoons and anime, preserving sharp lines and details.
13
+ * **Web Ready:** Run directly in the browser with TensorFlow.js for client-side image processing.
14
+ * **Multiple Scales & Models:** Includes various models for different upscaling factors and noise reduction levels.
15
+ * **Lightweight & Fast:** CUGAN is designed to be more efficient than many larger GAN-based upscalers.
16
+
17
  ---
18
+
19
+ ## πŸš€ Usage Example
20
+
21
+ To use these models, you will need to have TensorFlow.js set up in your project.
22
+
23
+ ```bash
24
+ # Using npm
25
+ npm install @tensorflow/tfjs
26
+
27
+ # Using yarn
28
+ yarn add @tensorflow/tfjs
29
+ ```
30
+
31
+ Here is a basic example of how to load and run a model in JavaScript:
32
+
33
+ ```javascript
34
+ import * as tf from '@tensorflow/tfjs';
35
+
36
+ // The URL to the model.json file in this repository
37
+ 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)';
38
+
39
+ async function upscaleImage(imageElement) {
40
+ try {
41
+ // 1. Load the model
42
+ console.log('Loading model...');
43
+ const model = await tf.loadGraphModel(MODEL_URL);
44
+ console.log('Model loaded.');
45
+
46
+ // 2. Prepare the input tensor from an HTMLImageElement
47
+ // Models are trained on float32 tensors, normalized to the [0, 1] range.
48
+ const inputTensor = tf.browser.fromPixels(imageElement)
49
+ .toFloat()
50
+ .div(255.0)
51
+ .expandDims(0); // Add batch dimension: [h, w, c] -> [1, h, w, c]
52
+
53
+ // 3. Run inference
54
+ console.log('Running inference...');
55
+ const outputTensor = model.execute(inputTensor);
56
+
57
+ // 4. Process the output and display it on a canvas
58
+ const outputCanvas = document.getElementById('output-canvas');
59
+ await tf.browser.toPixels(outputTensor.squeeze(), outputCanvas);
60
+ console.log('Upscaling complete!');
61
+
62
+ // 5. Clean up tensors
63
+ tf.dispose([inputTensor, outputTensor]);
64
+
65
+ } catch (error) {
66
+ console.error('Failed to upscale image:', error);
67
+ }
68
+ }
69
+
70
+ // Find your input image element and pass it to the function
71
+ const myImage = document.getElementById('my-input-image');
72
+ upscaleImage(myImage);
73
+ ```
74
+
75
  ---
76
+
77
+ ## πŸ“‚ Available Models
78
+
79
+ 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.
80
+
81
+ | Model Type | Scale | Denoise Level | Path |
82
+ | :--------------- | :---: | :-----------: | :------------------------------------------------- |
83
+ | **Conservative** | 2x | - | `real-cugan-models/realcugan/2x-conservative-64/` |
84
+ | **Conservative** | 4x | - | `real-cugan-models/realcugan/4x-conservative-64/` |
85
+ | *More models can be added here as they are converted.* | | | |
86
+
87
+ ---
88
+
89
+ ## πŸ™ Acknowledgements & Credits
90
+
91
+ This repository only contains the converted models. All credit for the research and training of the original models goes to their respective creators.
92
+
93
+ * **Original Real-CUGAN Models:** The foundational research and PyTorch models were developed by **Bilibili AI Lab**. Their incredible work made this possible.
94
+ * **GitHub Repository:** [bilibili/ailab/Real-CUGAN](https://github.com/bilibili/ailab/tree/main/Real-CUGAN)
95
+
96
+ * **TensorFlow.js Conversion:** The methodology for converting these models to TensorFlow.js format was adapted from the excellent **[web-realesrgan](https://github.com/ts-ai/web-realesrgan)** project, which provided a clear path for on-device super-resolution in the browser.
97
+
98
+ ---
99
+
100
+ ## πŸ“œ License
101
+
102
+ The code and configuration in this repository are released under the **MIT License**.
103
+
104
+ The original Real-CUGAN models are subject to their own license terms as specified in the [official Real-CUGAN repository](https://github.com/bilibili/ailab/tree/main/Real-CUGAN). Please ensure compliance with their license if you use these models.