{"id":15038013,"url":"https://github.com/po-hsun-su/pytorch-ssim","last_synced_at":"2025-05-14T20:05:21.334Z","repository":{"id":37470676,"uuid":"99848212","full_name":"Po-Hsun-Su/pytorch-ssim","owner":"Po-Hsun-Su","description":"pytorch structural similarity (SSIM) loss","archived":false,"fork":false,"pushed_at":"2024-02-22T09:28:51.000Z","size":1212,"stargazers_count":1918,"open_issues_count":33,"forks_count":370,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-13T15:09:59.754Z","etag":null,"topics":["image-analysis","image-processing","pytorch"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Po-Hsun-Su.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-09T20:04:28.000Z","updated_at":"2025-04-11T08:34:12.000Z","dependencies_parsed_at":"2024-01-16T22:18:09.285Z","dependency_job_id":"4aa58186-de04-4d13-882b-330544731f87","html_url":"https://github.com/Po-Hsun-Su/pytorch-ssim","commit_stats":{"total_commits":17,"total_committers":2,"mean_commits":8.5,"dds":"0.11764705882352944","last_synced_commit":"3add4532d3f633316cba235da1c69e90f0dfb952"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Po-Hsun-Su%2Fpytorch-ssim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Po-Hsun-Su%2Fpytorch-ssim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Po-Hsun-Su%2Fpytorch-ssim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Po-Hsun-Su%2Fpytorch-ssim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Po-Hsun-Su","download_url":"https://codeload.github.com/Po-Hsun-Su/pytorch-ssim/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732486,"owners_count":21152852,"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":["image-analysis","image-processing","pytorch"],"created_at":"2024-09-24T20:36:49.075Z","updated_at":"2025-04-13T15:10:17.396Z","avatar_url":"https://github.com/Po-Hsun-Su.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pytorch-ssim (This repo is not maintained) \n\nThe code doesn't work because it is on super old pytorch.\n\n### Differentiable structural similarity (SSIM) index.\n![einstein](https://raw.githubusercontent.com/Po-Hsun-Su/pytorch-ssim/master/einstein.png) ![Max_ssim](https://raw.githubusercontent.com/Po-Hsun-Su/pytorch-ssim/master/max_ssim.gif)\n\n## Installation\n1. Clone this repo.\n2. Copy \"pytorch_ssim\" folder in your project.\n\n## Example\n### basic usage\n```python\nimport pytorch_ssim\nimport torch\nfrom torch.autograd import Variable\n\nimg1 = Variable(torch.rand(1, 1, 256, 256))\nimg2 = Variable(torch.rand(1, 1, 256, 256))\n\nif torch.cuda.is_available():\n    img1 = img1.cuda()\n    img2 = img2.cuda()\n\nprint(pytorch_ssim.ssim(img1, img2))\n\nssim_loss = pytorch_ssim.SSIM(window_size = 11)\n\nprint(ssim_loss(img1, img2))\n\n```\n### maximize ssim\n```python\nimport pytorch_ssim\nimport torch\nfrom torch.autograd import Variable\nfrom torch import optim\nimport cv2\nimport numpy as np\n\nnpImg1 = cv2.imread(\"einstein.png\")\n\nimg1 = torch.from_numpy(np.rollaxis(npImg1, 2)).float().unsqueeze(0)/255.0\nimg2 = torch.rand(img1.size())\n\nif torch.cuda.is_available():\n    img1 = img1.cuda()\n    img2 = img2.cuda()\n\n\nimg1 = Variable( img1,  requires_grad=False)\nimg2 = Variable( img2, requires_grad = True)\n\n\n# Functional: pytorch_ssim.ssim(img1, img2, window_size = 11, size_average = True)\nssim_value = pytorch_ssim.ssim(img1, img2).data[0]\nprint(\"Initial ssim:\", ssim_value)\n\n# Module: pytorch_ssim.SSIM(window_size = 11, size_average = True)\nssim_loss = pytorch_ssim.SSIM()\n\noptimizer = optim.Adam([img2], lr=0.01)\n\nwhile ssim_value \u003c 0.95:\n    optimizer.zero_grad()\n    ssim_out = -ssim_loss(img1, img2)\n    ssim_value = - ssim_out.data[0]\n    print(ssim_value)\n    ssim_out.backward()\n    optimizer.step()\n\n```\n\n## Reference\nhttps://ece.uwaterloo.ca/~z70wang/research/ssim/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpo-hsun-su%2Fpytorch-ssim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpo-hsun-su%2Fpytorch-ssim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpo-hsun-su%2Fpytorch-ssim/lists"}