Skip to main content

Sinusoidal Representation Networks (SIREN)

Unofficial PyTorch implementation of Sinusodial Representation networks (SIREN) from the paper Implicit Neural Representations with Periodic Activation Functions. This repository is a PyTorch port of this excellent TF 2.0 implementation of the same.

Setup

  • Install using pip
$ pip install siren-torch

Usage

Sine activation

You can use the Sine activation as any other activation

from siren import Sine

x = torch.rand(10)
y = Sine(w0=1)(x)

Initialization

The authors in the paper propose a principled way of intializing the layers for the SIREN model. The initialization function can be used as any other initialization present in torch.nn.init.

from siren.init import siren_uniform_

w = torch.empty(3, 5)
siren_uniform_(w, mode='fan_in', c=6)

SIREN model

The SIREN model used in the paper, with sine activation and custom initialization, can directly be created as follows.

from siren import SIREN

# defining the model
layers = [256, 256, 256, 256, 256]
in_features = 2
out_features = 3
initializer = 'siren'
w0 = 1.0
w0_initial = 30.0
c = 6
model = SIREN(
    layers, in_features, out_features, w0, w0_initial,
    initializer=initializer, c=c)

# defining the input
x = torch.rand(10, 2)

# forward pass
y = model(x)

Results on Image Inpainting task

A partial implementation of the image inpainting task is available as the train_inpainting_siren.py and eval_inpainting_siren.py scripts.

To run training:

$ python scripts/train_inpainting_siren.py

To run evaluation:

$ python scripts/eval_inpainting_siren.py

Weight files are made available in the repository under the checkpoints directory. It generates the following output after 5000 epochs of training with batch size 8192 while using only 10% of the available pixels in the image during training phase.

Tests

Tests are written using unittest. You can run any script under the tests folder.

Contributing

As mentioned at the beginning, this codebase is a PyTorch port of this. So, I might have missed a few details mentioned in the original paper. Assuming that the implemention in the linked repo is correct, one can safely trust this implementation as well. The only major difference from the reference repo is that it has w0 as part of the initialization as well. I did not see that in the paper and hence, didn't include it here. I have not deeply read the paper and this is simply to serve as a starting point for anyone looking for the implementation. Please feel free to make a PR or create an issue if you find a bug or you want to contribute to improve any other aspect of the codebase.

Metadata

Release files for siren-torch 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for siren-torch 1.1
File Size Uploaded
siren-torch-1.1.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for siren-torch 1.1
File Interpreter ABI Platform
siren_torch-1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.7 kB

Release files / siren-torch-1.1.tar.gz

Download URL siren-torch-1.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
621e670b3e7b827fcd4694025a3db9ba1a23a2d3bad9be03625c9b64b4249d73
BLAKE2b-256 checksum
How to use checksums
4dbead6f0fb7d9aa7761a98a681deaf4962aee12d003e89e13d60e5c7a8339bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.5.2

Release files / siren_torch-1.1-py3-none-any.whl

Download URL siren_torch-1.1-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f8d3488678fd452fc9cba154e32a28dd225163f34c353ab4b9a1d7b92f4632b
BLAKE2b-256 checksum
How to use checksums
ce85691f212afb61008159414e647ec583d11ca007fdc17441c83c06a07d667b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.5.2

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page