Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
iperov
GitHub Repository: iperov/deepfacelab
Path: blob/master/core/leras/layers/ScaleAdd.py
628 views
1
from core.leras import nn
2
tf = nn.tf
3
4
class ScaleAdd(nn.LayerBase):
5
def __init__(self, ch, dtype=None, **kwargs):
6
if dtype is None:
7
dtype = nn.floatx
8
self.dtype = dtype
9
self.ch = ch
10
11
super().__init__(**kwargs)
12
13
def build_weights(self):
14
self.weight = tf.get_variable("weight",(self.ch,), dtype=self.dtype, initializer=tf.initializers.zeros() )
15
16
def get_weights(self):
17
return [self.weight]
18
19
def forward(self, inputs):
20
if nn.data_format == "NHWC":
21
shape = (1,1,1,self.ch)
22
else:
23
shape = (1,self.ch,1,1)
24
25
weight = tf.reshape ( self.weight, shape )
26
27
x0, x1 = inputs
28
x = x0 + x1*weight
29
30
return x
31
nn.ScaleAdd = ScaleAdd
32