{"id":23451423,"url":"https://github.com/coloquinte/torchsr","last_synced_at":"2025-04-05T02:09:01.893Z","repository":{"id":42453957,"uuid":"344561101","full_name":"Coloquinte/torchSR","owner":"Coloquinte","description":"Super Resolution datasets and models in Pytorch","archived":false,"fork":false,"pushed_at":"2023-12-23T13:08:59.000Z","size":456,"stargazers_count":199,"open_issues_count":1,"forks_count":19,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-29T01:14:04.208Z","etag":null,"topics":["datasets","edsr","pytorch","rcan","rdn","superresolution","torchvision","vdsr"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Coloquinte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-04T17:49:52.000Z","updated_at":"2025-03-13T09:14:54.000Z","dependencies_parsed_at":"2023-12-15T15:53:51.347Z","dependency_job_id":"aed05731-0e15-4bb1-9207-425acc11de06","html_url":"https://github.com/Coloquinte/torchSR","commit_stats":{"total_commits":186,"total_committers":4,"mean_commits":46.5,"dds":"0.043010752688172005","last_synced_commit":"44ddac16dfbb291c6725f80723fcf46d8f36c426"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coloquinte%2FtorchSR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coloquinte%2FtorchSR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coloquinte%2FtorchSR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coloquinte%2FtorchSR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Coloquinte","download_url":"https://codeload.github.com/Coloquinte/torchSR/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247276164,"owners_count":20912288,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datasets","edsr","pytorch","rcan","rdn","superresolution","torchvision","vdsr"],"created_at":"2024-12-24T00:25:58.978Z","updated_at":"2025-04-05T02:09:01.878Z","avatar_url":"https://github.com/Coloquinte.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4868308.svg)](https://doi.org/10.5281/zenodo.4868308)\n[![PyPI](https://img.shields.io/pypi/v/torchsr?color=orange)](https://pypi.org/project/torchsr/)\n[![GitHub](https://img.shields.io/github/license/coloquinte/torchsr?color=lightgrey)](https://opensource.org/licenses/MIT)\n\n\n# Super-Resolution Networks for Pytorch\n\n[Super-resolution](https://en.wikipedia.org/wiki/Super-resolution_imaging) is a process that increases the resolution of an image, adding additional details.\nMethods using neural networks give the most accurate results, much better than other interpolation methods.\nWith the right training, it is even possible to make photo-realistic images.\n\nFor example, here is a low-resolution image, magnified x4 by a neural network, and a high resolution image of the same object:\n\n![Pixelated image of a butterfly](https://raw.githubusercontent.com/Coloquinte/torchSR/v1.0.2/doc/example_small.png \"Low resolution image\")\n![Smooth magnified image](https://raw.githubusercontent.com/Coloquinte/torchSR/v1.0.2/doc/example_x4.png \"Magnified x4\")\n![High resolution image](https://raw.githubusercontent.com/Coloquinte/torchSR/v1.0.2/doc/example_hr.png \"High resolution image\")\n\n\nIn this repository, you will find:\n*   the popular super-resolution networks, pretrained\n*   common super-resolution datasets\n*   Pytorch datasets and transforms adapted to super-resolution\n*   a unified training script for all models\n\n\n\n## Models\n\nThe following pretrained models are available. Click on the links for the paper:\n*   [EDSR](https://arxiv.org/abs/1707.02921)\n*   [CARN](https://arxiv.org/abs/1803.08664)\n*   [RDN](https://arxiv.org/abs/1802.08797)\n*   [RCAN](https://arxiv.org/abs/1807.02758)\n*   [NinaSR](doc/NinaSR.md)\n\nNewer and larger models perform better: the most accurate models are EDSR (huge), RCAN and NinaSR-B2.\nFor practical applications, I recommend a smaller model, such as NinaSR-B1.\n\n\n\u003cdetails\u003e\n\u003csummary\u003eExpand benchmark results\u003c/summary\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eSet5 results\u003c/summary\u003e\n\n|  Network            | Parameters (M) | 2x (PSNR/SSIM) | 3x (PSNR/SSIM) | 4x (PSNR/SSIM) |\n| ------------------- | -------------- | -------------- | -------------- | -------------- |\n| carn                | 1.59           | 37.88 / 0.9600 | 34.32 / 0.9265 | 32.14 / 0.8942 |\n| carn\\_m             | 0.41           | 37.68 / 0.9594 | 34.06 / 0.9247 | 31.88 / 0.8907 |\n| edsr\\_baseline      | 1.37           | 37.98 / 0.9604 | 34.37 / 0.9270 | 32.09 / 0.8936 |\n| edsr                | 40.7           | 38.19 / 0.9609 | 34.68 / 0.9293 | 32.48 / 0.8985 |\n| ninasr\\_b0          | 0.10           | 37.72 / 0.9594 | 33.96 / 0.9234 | 31.77 / 0.8877 |\n| ninasr\\_b1          | 1.02           | 38.14 / 0.9609 | 34.48 / 0.9277 | 32.28 / 0.8955 |\n| ninasr\\_b2          | 10.0           | 38.21 / 0.9612 | 34.61 / 0.9288 | 32.45 / 0.8973 |\n| rcan                | 15.4           | 38.27 / 0.9614 | 34.76 / 0.9299 | 32.64 / 0.9000 |\n| rdn                 | 22.1           | 38.12 / 0.9609 | 33.98 / 0.9234 | 32.35 / 0.8968 |\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eSet14 results\u003c/summary\u003e\n\n|  Network            | Parameters (M) | 2x (PSNR/SSIM) | 3x (PSNR/SSIM) | 4x (PSNR/SSIM) |\n| ------------------- | -------------- | -------------- | -------------- | -------------- |\n| carn                | 1.59           | 33.57 / 0.9173 | 30.30 / 0.8412 | 28.61 / 0.7806 |\n| carn\\_m             | 0.41           | 33.30 / 0.9151 | 30.10 / 0.8374 | 28.42 / 0.7764 |\n| edsr\\_baseline      | 1.37           | 33.57 / 0.9174 | 30.28 / 0.8414 | 28.58 / 0.7804 |\n| edsr                | 40.7           | 33.95 / 0.9201 | 30.53 / 0.8464 | 28.81 / 0.7872 |\n| ninasr\\_b0          | 0.10           | 33.24 / 0.9144 | 30.02 / 0.8355 | 28.28 / 0.7727 |\n| ninasr\\_b1          | 1.02           | 33.71 / 0.9189 | 30.41 / 0.8437 | 28.71 / 0.7840 |\n| ninasr\\_b2          | 10.0           | 34.00 / 0.9206 | 30.53 / 0.8461 | 28.80 / 0.7863 |\n| rcan                | 15.4           | 34.13 / 0.9216 | 30.63 / 0.8475 | 28.85 / 0.7878 |\n| rdn                 | 22.1           | 33.71 / 0.9182 | 30.07 / 0.8373 | 28.72 / 0.7846 |\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eDIV2K results (validation set)\u003c/summary\u003e\n\n|  Network            | Parameters (M) | 2x (PSNR/SSIM) | 3x (PSNR/SSIM) | 4x (PSNR/SSIM) | 8x (PSNR/SSIM) |\n| ------------------- | -------------- | -------------- | -------------- | -------------- | -------------- |\n| carn                | 1.59           | 36.08 / 0.9451 | 32.37 / 0.8871 | 30.43 / 0.8366 | N/A            |\n| carn\\_m             | 0.41           | 35.76 / 0.9429 | 32.09 / 0.8827 | 30.18 / 0.8313 | N/A            |\n| edsr\\_baseline      | 1.37           | 36.13 / 0.9455 | 32.41 / 0.8878 | 30.43 / 0.8370 | N/A            |\n| edsr                | 40.7           | 36.56 / 0.9485 | 32.75 / 0.8933 | 30.73 / 0.8445 | N/A            |\n| ninasr\\_b0          | 0.10           | 35.77 / 0.9428 | 32.06 / 0.8818 | 30.09 / 0.8293 | 26.60 / 0.7084 |\n| ninasr\\_b1          | 1.02           | 36.35 / 0.9471 | 32.51 / 0.8892 | 30.56 / 0.8405 | 26.96 / 0.7207 |\n| ninasr\\_b2          | 10.0           | 36.52 / 0.9482 | 32.73 / 0.8926 | 30.73 / 0.8437 | 27.07 / 0.7246 |\n| rcan                | 15.4           | 36.61 / 0.9489 | 32.78 / 0.8935 | 30.73 / 0.8447 | 27.17 / 0.7292 |\n| rdn                 | 22.1           | 36.32 / 0.9468 | 32.04 / 0.8822 | 30.61 / 0.8414 | N/A            |\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eB100 results\u003c/summary\u003e\n\n|  Network            | Parameters (M) | 2x (PSNR/SSIM) | 3x (PSNR/SSIM) | 4x (PSNR/SSIM) |\n| ------------------- | -------------- | -------------- | -------------- | -------------- |\n| carn                | 1.59           | 32.12 / 0.8986 | 29.07 / 0.8042 | 27.58 / 0.7355 |\n| carn\\_m             | 0.41           | 31.97 / 0.8971 | 28.94 / 0.8010 | 27.45 / 0.7312 |\n| edsr\\_baseline      | 1.37           | 32.15 / 0.8993 | 29.08 / 0.8051 | 27.56 / 0.7354 |\n| edsr                | 40.7           | 32.35 / 0.9019 | 29.26 / 0.8096 | 27.72 / 0.7419 |\n| ninasr\\_b0          | 0.10           | 31.97 / 0.8974 | 28.90 / 0.8000 | 27.36 / 0.7290 |\n| ninasr\\_b1          | 1.02           | 32.24 / 0.9004 | 29.13 / 0.8061 | 27.62 / 0.7377 |\n| ninasr\\_b2          | 10.0           | 32.32 / 0.9014 | 29.23 / 0.8087 | 27.71 / 0.7407 |\n| rcan                | 15.4           | 32.39 / 0.9024 | 29.30 / 0.8106 | 27.74 / 0.7429 |\n| rdn                 | 22.1           | 32.25 / 0.9006 | 28.90 / 0.8004 | 27.66 / 0.7388 |\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eUrban100 results\u003c/summary\u003e\n\n|  Network            | Parameters (M) | 2x (PSNR/SSIM) | 3x (PSNR/SSIM) | 4x (PSNR/SSIM) |\n| ------------------- | -------------- | -------------- | -------------- | -------------- |\n| carn                | 1.59           | 31.95 / 0.9263 | 28.07 / 0.849 | 26.07 / 0.78349 |\n| carn\\_m             | 0.41           | 31.30 / 0.9200 | 27.57 / 0.839 | 25.64 / 0.76961 |\n| edsr\\_baseline      | 1.37           | 31.98 / 0.9271 | 28.15 / 0.852 | 26.03 / 0.78424 |\n| edsr                | 40.7           | 32.97 / 0.9358 | 28.81 / 0.865 | 26.65 / 0.80328 |\n| ninasr\\_b0          | 0.10           | 31.33 / 0.9204 | 27.48 / 0.8374 | 25.45 / 0.7645 |\n| ninasr\\_b1          | 1.02           | 32.48 / 0.9319 | 28.29 / 0.8555 | 26.25 / 0.7914 |\n| ninasr\\_b2          | 10.0           | 32.91 / 0.9354 | 28.70 / 0.8640 | 26.54 / 0.8008 |\n| rcan                | 15.4           | 33.19 / 0.9372 | 29.01 / 0.868 | 26.75 / 0.80624 |\n| rdn                 | 22.1           | 32.41 / 0.9310 | 27.49 / 0.838 | 26.36 / 0.79460 |\n\n\u003c/details\u003e\n\n\u003c/details\u003e\n\nAll models are defined in `torchsr.models`. Other useful tools to augment your models, such as self-ensemble methods and tiling, are present in `torchsr.models.utils`.\n\n\n\n## Datasets\n\nThe following datasets are available. Click on the links for the project page:\n*   [DIV2K](https://data.vision.ee.ethz.ch/cvl/DIV2K/)\n*   [RealSR](https://github.com/csjcai/RealSR)\n*   [Flicr2K](https://github.com/limbee/NTIRE2017)\n*   [REDS](https://seungjunnah.github.io/Datasets/reds)\n*   [Set5](http://people.rennes.inria.fr/Aline.Roumy/results/SR_BMVC12.html), [Set14](https://paperswithcode.com/dataset/set14), [B100](https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/bsds/), [Urban100](https://paperswithcode.com/dataset/urban100)\n\nAll datasets are defined in `torchsr.datasets`. They return a list of images, with the high-resolution image followed by downscaled or degraded versions.\nData augmentation methods are provided in `torchsr.transforms`.\n\nDatasets are downloaded automatically when using the `download=True` flag, or by running the corresponding script i.e. `./scripts/download_div2k.sh`.\n\n\n\n## Usage\n\n\n```python\nfrom torchsr.datasets import Div2K\nfrom torchsr.models import ninasr_b0\nfrom torchvision.transforms.functional import to_pil_image, to_tensor\n\n# Div2K dataset\ndataset = Div2K(root=\"./data\", scale=2, download=False)\n\n# Get the first image in the dataset (High-Res and Low-Res)\nhr, lr = dataset[0]\n\n# Download a pretrained NinaSR model\nmodel = ninasr_b0(scale=2, pretrained=True)\n\n# Run the Super-Resolution model\nlr_t = to_tensor(lr).unsqueeze(0)\nsr_t = model(lr_t)\nsr = to_pil_image(sr_t.squeeze(0).clamp(0, 1))\nsr.show()\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eExpand more examples\u003c/summary\u003e\n\n\n```python\nfrom torchsr.datasets import Div2K\nfrom torchsr.models import edsr, rcan\nfrom torchsr.models.utils import ChoppedModel, SelfEnsembleModel\nfrom torchsr.transforms import ColorJitter, Compose, RandomCrop\n\n# Div2K dataset, cropped to 256px, width color jitter\ndataset = Div2K(\n    root=\"./data\", scale=2, download=False,\n    transform=Compose([\n        RandomCrop(256, scales=[1, 2]),\n        ColorJitter(brightness=0.2)\n    ]))\n\n# Pretrained RCAN model, with tiling for large images\nmodel = ChoppedModel(\n    rcan(scale=2, pretrained=True), scale=2,\n    chop_size=400, chop_overlap=10)\n\n# Pretrained EDSR model, with self-ensemble method for higher quality\nmodel = SelfEnsembleModel(edsr(scale=2, pretrained=True))\n```\n\u003c/details\u003e\n\n\n\n## Training\n\nA script is available to train the models from scratch, evaluate them, and much more. It is not part of the pip package, and requires additional dependencies. More examples are available in `scripts/`.\n\n```bash\npip install piq tqdm tensorboard  # Additional dependencies\npython -m torchsr.train -h\npython -m torchsr.train --arch edsr_baseline --scale 2 --download-pretrained --images test/butterfly.png --destination results/\npython -m torchsr.train --arch edsr_baseline --scale 2 --download-pretrained --validation-only\npython -m torchsr.train --arch edsr_baseline --scale 2 --epochs 300 --loss l1 --dataset-train div2k_bicubic\n```\n\nYou can evaluate models from the command line as well. For example, for EDSR with the paper's PSNR evaluation:\n```\npython -m torchsr.train --validation-only --arch edsr_baseline --scale 2 --dataset-val set5 --chop-size 400 --download-pretrained --shave-border 2 --eval-luminance\n```\n\n\n# Acknowledgements\n\nThanks to the people behind [torchvision](https://github.com/pytorch/vision) and [EDSR](https://github.com/zhouhuanxiang/EDSR-PyTorch), whose work inspired this repository.\nSome of the models available here come from [EDSR-PyTorch](https://github.com/zhouhuanxiang/EDSR-PyTorch) and [CARN-PyTorch](https://github.com/nmhkahn/CARN-pytorch).\n\nTo cite this work, please use:\n\n```\n@misc{torchsr,\n  author = {Gabriel Gouvine},\n  title = {Super-Resolution Networks for Pytorch},\n  year = {2021},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://github.com/Coloquinte/torchSR}},\n  doi = {10.5281/zenodo.4868308}\n}\n\n@misc{ninasr,\n  author = {Gabriel Gouvine},\n  title = {NinaSR: Efficient Small and Large ConvNets for Super-Resolution},\n  year = {2021},\n  publisher = {GitHub},\n  journal = {GitHub repository},\n  howpublished = {\\url{https://github.com/Coloquinte/torchSR/blob/main/doc/NinaSR.md}},\n  doi = {10.5281/zenodo.4868308}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoloquinte%2Ftorchsr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoloquinte%2Ftorchsr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoloquinte%2Ftorchsr/lists"}