Registry / ai-ml / torchsr

torchsr

JSON →
library1.0.4pypypi✓ verified 86d ago

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.

pip install torchsr
INSTALL
IMPORT
SIG · TORCHSR
T
torchsr
ai-mlpythonv1.0.4
Install
66.6s avg
Import
12720ms
Disk
4890MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 80.5s
py 3.11
✕ build_error
✓ 69.25s
py 3.12
✕ build_error
✓ 59.6s
py 3.13
✕ build_error
✓ 57.15s
py 3.9
✕ build_error
✕ timeout
4890MB installed
● package 4890MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

models
import torchsr.models
Accesses a collection of Super Resolution models.
datasets
import torchsr.datasets
Provides access to datasets relevant for Super Resolution tasks.

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)
Debug
Known issues
gotchaPyTorch Version Compatibility: Pretrained models in `torchsr` were often trained with specific PyTorch versions. While the library generally aims for broad compatibility, significantly older or newer PyTorch versions might lead to issues when loading pretrained weights due to serialization changes. It's recommended to use a PyTorch version reasonably close to the latest stable release.
fix
If encountering errors with pretrained weights, try updating your PyTorch version or explicitly instantiating the model without `pretrained=True` to rule out compatibility issues with weights.
affects: All versions
gotchaPretrained Model Availability: Not all models or all upscale factors (scales) within `torchsr` have pretrained weights available. Attempting to load a non-existent combination (e.g., `model(scale=5, pretrained=True)` where only `scale=2` is available) will raise a `ValueError`. Always verify the existence of pretrained weights for your desired configuration.
fix
Consult the `torchsr` documentation or repository for available models and their supported scales/pretrained weights. Alternatively, set `pretrained=False` to use an untrained model.
affects: All versions
gotchaDevice Placement Mismatch: A common PyTorch issue where the input tensor and the model are on different devices (e.g., one on CPU, the other on GPU). This leads to `RuntimeError: Expected all tensors to be on the same device...`.
fix
Ensure both your model and your input tensors are explicitly moved to the same device using `.to(device)` (e.g., `model.to('cuda')`, `input_tensor.to('cuda')`).
affects: All versions
Errors
Common errors & fixes
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0!
The input tensor you are passing to the `torchsr` model is on a different device (CPU or GPU) than the model itself.
fix
Move both the model and your input tensor to the same device using `.to(device)`. For example: `device = 'cuda' if torch.cuda.is_available() else 'cpu'; model = model.to(device); input_tensor = input_tensor.to(device)`.
AttributeError: module 'torchsr.models' has no attribute 'my_non_existent_model'
You are attempting to access a model that does not exist, or you have a typo in the model name within `torchsr.models`.
fix
Double-check the exact model name from the `torchsr` documentation or by inspecting the available models (e.g., `print(dir(torchsr.models))`). Ensure the name matches precisely.
ValueError: Cannot find pretrained weights for model 'edsr_r16f64' at scale '4'
The requested pretrained weights for the specified model and upscale factor (scale) are not available or could not be found/downloaded by the library.
fix
Verify that pretrained weights exist for your chosen model and scale combination by checking the `torchsr` documentation. If not available, you can instantiate the model without pretrained weights by setting `pretrained=False`, or choose a different model/scale combination.
Upgrade
Version history
1.0.4latest on PyPI · released Aug 21, 2022
Audit
Dependencies
torchrequiredCore deep learning framework dependency.
torchvisionrequiredProvides datasets, models, and image transformations, often used alongside torchsr.
tqdmrequiredUsed for progress bars in some utility functions, optional for core model inference.
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
torchsr — pip install torchsr · libregistry