Skip to main content

PyTorch implementation of Sinusodial Representation networks (SIREN)

Project description

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 dependencies using requirements.txt
$ pip install -r requirements.txt
  • Add this folder to your PYTHONPATH
$ export PYTHONPATH=/path/to/siren:$PYTHONPATH

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

siren-torch-1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

siren_torch-1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file siren-torch-1.0.tar.gz.

File metadata

  • Download URL: siren-torch-1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for siren-torch-1.0.tar.gz
Algorithm Hash digest
SHA256 87530eab818d17f506f69f3282092c4f63864d9011d421250bcc9a2929348a5d
MD5 a2f2c8dee80b84bc989364e25169b1f1
BLAKE2b-256 324ed78e741859bce7411281467b373d0f5ff077280032ece1dc304d0607150b

See more details on using hashes here.

File details

Details for the file siren_torch-1.0-py3-none-any.whl.

File metadata

  • Download URL: siren_torch-1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for siren_torch-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b773d9084333a1ea55cf03f30382eb7cfef99ea2601009eb5d7b4316846bd1b
MD5 573b76546f5e40d3005c0ae248cd7633
BLAKE2b-256 e6676eafdc9abb5e6b7d663a75a84c1a91d434ce5e7afc7f7e7138b8f2814458

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page