lucidrains/siren-pytorch
소개
SIREN(주기적 활성화 함수를 사용하는 암시적 신경 표현)의 PyTorch 구현
AI 및 머신러닝측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalSIREN in Pytorch
Pytorch implementation of SIREN - Implicit Neural Representations with Periodic Activation Function
Install
$ pip install siren-pytorch
Usage
A SIREN based multi-layered neural network
import torch
from torch import nn
from siren_pytorch import SirenNet
net = SirenNet(
dim_in = 2, # input dimension, ex. 2d coor
dim_hidden = 256, # hidden dimension
dim_out = 3, # output dimension, ex. rgb value
num_layers = 5, # number of layers
final_activation = nn.Sigmoid(), # activation of final layer (nn.Identity() for direct output)
w0_initial = 30. # different signals may require different omega_0 in the first layer - this is a hyperparameter
)
coor = torch.randn(1, 2)
net(coor) # (1, 3) <- rgb value
One SIREN layer
import torch
from siren_pytorch import Siren
neuron = Siren(
dim_in = 3,
dim_out = 256
)
coor = torch.randn(1, 3)
neuron(coor) # (1, 256)
Sine activation (just a wrapper around torch.sin)
import torch
from siren_pytorch import Sine
act = Sine(1.)
coor = torch.randn(1, 2)
act(coor)
Wrapper to train on a specific image of specified height and width from a given SirenNet, and then to subsequently generate.
import torch
from torch import nn
from siren_pytorch import SirenNet, SirenWrapper
net = SirenNet(
dim_in = 2, # input dimension, ex. 2d coor
dim_hidden = 256, # hidden dimension
dim_out = 3, # output dimension, ex. rgb value
num_layers = 5, # number of layers
w0_initial = 30. # different signals may require different omega_0 in the first layer - this is a hyperparameter
)
wrapper = SirenWrapper(
net,
image_width = 256,
image_height = 256
)
img = torch.randn(1, 3, 256, 256)
loss = wrapper(img)
loss.backward()
# after much training ...
# simply invoke the wrapper without passing in anything
pred_img = wrapper() # (1, 3, 256, 256)
Modulation with Latent Code
A new paper 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.
You can use this simply by setting an extra keyword latent_dim, on the SirenWrapper
import torch
from torch import nn
from siren_pytorch import SirenNet, SirenWrapper
net = SirenNet(
dim_in = 2, # input dimension, ex. 2d coor
dim_hidden = 256, # hidden dimension
dim_out = 3, # output dimension, ex. rgb value
num_layers = 5, # number of layers
w0_initial = 30. # different signals may require different omega_0 in the first layer - this is a hyperparameter
)
wrapper = SirenWrapper(
net,
latent_dim = 512,
image_width = 256,
image_height = 256
)
latent = nn.Parameter(torch.zeros(512).normal_(0, 1e-2))
img = torch.randn(1, 3, 256, 256)
loss = wrapper(img, latent = latent)
loss.backward()
# after much training ...
# simply invoke the wrapper without passing in anything
pred_img = wrapper(latent = latent) # (1, 3, 256, 256)
Citations
@misc{sitzmann2020implicit,
title = {Implicit Neural Representations with Periodic Activation Functions},
author = {Vincent Sitzmann and Julien N. P. Martel and Alexander W. Bergman and David B. Lindell and Gordon Wetzstein},
year = {2020},
eprint = {2006.09661},
archivePrefix = {arXiv},
primaryClass = {cs.CV}
}
@misc{mehta2021modulated,
title = {Modulated Periodic Activations for Generalizable Local Functional Representations},
author = {Ishit Mehta and Michaël Gharbi and Connelly Barnes and Eli Shechtman and Ravi Ramamoorthi and Manmohan Chandraker},
year = {2021},
eprint = {2104.03960},
archivePrefix = {arXiv},
primaryClass = {cs.CV}
}
관련 프로젝트 살펴보기
불러오는 중…