Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
iperov
GitHub Repository: iperov/deepfacelab
Path: blob/master/core/leras/layers/TLU.py
628 views
1
from core.leras import nn
2
tf = nn.tf
3
4
class TLU(nn.LayerBase):
5
"""
6
Tensorflow implementation of
7
Filter Response Normalization Layer: Eliminating Batch Dependence in theTraining of Deep Neural Networks
8
https://arxiv.org/pdf/1911.09737.pdf
9
"""
10
def __init__(self, in_ch, dtype=None, **kwargs):
11
self.in_ch = in_ch
12
13
if dtype is None:
14
dtype = nn.floatx
15
self.dtype = dtype
16
17
super().__init__(**kwargs)
18
19
def build_weights(self):
20
self.tau = tf.get_variable("tau", (self.in_ch,), dtype=self.dtype, initializer=tf.initializers.zeros() )
21
22
def get_weights(self):
23
return [self.tau]
24
25
def forward(self, x):
26
if nn.data_format == "NHWC":
27
shape = (1,1,1,self.in_ch)
28
else:
29
shape = (1,self.in_ch,1,1)
30
31
tau = tf.reshape ( self.tau, shape )
32
return tf.math.maximum(x, tau)
33
nn.TLU = TLU
34