torchsr: Super Resolution Networks for PyTorch

1.0.4 · active · verified Fri Apr 17

torchsr is a Python library providing a collection of Super Resolution (SR) network architectures implemented in PyTorch. It includes popular models like EDSR, RCAN, and NinaSR variants, often with pretrained weights, to easily integrate SR capabilities into deep learning projects. The current version is 1.0.4, with releases focusing on model improvements, new architectures, and compatibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load a pretrained Super Resolution model (EDSR in this case) from `torchsr.models`, move it to the appropriate device, and perform inference on a dummy input tensor. The output shape confirms the upscale factor applied by the model.

import torch
import torchsr.models

# Instantiate an EDSR model with a 2x upscale factor, using pretrained weights
# Replace 'cpu' with 'cuda' if a GPU is available
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = torchsr.models.edsr_r16f64(scale=2, pretrained=True).to(device)
model.eval() # Set model to evaluation mode

# Create a dummy low-resolution input tensor (e.g., 1 channel, 64x64)
# Batch size is 1, so (1, C, H, W)
input_tensor = torch.randn(1, 3, 64, 64).to(device)

# Perform super-resolution inference
with torch.no_grad():
    output_tensor = model(input_tensor)

print(f"Input shape: {input_tensor.shape}")
print(f"Output shape: {output_tensor.shape}") # Should be 2x larger: (1, 3, 128, 128)

view raw JSON →