SAEHD: added 'dfuhd' and 'liaeuhd' archi

This commit is contained in:
Colombo 2020-03-23 22:01:44 +04:00
commit eddebedcf6
5 changed files with 190 additions and 155 deletions

View file

@ -0,0 +1,16 @@
from core.leras import nn
tf = nn.tf
class DenseNorm(nn.LayerBase):
def __init__(self, dense=False, eps=1e-06, dtype=None, **kwargs):
self.dense = dense
if dtype is None:
dtype = nn.floatx
self.eps = tf.constant(eps, dtype=dtype, name="epsilon")
super().__init__(**kwargs)
def __call__(self, x):
return x * tf.rsqrt(tf.reduce_mean(tf.square(x), axis=-1, keepdims=True) + self.eps)
nn.DenseNorm = DenseNorm

View file

@ -0,0 +1,31 @@
from core.leras import nn
tf = nn.tf
class ScaleAdd(nn.LayerBase):
def __init__(self, ch, dtype=None, **kwargs):
if dtype is None:
dtype = nn.floatx
self.dtype = dtype
self.ch = ch
super().__init__(**kwargs)
def build_weights(self):
self.weight = tf.get_variable("weight",(self.ch,), dtype=self.dtype, initializer=tf.initializers.zeros() )
def get_weights(self):
return [self.weight]
def forward(self, inputs):
if nn.data_format == "NHWC":
shape = (1,1,1,self.ch)
else:
shape = (1,self.ch,1,1)
weight = tf.reshape ( self.weight, shape )
x0, x1 = inputs
x = x0 + x1*weight
return x
nn.ScaleAdd = ScaleAdd

View file

@ -9,4 +9,6 @@ from .BlurPool import *
from .BatchNorm2D import *
from .FRNorm2D import *
from .TLU import *
from .TLU import *
from .ScaleAdd import *
from .DenseNorm import *