mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-14 02:37:00 -07:00
global refactoring and fixes,
removed support of extracted(aligned) PNG faces. Use old builds to convert from PNG to JPG. fanseg model file in facelib/ is renamed
This commit is contained in:
parent
921b464d5b
commit
61472cdaf7
82 changed files with 3838 additions and 3812 deletions
40
core/leras/layers/InstanceNorm2D.py
Normal file
40
core/leras/layers/InstanceNorm2D.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
from core.leras import nn
|
||||
tf = nn.tf
|
||||
|
||||
class InstanceNorm2D(nn.LayerBase):
|
||||
def __init__(self, in_ch, dtype=None, **kwargs):
|
||||
self.in_ch = in_ch
|
||||
|
||||
if dtype is None:
|
||||
dtype = nn.floatx
|
||||
self.dtype = dtype
|
||||
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def build_weights(self):
|
||||
kernel_initializer = tf.initializers.glorot_uniform(dtype=self.dtype)
|
||||
self.weight = tf.get_variable("weight", (self.in_ch,), dtype=self.dtype, initializer=kernel_initializer )
|
||||
self.bias = tf.get_variable("bias", (self.in_ch,), dtype=self.dtype, initializer=tf.initializers.zeros() )
|
||||
|
||||
def get_weights(self):
|
||||
return [self.weight, self.bias]
|
||||
|
||||
def forward(self, x):
|
||||
if nn.data_format == "NHWC":
|
||||
shape = (1,1,1,self.in_ch)
|
||||
else:
|
||||
shape = (1,self.in_ch,1,1)
|
||||
|
||||
weight = tf.reshape ( self.weight , shape )
|
||||
bias = tf.reshape ( self.bias , shape )
|
||||
|
||||
x_mean = tf.reduce_mean(x, axis=nn.conv2d_spatial_axes, keepdims=True )
|
||||
x_std = tf.math.reduce_std(x, axis=nn.conv2d_spatial_axes, keepdims=True ) + 1e-5
|
||||
|
||||
x = (x - x_mean) / x_std
|
||||
x *= weight
|
||||
x += bias
|
||||
|
||||
return x
|
||||
|
||||
nn.InstanceNorm2D = InstanceNorm2D
|
Loading…
Add table
Add a link
Reference in a new issue