Skip to content

Commit

Permalink
Added LayerNorm implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dusan Malic committed Jan 29, 2021
1 parent f79df70 commit 091612a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions torchsparse/nn/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .conv import *
from .pooling import *
from .detection import *
from .layernorm import *
23 changes: 23 additions & 0 deletions torchsparse/nn/modules/layernorm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from torch import nn

from torchsparse.sparse_tensor import *

__all__ = ['LayerNorm']


class LayerNorm(nn.LayerNorm):
def __init__(self,
normalized_shape,
eps=1e-05,
elementwise_affine=True):
super().__init__(normalized_shape, eps=eps, elementwise_affine=elementwise_affine)

def forward(self, inputs):
features = inputs.F
coords = inputs.C
cur_stride = inputs.s
output_features = super().forward(features)
output_tensor = SparseTensor(output_features, coords, cur_stride)
output_tensor.coord_maps = inputs.coord_maps
output_tensor.kernel_maps = inputs.kernel_maps
return output_tensor

0 comments on commit 091612a

Please sign in to comment.