mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-05 20:42:11 -07:00
Maximum resolution is increased to 640. ‘hd’ archi is removed. ‘hd’ was experimental archi created to remove subpixel shake, but ‘lr_dropout’ and ‘disable random warping’ do that better. ‘uhd’ is renamed to ‘-u’ dfuhd and liaeuhd will be automatically renamed to df-u and liae-u in existing models. Added new experimental archi (key -d) which doubles the resolution using the same computation cost. It is mean same configs will be x2 faster, or for example you can set 448 resolution and it will train as 224. Strongly recommended not to train from scratch and use pretrained models. New archi naming: 'df' keeps more identity-preserved face. 'liae' can fix overly different face shapes. '-u' increased likeness of the face. '-d' (experimental) doubling the resolution using the same computation cost Examples: df, liae, df-d, df-ud, liae-ud, ... Improved GAN training (GAN_power option). It was used for dst model, but actually we don’t need it for dst. Instead, a second src GAN model with x2 smaller patch size was added, so the overall quality for hi-res models should be higher. Added option ‘Uniform yaw distribution of samples (y/n)’: Helps to fix blurry side faces due to small amount of them in the faceset. Quick96: Now based on df-ud archi and 20% faster. XSeg trainer: Improved sample generator. Now it randomly adds the background from other samples. Result is reduced chance of random mask noise on the area outside the face. Now you can specify ‘batch_size’ in range 2-16. Reduced size of samples with applied XSeg mask. Thus size of packed samples with applied xseg mask is also reduced.
77 lines
No EOL
3.1 KiB
Python
77 lines
No EOL
3.1 KiB
Python
from core.leras import nn
|
|
tf = nn.tf
|
|
|
|
|
|
patch_discriminator_kernels = \
|
|
{ 1 : (512, [ [1,1] ]),
|
|
2 : (512, [ [2,1] ]),
|
|
3 : (512, [ [2,1], [2,1] ]),
|
|
4 : (512, [ [2,2], [2,2] ]),
|
|
5 : (512, [ [3,2], [2,2] ]),
|
|
6 : (512, [ [4,2], [2,2] ]),
|
|
7 : (512, [ [3,2], [3,2] ]),
|
|
8 : (512, [ [4,2], [3,2] ]),
|
|
9 : (512, [ [3,2], [4,2] ]),
|
|
10 : (512, [ [4,2], [4,2] ]),
|
|
11 : (512, [ [3,2], [3,2], [2,1] ]),
|
|
12 : (512, [ [4,2], [3,2], [2,1] ]),
|
|
13 : (512, [ [3,2], [4,2], [2,1] ]),
|
|
14 : (512, [ [4,2], [4,2], [2,1] ]),
|
|
15 : (512, [ [3,2], [3,2], [3,1] ]),
|
|
16 : (512, [ [4,2], [3,2], [3,1] ]),
|
|
17 : (512, [ [3,2], [4,2], [3,1] ]),
|
|
18 : (512, [ [4,2], [4,2], [3,1] ]),
|
|
19 : (512, [ [3,2], [3,2], [4,1] ]),
|
|
20 : (512, [ [4,2], [3,2], [4,1] ]),
|
|
21 : (512, [ [3,2], [4,2], [4,1] ]),
|
|
22 : (512, [ [4,2], [4,2], [4,1] ]),
|
|
23 : (256, [ [3,2], [3,2], [3,2], [2,1] ]),
|
|
24 : (256, [ [4,2], [3,2], [3,2], [2,1] ]),
|
|
25 : (256, [ [3,2], [4,2], [3,2], [2,1] ]),
|
|
26 : (256, [ [4,2], [4,2], [3,2], [2,1] ]),
|
|
27 : (256, [ [3,2], [4,2], [4,2], [2,1] ]),
|
|
28 : (256, [ [4,2], [3,2], [4,2], [2,1] ]),
|
|
29 : (256, [ [3,2], [4,2], [4,2], [2,1] ]),
|
|
30 : (256, [ [4,2], [4,2], [4,2], [2,1] ]),
|
|
31 : (256, [ [3,2], [3,2], [3,2], [3,1] ]),
|
|
32 : (256, [ [4,2], [3,2], [3,2], [3,1] ]),
|
|
33 : (256, [ [3,2], [4,2], [3,2], [3,1] ]),
|
|
34 : (256, [ [4,2], [4,2], [3,2], [3,1] ]),
|
|
35 : (256, [ [3,2], [4,2], [4,2], [3,1] ]),
|
|
36 : (256, [ [4,2], [3,2], [4,2], [3,1] ]),
|
|
37 : (256, [ [3,2], [4,2], [4,2], [3,1] ]),
|
|
38 : (256, [ [4,2], [4,2], [4,2], [3,1] ]),
|
|
39 : (256, [ [3,2], [3,2], [3,2], [4,1] ]),
|
|
40 : (256, [ [4,2], [3,2], [3,2], [4,1] ]),
|
|
41 : (256, [ [3,2], [4,2], [3,2], [4,1] ]),
|
|
42 : (256, [ [4,2], [4,2], [3,2], [4,1] ]),
|
|
43 : (256, [ [3,2], [4,2], [4,2], [4,1] ]),
|
|
44 : (256, [ [4,2], [3,2], [4,2], [4,1] ]),
|
|
45 : (256, [ [3,2], [4,2], [4,2], [4,1] ]),
|
|
46 : (256, [ [4,2], [4,2], [4,2], [4,1] ]),
|
|
}
|
|
|
|
|
|
class PatchDiscriminator(nn.ModelBase):
|
|
def on_build(self, patch_size, in_ch, base_ch=None, conv_kernel_initializer=None):
|
|
suggested_base_ch, kernels_strides = patch_discriminator_kernels[patch_size]
|
|
|
|
if base_ch is None:
|
|
base_ch = suggested_base_ch
|
|
|
|
prev_ch = in_ch
|
|
self.convs = []
|
|
for i, (kernel_size, strides) in enumerate(kernels_strides):
|
|
cur_ch = base_ch * min( (2**i), 8 )
|
|
|
|
self.convs.append ( nn.Conv2D( prev_ch, cur_ch, kernel_size=kernel_size, strides=strides, padding='SAME', kernel_initializer=conv_kernel_initializer) )
|
|
prev_ch = cur_ch
|
|
|
|
self.out_conv = nn.Conv2D( prev_ch, 1, kernel_size=1, padding='VALID', kernel_initializer=conv_kernel_initializer)
|
|
|
|
def forward(self, x):
|
|
for conv in self.convs:
|
|
x = tf.nn.leaky_relu( conv(x), 0.1 )
|
|
return self.out_conv(x)
|
|
|
|
nn.PatchDiscriminator = PatchDiscriminator |