Bernstein_Poster_2024/avg_pooling_nnmf/L1NormLayer.py

14 lines
319 B
Python
Raw Permalink Normal View History

2024-10-21 16:43:42 +02:00
import torch
class L1NormLayer(torch.nn.Module):
epsilon: float
def __init__(self, epsilon: float = 10e-20) -> None:
super().__init__()
self.epsilon = epsilon
def forward(self, input: torch.Tensor) -> torch.Tensor:
return input / (input.sum(dim=1, keepdim=True) + self.epsilon)