{"id":10304,"library":"torchsr","title":"torchsr: Super Resolution Networks for PyTorch","description":"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.","status":"active","version":"1.0.4","language":"en","source_language":"en","source_url":"https://github.com/Coloquinte/torchSR","tags":["pytorch","super-resolution","computer-vision","deep-learning","image-processing","machine-learning"],"install":[{"cmd":"pip install torchsr","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core deep learning framework dependency.","package":"torch"},{"reason":"Provides datasets, models, and image transformations, often used alongside torchsr.","package":"torchvision"},{"reason":"Used for progress bars in some utility functions, optional for core model inference.","package":"tqdm"}],"imports":[{"note":"Accesses a collection of Super Resolution models.","symbol":"models","correct":"import torchsr.models"},{"note":"Provides access to datasets relevant for Super Resolution tasks.","symbol":"datasets","correct":"import torchsr.datasets"}],"quickstart":{"code":"import torch\nimport torchsr.models\n\n# Instantiate an EDSR model with a 2x upscale factor, using pretrained weights\n# Replace 'cpu' with 'cuda' if a GPU is available\ndevice = 'cuda' if torch.cuda.is_available() else 'cpu'\nmodel = torchsr.models.edsr_r16f64(scale=2, pretrained=True).to(device)\nmodel.eval() # Set model to evaluation mode\n\n# Create a dummy low-resolution input tensor (e.g., 1 channel, 64x64)\n# Batch size is 1, so (1, C, H, W)\ninput_tensor = torch.randn(1, 3, 64, 64).to(device)\n\n# Perform super-resolution inference\nwith torch.no_grad():\n    output_tensor = model(input_tensor)\n\nprint(f\"Input shape: {input_tensor.shape}\")\nprint(f\"Output shape: {output_tensor.shape}\") # Should be 2x larger: (1, 3, 128, 128)\n","lang":"python","description":"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."},"warnings":[{"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.","message":"PyTorch 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Pretrained 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.","severity":"gotcha","affected_versions":"All versions"},{"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')`).","message":"Device 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...`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"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)`.","cause":"The input tensor you are passing to the `torchsr` model is on a different device (CPU or GPU) than the model itself.","error":"RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0!"},{"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.","cause":"You are attempting to access a model that does not exist, or you have a typo in the model name within `torchsr.models`.","error":"AttributeError: module 'torchsr.models' has no attribute 'my_non_existent_model'"},{"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.","cause":"The requested pretrained weights for the specified model and upscale factor (scale) are not available or could not be found/downloaded by the library.","error":"ValueError: Cannot find pretrained weights for model 'edsr_r16f64' at scale '4'"}]}