{"id":15600958,"url":"https://github.com/lucidrains/siren-pytorch","last_synced_at":"2025-04-12T20:42:38.500Z","repository":{"id":38830296,"uuid":"273573169","full_name":"lucidrains/siren-pytorch","owner":"lucidrains","description":"Pytorch implementation of SIREN -  Implicit Neural Representations with Periodic Activation Function","archived":false,"fork":false,"pushed_at":"2023-07-28T14:59:08.000Z","size":16,"stargazers_count":482,"open_issues_count":4,"forks_count":51,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-04-04T01:05:24.246Z","etag":null,"topics":["activation-functions","artificial-intelligence","deep-learning"],"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/lucidrains.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-19T19:39:13.000Z","updated_at":"2025-03-28T14:07:18.000Z","dependencies_parsed_at":"2024-06-18T21:27:53.254Z","dependency_job_id":"cb9227a6-b5f2-4935-8507-be2385b724f6","html_url":"https://github.com/lucidrains/siren-pytorch","commit_stats":{"total_commits":24,"total_committers":2,"mean_commits":12.0,"dds":0.04166666666666663,"last_synced_commit":"3555d895b213d243e8aa4db1913d01154cdcdd6b"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fsiren-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fsiren-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fsiren-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Fsiren-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidrains","download_url":"https://codeload.github.com/lucidrains/siren-pytorch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631669,"owners_count":21136554,"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":["activation-functions","artificial-intelligence","deep-learning"],"created_at":"2024-10-03T02:10:21.501Z","updated_at":"2025-04-12T20:42:38.479Z","avatar_url":"https://github.com/lucidrains.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## SIREN in Pytorch\n\n[![PyPI version](https://badge.fury.io/py/siren-pytorch.svg)](https://badge.fury.io/py/siren-pytorch)\n\nPytorch implementation of SIREN -  \u003ca href=\"https://arxiv.org/abs/2006.09661\"\u003eImplicit Neural Representations with Periodic Activation Function\u003c/a\u003e\n\n## Install\n\n```bash\n$ pip install siren-pytorch\n```\n\n## Usage\n\nA SIREN based multi-layered neural network\n\n```python\nimport torch\nfrom torch import nn\nfrom siren_pytorch import SirenNet\n\nnet = SirenNet(\n    dim_in = 2,                        # input dimension, ex. 2d coor\n    dim_hidden = 256,                  # hidden dimension\n    dim_out = 3,                       # output dimension, ex. rgb value\n    num_layers = 5,                    # number of layers\n    final_activation = nn.Sigmoid(),   # activation of final layer (nn.Identity() for direct output)\n    w0_initial = 30.                   # different signals may require different omega_0 in the first layer - this is a hyperparameter\n)\n\ncoor = torch.randn(1, 2)\nnet(coor) # (1, 3) \u003c- rgb value\n```\n\nOne SIREN layer\n\n```python\nimport torch\nfrom siren_pytorch import Siren\n\nneuron = Siren(\n    dim_in = 3,\n    dim_out = 256\n)\n\ncoor = torch.randn(1, 3)\nneuron(coor) # (1, 256)\n```\n\nSine activation (just a wrapper around `torch.sin`)\n\n```python\nimport torch\nfrom siren_pytorch import Sine\n\nact = Sine(1.)\ncoor = torch.randn(1, 2)\nact(coor)\n```\n\nWrapper to train on a specific image of specified height and width from a given `SirenNet`, and then to subsequently generate.\n\n\n```python\nimport torch\nfrom torch import nn\nfrom siren_pytorch import SirenNet, SirenWrapper\n\nnet = SirenNet(\n    dim_in = 2,                        # input dimension, ex. 2d coor\n    dim_hidden = 256,                  # hidden dimension\n    dim_out = 3,                       # output dimension, ex. rgb value\n    num_layers = 5,                    # number of layers\n    w0_initial = 30.                   # different signals may require different omega_0 in the first layer - this is a hyperparameter\n)\n\nwrapper = SirenWrapper(\n    net,\n    image_width = 256,\n    image_height = 256\n)\n\nimg = torch.randn(1, 3, 256, 256)\nloss = wrapper(img)\nloss.backward()\n\n# after much training ...\n# simply invoke the wrapper without passing in anything\n\npred_img = wrapper() # (1, 3, 256, 256)\n```\n\n## Modulation with Latent Code\n\nA \u003ca href=\"https://arxiv.org/abs/2104.03960\"\u003enew paper\u003c/a\u003e proposes that the best way to condition a Siren with a latent code is to pass the latent vector through a modulator feedforward network, where each layer's hidden state is elementwise multiplied with the corresponding layer of the Siren.\n\nYou can use this simply by setting an extra keyword `latent_dim`, on the `SirenWrapper`\n\n```python\nimport torch\nfrom torch import nn\nfrom siren_pytorch import SirenNet, SirenWrapper\n\nnet = SirenNet(\n    dim_in = 2,                        # input dimension, ex. 2d coor\n    dim_hidden = 256,                  # hidden dimension\n    dim_out = 3,                       # output dimension, ex. rgb value\n    num_layers = 5,                    # number of layers\n    w0_initial = 30.                   # different signals may require different omega_0 in the first layer - this is a hyperparameter\n)\n\nwrapper = SirenWrapper(\n    net,\n    latent_dim = 512,\n    image_width = 256,\n    image_height = 256\n)\n\nlatent = nn.Parameter(torch.zeros(512).normal_(0, 1e-2))\nimg = torch.randn(1, 3, 256, 256)\n\nloss = wrapper(img, latent = latent)\nloss.backward()\n\n# after much training ...\n# simply invoke the wrapper without passing in anything\n\npred_img = wrapper(latent = latent) # (1, 3, 256, 256)\n```\n\n## Citations\n\n```bibtex\n@misc{sitzmann2020implicit,\n    title   = {Implicit Neural Representations with Periodic Activation Functions},\n    author  = {Vincent Sitzmann and Julien N. P. Martel and Alexander W. Bergman and David B. Lindell and Gordon Wetzstein},\n    year    = {2020},\n    eprint  = {2006.09661},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.CV}\n}\n```\n\n```bibtex\n@misc{mehta2021modulated,\n    title   = {Modulated Periodic Activations for Generalizable Local Functional Representations}, \n    author  = {Ishit Mehta and Michaël Gharbi and Connelly Barnes and Eli Shechtman and Ravi Ramamoorthi and Manmohan Chandraker},\n    year    = {2021},\n    eprint  = {2104.03960},\n    archivePrefix = {arXiv},\n    primaryClass = {cs.CV}\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fsiren-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidrains%2Fsiren-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Fsiren-pytorch/lists"}