Views
No views yet






| Name | Upscale | Num Channels | Encoder Layers | Parameters | Control Modules | Library Version |
|---|---|---|---|---|---|---|
| andrewdalpino/MewZoom-V0-2X-Ctrl | 2X | 48 | 20 | 1.8M | Yes | 0.2.x |
| andrewdalpino/MewZoom-V0-3X-Ctrl | 3X | 54 | 30 | 3.5M | Yes | 0.2.x |
| andrewdalpino/MewZoom-V0-4X-Ctrl | 4X | 96 | 40 | 14M | Yes | 0.2.x |
| andrewdalpino/MewZoom-V0-2X | 2X | 48 | 20 | 1.8M | No | 0.1.x |
| andrewdalpino/MewZoom-V0-3X | 3X | 54 | 30 | 3.5M | No | 0.1.x |
| andrewdalpino/MewZoom-V0-4X | 4X | 96 | 40 | 14M | No | 0.1.x |
ultrazoom package installed into your project. For the non-control version we'll need library version 0.1.x to load the pretrained weights. We'll also need the torchvision library to do some basic image preprocessing. We recommend using a virtual environment to make package management easier.pip install ultrazoom~=0.1.0 torchvision1import torch
2
3from torchvision.io import decode_image, ImageReadMode
4from torchvision.transforms.v2 import ToDtype, ToPILImage
5
6from ultrazoom.model import MewZoom
7
8
9model_name = "andrewdalpino/MewZoom-V0-2X"
10image_path = "./dataset/bird.png"
11
12model = MewZoom.from_pretrained(model_name)
13
14image_to_tensor = ToDtype(torch.float32, scale=True)
15tensor_to_pil = ToPILImage()
16
17image = decode_image(image_path, mode=ImageReadMode.RGB)
18
19x = image_to_tensor(image).unsqueeze(0)
20
21y_pred = model.upscale(x)
22
23pil_image = tensor_to_pil(y_pred.squeeze(0))
24
25pil_image.show()0.2.x of the library is required for control functionality.pip install ultrazoom~=0.2.0 torchvisionControlVector class takes 3 arguments - gaussian_blur, gaussian_noise, and jpeg_compression corresponding to the assumed level of each type of degradation present in the input image. Their values range from 0.0 meaning no degradation is assumed present to 1.0 meaning that the maximum amount of degradation is assumed present.1import torch
2
3from torchvision.io import decode_image, ImageReadMode
4from torchvision.transforms.v2 import ToDtype, ToPILImage
5
6from ultrazoom.model import MewZoom
7from ultrazoom.control import ControlVector
8
9
10model_name = "andrewdalpino/MewZoom-V0-2X-Ctrl"
11image_path = "./dataset/bird.png"
12
13model = MewZoom.from_pretrained(model_name)
14
15image_to_tensor = ToDtype(torch.float32, scale=True)
16tensor_to_pil = ToPILImage()
17
18image = decode_image(image_path, mode=ImageReadMode.RGB)
19
20x = image_to_tensor(image).unsqueeze(0)
21
22c = ControlVector(
23 gaussian_blur=0.5, # Higher values indicate more degradation
24 gaussian_noise=0.2, # which increases the strength of the
25 jpeg_compression=0.3 # enhancement [0, 1].
26).to_tensor()
27
28y_pred = model.upscale(x, c)
29
30pil_image = tensor_to_pil(y_pred.squeeze(0))
31
32pil_image.show()pip install onnxruntime numpy pillowNote: For GPU acceleration on Windows, useonnxruntime-directmlinstead. On macOS, the standardonnxruntimepackage includes CoreML support.
1import numpy as np
2import onnxruntime as ort
3
4from PIL import Image
5
6model_path = "./model.onnx"
7image_path = "./image.png"
8
9# Load the ONNX model
10session = ort.InferenceSession(model_path, providers=["CPUExecutionProvider"])
11
12# Load and preprocess the image
13image = Image.open(image_path).convert("RGB")
14image_array = np.array(image, dtype=np.float32) / 255.0 # Normalize to [0, 1]
15
16# Convert from (H, W, C) to (1, C, H, W)
17input_tensor = np.transpose(image_array, (2, 0, 1))
18input_tensor = np.expand_dims(input_tensor, axis=0)
19
20# Run inference
21outputs = session.run(None, {"x": input_tensor})
22
23# Postprocess the output
24output_tensor = outputs[0][0] # Remove batch dimension
25output_array = np.transpose(output_tensor, (1, 2, 0)) # (C, H, W) -> (H, W, C)
26output_array = np.clip(output_array, 0.0, 1.0)
27output_image = (output_array * 255).astype(np.uint8)
28
29# Display the result
30result = Image.fromarray(output_image, "RGB")
31result.show()c - a control vector with 3 values corresponding to the assumed level of degradation in the input image. Each value ranges from 0.0 (no degradation) to 1.0 (maximum degradation).| Index | Parameter | Description |
|---|---|---|
| 0 | gaussian_blur | Deblurring strength |
| 1 | gaussian_noise | Denoising strength |
| 2 | jpeg_compression | JPEG artifact removal strength |
1import numpy as np
2import onnxruntime as ort
3
4from PIL import Image
5
6model_path = "./model.onnx"
7image_path = "./image.png"
8
9# Load the ONNX model
10session = ort.InferenceSession(model_path, providers=["CPUExecutionProvider"])
11
12# Load and preprocess the image
13image = Image.open(image_path).convert("RGB")
14image_array = np.array(image, dtype=np.float32) / 255.0
15
16# Convert from (H, W, C) to (1, C, H, W)
17input_tensor = np.transpose(image_array, (2, 0, 1))
18input_tensor = np.expand_dims(input_tensor, axis=0)
19
20# Define the control vector: [gaussian_blur, gaussian_noise, jpeg_compression]
21control_vector = np.array([[0.5, 0.2, 0.3]], dtype=np.float32)
22
23# Run inference with control vector
24outputs = session.run(None, {"x": input_tensor, "c": control_vector})
25
26# Postprocess the output
27output_tensor = outputs[0][0]
28output_array = np.transpose(output_tensor, (1, 2, 0))
29output_array = np.clip(output_array, 0.0, 1.0)
30output_image = (output_array * 255).astype(np.uint8)
31
32# Display the result
33result = Image.fromarray(output_image, "RGB")
34result.show()
- J. Song, et al. Gram-GAN: Image Super-Resolution Based on Gram Matrix and Discriminator Perceptual Loss, Sensors, 2023.
- Z. Liu, et al. A ConvNet for the 2020s, 2022.
- A. Jolicoeur-Martineau. The Relativistic Discriminator: A Key Element Missing From Standard GAN, 2018.
- J. Yu, et al. Wide Activation for Efficient and Accurate Image Super-Resolution, 2018.
- J. Johnson, et al. Perceptual Losses for Real-time Style Transfer and Super-Resolution, 2016.
- W. Shi, et al. Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network, 2016.
- T. Salimans, et al. Weight Normalization: A Simple Reparameterization to Accelerate Training of Deep Neural Networks, OpenAI, 2016.
- T. Miyato, et al. Spectral Normalization for Generative Adversarial Networks, ICLR, 2018.
- E. Perez, et. al. FiLM: Visual Reasoning with a General Conditioning Layer, Association for the Advancement of Artificial Intelligence, 2018.
- A. Kendall, et. al. Multi-task Learning Using Uncertainty to Weigh Losses for Scene Geomtery and Semantics, 2018.