pytorch-parametrizations


Namepytorch-parametrizations JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryParametrizations for PyTorch
upload_time2024-06-07 08:45:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Michał Dyczko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords pytorch parametrizations sadam spectral adam
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytorch-parametrizations

## Spectral Parametrization

    This module provides a PyTorch implementation of the spectral parametrization of the weights of a 2D convolutional layer, as introduced in the paper "Efficient Nonlinear Transforms for Lossy Image Compression" by Johannes Ballé, PCS 2018.

### Usage

```python
import torch
import torch.nn.utils.parametrize as parametrize

from pytorch_parametrizations import SpectralParametrization

# Create a 2D convolutional layer
conv = torch.nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3, padding=1)

# Register the spectral parametrization for the weights of the layer
parametrize.register_parametrization(conv, 'weight', SpectralParametrization(conv.kernel_size), unsafe=True)


print(conv.parametrizations.weight)
# Output:
# conv.parametrizations.weight
# ParametrizationList(
#   (0): SpectralParametrization()
# )
```

## register_spectral_parametrization

    This function registers the spectral parametrization for every Conv2d and ConvTranspose2d layer in a given module.

### Usage

```python
import torch
from pytorch_parametrizations.spectral.utils import register_spectral_parametrization

# Create a module
module = torch.nn.Sequential(
    torch.nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3, padding=1),
    torch.nn.ReLU(),
    torch.nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3, padding=1),
    torch.nn.ReLU(),
    torch.nn.Conv2d(in_channels=64, out_channels=3, kernel_size=3, padding=1),
    torch.nn.Sigmoid()
)

# Register the spectral parametrization for every Conv2d and ConvTranspose2d layer in the module
register_spectral_parametrization(module)

print(module)
# Output:
# Sequential(
#   (0): ParametrizedConv2d(
#     3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
#     (parametrizations): ModuleDict(
#       (weight): ParametrizationList(
#         (0): SpectralParametrization()
#       )
#     )
#   )
#   (1): ReLU()
#   (2): ParametrizedConv2d(
#     64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
#     (parametrizations): ModuleDict(
#       (weight): ParametrizationList(
#         (0): SpectralParametrization()
#       )
#     )
#   )
#   (3): ReLU()
#   (4): ParametrizedConv2d(
#     64, 3, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)
#     (parametrizations): ModuleDict(
#       (weight): ParametrizationList(
#         (0): SpectralParametrization()
#       )
#     )
#   )
#   (5): Sigmoid()
# )

# Unregister the spectral parametrization for every Conv2d and ConvTranspose2d layer in the module
register_spectral_parametrization(module, undo=True)

print(module)
# Output:
# Sequential(
#   (0): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
#   (1): ReLU()
#   (2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
#   (3): ReLU()
#   (4): Conv2d(64, 3, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
#   (5): Sigmoid()
# )
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytorch-parametrizations",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "pytorch, parametrizations, sadam, spectral Adam",
    "author": null,
    "author_email": "Micha\u0142 Dyczko <michal@dyczko.dev>",
    "download_url": "https://files.pythonhosted.org/packages/4c/59/10a55c2f907a265d230671db932936b9b7a95582ca74a5f162e118b32e5c/pytorch_parametrizations-1.0.0.tar.gz",
    "platform": null,
    "description": "# pytorch-parametrizations\n\n## Spectral Parametrization\n\n    This module provides a PyTorch implementation of the spectral parametrization of the weights of a 2D convolutional layer, as introduced in the paper \"Efficient Nonlinear Transforms for Lossy Image Compression\" by Johannes Ball\u00e9, PCS 2018.\n\n### Usage\n\n```python\nimport torch\nimport torch.nn.utils.parametrize as parametrize\n\nfrom pytorch_parametrizations import SpectralParametrization\n\n# Create a 2D convolutional layer\nconv = torch.nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3, padding=1)\n\n# Register the spectral parametrization for the weights of the layer\nparametrize.register_parametrization(conv, 'weight', SpectralParametrization(conv.kernel_size), unsafe=True)\n\n\nprint(conv.parametrizations.weight)\n# Output:\n# conv.parametrizations.weight\n# ParametrizationList(\n#   (0): SpectralParametrization()\n# )\n```\n\n## register_spectral_parametrization\n\n    This function registers the spectral parametrization for every Conv2d and ConvTranspose2d layer in a given module.\n\n### Usage\n\n```python\nimport torch\nfrom pytorch_parametrizations.spectral.utils import register_spectral_parametrization\n\n# Create a module\nmodule = torch.nn.Sequential(\n    torch.nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3, padding=1),\n    torch.nn.ReLU(),\n    torch.nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3, padding=1),\n    torch.nn.ReLU(),\n    torch.nn.Conv2d(in_channels=64, out_channels=3, kernel_size=3, padding=1),\n    torch.nn.Sigmoid()\n)\n\n# Register the spectral parametrization for every Conv2d and ConvTranspose2d layer in the module\nregister_spectral_parametrization(module)\n\nprint(module)\n# Output:\n# Sequential(\n#   (0): ParametrizedConv2d(\n#     3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)\n#     (parametrizations): ModuleDict(\n#       (weight): ParametrizationList(\n#         (0): SpectralParametrization()\n#       )\n#     )\n#   )\n#   (1): ReLU()\n#   (2): ParametrizedConv2d(\n#     64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)\n#     (parametrizations): ModuleDict(\n#       (weight): ParametrizationList(\n#         (0): SpectralParametrization()\n#       )\n#     )\n#   )\n#   (3): ReLU()\n#   (4): ParametrizedConv2d(\n#     64, 3, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1)\n#     (parametrizations): ModuleDict(\n#       (weight): ParametrizationList(\n#         (0): SpectralParametrization()\n#       )\n#     )\n#   )\n#   (5): Sigmoid()\n# )\n\n# Unregister the spectral parametrization for every Conv2d and ConvTranspose2d layer in the module\nregister_spectral_parametrization(module, undo=True)\n\nprint(module)\n# Output:\n# Sequential(\n#   (0): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n#   (1): ReLU()\n#   (2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n#   (3): ReLU()\n#   (4): Conv2d(64, 3, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n#   (5): Sigmoid()\n# )\n```\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Micha\u0142 Dyczko  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Parametrizations for PyTorch",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/michaldyczko/pytorch-parametrizations"
    },
    "split_keywords": [
        "pytorch",
        " parametrizations",
        " sadam",
        " spectral adam"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49a25e475bb794cfe200d72abab6d815f1134047448dd44b65715f4738aea221",
                "md5": "1e1dcfe06d3902879274b4106ffd598e",
                "sha256": "0ebf38211f21c89efe98ce840bd63d95ddcbaa6428ea1dc07d139585ecdf615a"
            },
            "downloads": -1,
            "filename": "pytorch_parametrizations-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1e1dcfe06d3902879274b4106ffd598e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 5287,
            "upload_time": "2024-06-07T08:45:46",
            "upload_time_iso_8601": "2024-06-07T08:45:46.230416Z",
            "url": "https://files.pythonhosted.org/packages/49/a2/5e475bb794cfe200d72abab6d815f1134047448dd44b65715f4738aea221/pytorch_parametrizations-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4c5910a55c2f907a265d230671db932936b9b7a95582ca74a5f162e118b32e5c",
                "md5": "7364cf93611af8cf466ed135996b0f07",
                "sha256": "3867cdbbfdf211d6f1102fe242b8c30184c6e0818e562a4928a98d0997cef88d"
            },
            "downloads": -1,
            "filename": "pytorch_parametrizations-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7364cf93611af8cf466ed135996b0f07",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 3703,
            "upload_time": "2024-06-07T08:45:47",
            "upload_time_iso_8601": "2024-06-07T08:45:47.910201Z",
            "url": "https://files.pythonhosted.org/packages/4c/59/10a55c2f907a265d230671db932936b9b7a95582ca74a5f162e118b32e5c/pytorch_parametrizations-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-07 08:45:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "michaldyczko",
    "github_project": "pytorch-parametrizations",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pytorch-parametrizations"
}
        
Elapsed time: 0.26979s