{"id":22111723,"url":"https://github.com/agentmaker/paddle-msssim","last_synced_at":"2025-07-25T07:32:13.747Z","repository":{"id":57450212,"uuid":"461898720","full_name":"AgentMaker/Paddle-MSSSIM","owner":"AgentMaker","description":"Fast and differentiable MS-SSIM and SSIM for Paddle.","archived":false,"fork":false,"pushed_at":"2022-02-23T09:02:51.000Z","size":3428,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-09-23T13:07:33.521Z","etag":null,"topics":["cv","deeplearning","loss","ms-ssim","msssim","paddle","paddlepaddle","ssim"],"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/AgentMaker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-21T14:33:14.000Z","updated_at":"2024-05-14T21:43:16.000Z","dependencies_parsed_at":"2022-08-25T23:00:28.397Z","dependency_job_id":null,"html_url":"https://github.com/AgentMaker/Paddle-MSSSIM","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaddle-MSSSIM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaddle-MSSSIM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaddle-MSSSIM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgentMaker%2FPaddle-MSSSIM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AgentMaker","download_url":"https://codeload.github.com/AgentMaker/Paddle-MSSSIM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227543361,"owners_count":17785195,"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":["cv","deeplearning","loss","ms-ssim","msssim","paddle","paddlepaddle","ssim"],"created_at":"2024-12-01T10:51:37.857Z","updated_at":"2024-12-01T10:51:41.337Z","avatar_url":"https://github.com/AgentMaker.png","language":"Python","readme":"# Paddle MS-SSIM\n\n## Introduction\n* Fast and differentiable MS-SSIM and SSIM for Paddle.\n\n    \u003cimg src=\"./images/lcs.png\" width=\"25%\"\u003e\n\n* Structural Similarity (SSIM): \n\n    \u003cimg src=\"./images/ssim.png\" width=\"50%\"\u003e\n\n* Multi-Scale Structural Similarity (MS-SSIM):\n\n    \u003cimg src=\"./images/ms-ssim.png\" width=\"55%\"\u003e\n\n## Installation\n* via pip\n\n    ```bash\n    $ pip install paddle-msssim\n    ```\n\n* via sources\n\n    ```bash\n    $ git clone https://github.com/AgentMaker/Paddle-MSSSIM\n\n    $ cd Paddle-MSSSIM\n\n    $ python setup.py install\n    ```\n## Requirement\n\n* paddlepaddle / paddlepaddle-gpu \u003e= 2.0.0\n\n## Usage\n\n* Basic Usage \n\n    ```python\n    from paddle_msssim import ssim, ms_ssim, SSIM, MS_SSIM\n    # X: (N,3,H,W) a batch of non-negative RGB images (0~255)\n    # Y: (N,3,H,W)  \n\n    # calculate ssim \u0026 ms-ssim for each image\n    ssim_val = ssim( X, Y, data_range=255, size_average=False) # return (N,)\n    ms_ssim_val = ms_ssim( X, Y, data_range=255, size_average=False ) #(N,)\n\n    # set 'size_average=True' to get a scalar value as loss. see tests/tests_loss.py for more details\n    ssim_loss = 1 - ssim( X, Y, data_range=255, size_average=True) # return a scalar\n    ms_ssim_loss = 1 - ms_ssim( X, Y, data_range=255, size_average=True )\n\n    # reuse the gaussian kernel with SSIM \u0026 MS_SSIM. \n    ssim_module = SSIM(data_range=255, size_average=True, channel=3) # channel=1 for grayscale images\n    ms_ssim_module = MS_SSIM(data_range=255, size_average=True, channel=3)\n\n    ssim_loss = 1 - ssim_module(X, Y)\n    ms_ssim_loss = 1 - ms_ssim_module(X, Y)\n    ```\n\n* Normalized input\n\n    ```python\n    '''\n    If you need to calculate MS-SSIM/SSIM on normalized images\n    Please denormalize them to the range of [0, 1] or [0, 255] first\n    '''\n    # X: (N,3,H,W) a batch of normalized images (-1 ~ 1)\n    # Y: (N,3,H,W)  \n    X = (X + 1) / 2  # [-1, 1] =\u003e [0, 1]\n    Y = (Y + 1) / 2  \n    ms_ssim_val = ms_ssim( X, Y, data_range=1, size_average=False ) #(N,)\n    ```\n\n* Enable nonnegative_ssim\n\n    * For ssim, it is recommended to set `nonnegative_ssim=True` to avoid negative results. However, this option is set to `False` by default to keep it consistent with tensorflow and skimage.\n\n    * For ms-ssim, there is no nonnegative_ssim option and the ssim reponses is forced to be non-negative to avoid NaN results.\n\n## Test\n* Switch to the tests dir\n\n    ```bash\n    $ cd ./tests\n    ```\n\n* Benchmark\n\n    ```bash \n    $ python comparisons_skimage_tf_torch.py\n    ```\n\n        outputs(AMD Ryzen 4600H): \n\n        ===================================\n                    Test SSIM\n        ===================================\n        ====\u003e Single Image\n        Repeat 10 times\n        sigma=0.0 ssim_skimage=1.000000 (247.7732 ms), ssim_tf=1.000000 (277.2696 ms), ssim_paddle=1.000000 (179.4677 ms), ssim_torch=1.000000 (183.6994 ms)\n        sigma=10.0 ssim_skimage=0.932399 (226.1620 ms), ssim_tf=0.932640 (257.2435 ms), ssim_paddle=0.932636 (163.2263 ms), ssim_torch=0.932400 (179.1418 ms)\n        sigma=20.0 ssim_skimage=0.786023 (224.1826 ms), ssim_tf=0.786032 (279.2126 ms), ssim_paddle=0.786017 (158.3070 ms), ssim_torch=0.786027 (180.0890 ms)\n        sigma=30.0 ssim_skimage=0.637174 (237.5582 ms), ssim_tf=0.637183 (267.6092 ms), ssim_paddle=0.637165 (167.9277 ms), ssim_torch=0.637178 (181.7910 ms)\n        sigma=40.0 ssim_skimage=0.515865 (221.0388 ms), ssim_tf=0.515876 (264.3230 ms), ssim_paddle=0.515857 (170.7676 ms), ssim_torch=0.515869 (189.0941 ms)\n        sigma=50.0 ssim_skimage=0.422551 (222.6846 ms), ssim_tf=0.422558 (273.1971 ms), ssim_paddle=0.422542 (168.3579 ms), ssim_torch=0.422554 (176.7442 ms)\n        sigma=60.0 ssim_skimage=0.351337 (215.1536 ms), ssim_tf=0.351340 (270.5560 ms), ssim_paddle=0.351325 (164.3315 ms), ssim_torch=0.351340 (194.6781 ms)\n        sigma=70.0 ssim_skimage=0.295752 (210.0273 ms), ssim_tf=0.295756 (272.1814 ms), ssim_paddle=0.295744 (169.3864 ms), ssim_torch=0.295755 (178.9230 ms)\n        sigma=80.0 ssim_skimage=0.253164 (239.2978 ms), ssim_tf=0.253169 (260.8894 ms), ssim_paddle=0.253157 (184.7061 ms), ssim_torch=0.253166 (181.4640 ms)\n        sigma=90.0 ssim_skimage=0.219240 (224.7329 ms), ssim_tf=0.219245 (270.3727 ms), ssim_paddle=0.219235 (172.3580 ms), ssim_torch=0.219242 (180.5838 ms)\n        sigma=100.0 ssim_skimage=0.192630 (238.8582 ms), ssim_tf=0.192634 (261.4317 ms), ssim_paddle=0.192624 (166.0294 ms), ssim_torch=0.192632 (175.7241 ms)\n        Pass!\n        ====\u003e Batch\n        Pass!\n\n\n        ===================================\n                    Test MS-SSIM\n        ===================================\n        ====\u003e Single Image\n        Repeat 10 times\n        sigma=0.0 msssim_tf=1.000000 (534.9398 ms), msssim_paddle=1.000000 (231.7381 ms), msssim_torch=1.000000 (257.3238 ms)\n        sigma=10.0 msssim_tf=0.991148 (525.1758 ms), msssim_paddle=0.991147 (213.8527 ms), msssim_torch=0.991101 (243.9299 ms)\n        sigma=20.0 msssim_tf=0.967450 (523.3070 ms), msssim_paddle=0.967447 (217.2415 ms), msssim_torch=0.967441 (253.1073 ms)\n        sigma=30.0 msssim_tf=0.934692 (538.5145 ms), msssim_paddle=0.934687 (215.2203 ms), msssim_torch=0.934692 (242.5429 ms)\n        sigma=40.0 msssim_tf=0.897363 (558.0346 ms), msssim_paddle=0.897357 (219.1107 ms), msssim_torch=0.897362 (249.1027 ms)\n        sigma=50.0 msssim_tf=0.859276 (524.8582 ms), msssim_paddle=0.859267 (232.4189 ms), msssim_torch=0.859275 (263.1328 ms)\n        sigma=60.0 msssim_tf=0.820967 (512.8726 ms), msssim_paddle=0.820958 (223.7422 ms), msssim_torch=0.820965 (251.9713 ms)\n        sigma=70.0 msssim_tf=0.784204 (529.6149 ms), msssim_paddle=0.784194 (213.1742 ms), msssim_torch=0.784203 (244.9676 ms)\n        sigma=80.0 msssim_tf=0.748574 (545.3014 ms), msssim_paddle=0.748563 (222.8581 ms), msssim_torch=0.748572 (261.0413 ms)\n        sigma=90.0 msssim_tf=0.715980 (538.3886 ms), msssim_paddle=0.715968 (214.4464 ms), msssim_torch=0.715977 (282.6247 ms)\n        sigma=100.0 msssim_tf=0.683882 (540.9150 ms), msssim_paddle=0.683870 (218.5596 ms), msssim_torch=0.683880 (244.1856 ms)\n        Pass\n        ====\u003e Batch\n        Pass\n\n## Example\n* Image comparison\n\n    |SSIM = 1.0000|SSIM = 0.4225|SSIM = 0.1924|\n    |:-:|:-:|:-:|\n    |![](./images/simga_0_ssim_1.0000.png) |![](./images/simga_50_ssim_0.4225.png)|![](./images/simga_100_ssim_0.1924.png)|\n\n* As a loss function\n\n    * switch to the examples/as_loss dir\n\n        ```bash\n        $ cd ./examples/as_loss\n        ```\n    \n    * run the example script as_loss.py\n\n        ```bash\n        $ python as_loss.py\n        ```\n\n            Initial ssim: 0.9937540888786316\n            step: 1 ssim_loss: 0.993843\n            step: 2 ssim_loss: 0.993934\n            step: 3 ssim_loss: 0.994021\n            step: 4 ssim_loss: 0.994106\n            step: 5 ssim_loss: 0.994190\n            ...\n            step: 81 ssim_loss: 0.999762\n            step: 82 ssim_loss: 0.999785\n            step: 83 ssim_loss: 0.999862\n            step: 84 ssim_loss: 0.999874\n            step: 85 ssim_loss: 0.999884\n            step: 86 ssim_loss: 0.999892\n            step: 87 ssim_loss: 0.999912\n\n    * result\n\n        |Input|Output|\n        |:-:|:-:|\n        |![](./examples/as_loss/einstein.png) |![](./examples/as_loss/results.png)|\n\n    * See [examples/as_loss/as_loss.py](./examples/as_loss/as_loss.py) for more details\n\n* Auto Encoder\n\n    * See [examples/auto_encoder](./examples/auto_encoder) for more details\n\n## References\n \n* [SSIM Research](https://ece.uwaterloo.ca/~z70wang/research/ssim/) \n\n* [SSIM Paper](https://ece.uwaterloo.ca/~z70wang/publications/ssim.pdf)\n\n* [MS-SSIM Paper](https://ece.uwaterloo.ca/~z70wang/publications/msssim.pdf)  \n\n* [Matlab Code](https://ece.uwaterloo.ca/~z70wang/research/iwssim/)   \n\n* [Pytorch Code](https://github.com/VainF/pytorch-msssim) \n\n* [TensorFlow Code](https://github.com/tensorflow/tensorflow/blob/v2.1.0/tensorflow/python/ops/image_ops_impl.py#L3314-L3438) \n\n## Thanks\n* This repo is based on [Pytorch MS-SSIM](https://github.com/VainF/pytorch-msssim) developed by [@VainF](https://github.com/VainF).\n\n* Thanks to the above project and its developers.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentmaker%2Fpaddle-msssim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagentmaker%2Fpaddle-msssim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentmaker%2Fpaddle-msssim/lists"}