MCPcopy Create free account
hub / github.com/TEA-Lab/TwoByTwo / VNLeakyReLU

Class VNLeakyReLU

src/shape_assembly/models/encoder/vn_layers.py:36–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35
36class VNLeakyReLU(nn.Module):
37 def __init__(self, in_channels, share_nonlinearity=False, negative_slope=0.2):
38 super(VNLeakyReLU, self).__init__()
39 if share_nonlinearity == True:
40 self.map_to_dir = nn.Linear(in_channels, 1, bias=False)
41 else:
42 self.map_to_dir = nn.Linear(in_channels, in_channels, bias=False)
43 self.negative_slope = negative_slope
44
45 def forward(self, x):
46 '''
47 x: point features of shape [B, N_feat, 3, N_samples, ...]
48 '''
49 d = self.map_to_dir(x.transpose(1, -1)).transpose(1, -1)
50 dotprod = (x * d).sum(2, keepdim=True)
51 mask = (dotprod >= 0).float()
52 d_norm_sq = (d * d).sum(2, keepdim=True)
53 x_out = self.negative_slope * x + (1 - self.negative_slope) * (
54 mask * x + (1 - mask) * (x - (dotprod / (d_norm_sq + EPS)) * d))
55 return x_out
56
57
58class VNNewLeakyReLU(nn.Module):

Callers 3

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected