mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-07 05:22:06 -07:00
removing trailing spaces
This commit is contained in:
parent
fa4e579b95
commit
a3df04999c
61 changed files with 2110 additions and 2103 deletions
|
@ -31,4 +31,3 @@ to_string_list = [ 'half_face',
|
||||||
'avatar',
|
'avatar',
|
||||||
'mark_only'
|
'mark_only'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -194,4 +194,3 @@ def video_from_sequence( input_dir, output_file, reference_file=None, ext=None,
|
||||||
job = job.run()
|
job = job.run()
|
||||||
except:
|
except:
|
||||||
io.log_err ("ffmpeg fail, job commandline:" + str(job.compile()) )
|
io.log_err ("ffmpeg fail, job commandline:" + str(job.compile()) )
|
||||||
|
|
||||||
|
|
|
@ -124,25 +124,26 @@ class SAEModel(ModelBase):
|
||||||
target_dst_ar = [ Input ( ( bgr_shape[0] // (2**i) ,)*2 + (bgr_shape[-1],) ) for i in range(ms_count-1, -1, -1)]
|
target_dst_ar = [ Input ( ( bgr_shape[0] // (2**i) ,)*2 + (bgr_shape[-1],) ) for i in range(ms_count-1, -1, -1)]
|
||||||
target_dstm_ar = [ Input ( ( mask_shape[0] // (2**i) ,)*2 + (mask_shape[-1],) ) for i in range(ms_count-1, -1, -1)]
|
target_dstm_ar = [ Input ( ( mask_shape[0] // (2**i) ,)*2 + (mask_shape[-1],) ) for i in range(ms_count-1, -1, -1)]
|
||||||
|
|
||||||
|
use_bn = True
|
||||||
|
|
||||||
models_list = []
|
models_list = []
|
||||||
weights_to_load = []
|
weights_to_load = []
|
||||||
if self.options['archi'] == 'liae':
|
if self.options['archi'] == 'liae':
|
||||||
self.encoder = modelify(SAEModel.LIAEEncFlow(resolution, self.options['lighter_encoder'], ed_ch_dims=ed_ch_dims) ) (Input(bgr_shape))
|
self.encoder = modelify(SAEModel.LIAEEncFlow(resolution, self.options['lighter_encoder'], ed_ch_dims=ed_ch_dims, use_bn=use_bn) ) (Input(bgr_shape))
|
||||||
|
|
||||||
enc_output_Inputs = [ Input(K.int_shape(x)[1:]) for x in self.encoder.outputs ]
|
enc_output_Inputs = [ Input(K.int_shape(x)[1:]) for x in self.encoder.outputs ]
|
||||||
|
|
||||||
self.inter_B = modelify(SAEModel.LIAEInterFlow(resolution, ae_dims=ae_dims)) (enc_output_Inputs)
|
self.inter_B = modelify(SAEModel.LIAEInterFlow(resolution, ae_dims=ae_dims, use_bn=use_bn)) (enc_output_Inputs)
|
||||||
self.inter_AB = modelify(SAEModel.LIAEInterFlow(resolution, ae_dims=ae_dims)) (enc_output_Inputs)
|
self.inter_AB = modelify(SAEModel.LIAEInterFlow(resolution, ae_dims=ae_dims, use_bn=use_bn)) (enc_output_Inputs)
|
||||||
|
|
||||||
inter_output_Inputs = [ Input( np.array(K.int_shape(x)[1:])*(1,1,2) ) for x in self.inter_B.outputs ]
|
inter_output_Inputs = [ Input( np.array(K.int_shape(x)[1:])*(1,1,2) ) for x in self.inter_B.outputs ]
|
||||||
|
|
||||||
self.decoder = modelify(SAEModel.LIAEDecFlow (bgr_shape[2],ed_ch_dims=ed_ch_dims//2, multiscale_count=self.ms_count )) (inter_output_Inputs)
|
self.decoder = modelify(SAEModel.LIAEDecFlow (bgr_shape[2],ed_ch_dims=ed_ch_dims//2, multiscale_count=self.ms_count, use_bn=use_bn )) (inter_output_Inputs)
|
||||||
|
|
||||||
models_list += [self.encoder, self.inter_B, self.inter_AB, self.decoder]
|
models_list += [self.encoder, self.inter_B, self.inter_AB, self.decoder]
|
||||||
|
|
||||||
if self.options['learn_mask']:
|
if self.options['learn_mask']:
|
||||||
self.decoderm = modelify(SAEModel.LIAEDecFlow (mask_shape[2],ed_ch_dims=int(ed_ch_dims/1.5) )) (inter_output_Inputs)
|
self.decoderm = modelify(SAEModel.LIAEDecFlow (mask_shape[2],ed_ch_dims=int(ed_ch_dims/1.5), use_bn=use_bn )) (inter_output_Inputs)
|
||||||
models_list += [self.decoderm]
|
models_list += [self.decoderm]
|
||||||
|
|
||||||
if not self.is_first_run():
|
if not self.is_first_run():
|
||||||
|
@ -495,6 +496,10 @@ class SAEModel(ModelBase):
|
||||||
def initialize_nn_functions():
|
def initialize_nn_functions():
|
||||||
exec (nnlib.import_all(), locals(), globals())
|
exec (nnlib.import_all(), locals(), globals())
|
||||||
|
|
||||||
|
def BatchNorm():
|
||||||
|
return BatchNormalization(axis=-1, gamma_initializer=RandomNormal(1., 0.02) )
|
||||||
|
|
||||||
|
|
||||||
class ResidualBlock(object):
|
class ResidualBlock(object):
|
||||||
def __init__(self, filters, kernel_size=3, padding='same', use_reflection_padding=False):
|
def __init__(self, filters, kernel_size=3, padding='same', use_reflection_padding=False):
|
||||||
self.filters = filters
|
self.filters = filters
|
||||||
|
@ -521,20 +526,29 @@ class SAEModel(ModelBase):
|
||||||
return var_x
|
return var_x
|
||||||
SAEModel.ResidualBlock = ResidualBlock
|
SAEModel.ResidualBlock = ResidualBlock
|
||||||
|
|
||||||
def downscale (dim):
|
def downscale (dim, use_bn=False):
|
||||||
def func(x):
|
def func(x):
|
||||||
|
if use_bn:
|
||||||
|
return LeakyReLU(0.1)(BatchNorm()(Conv2D(dim, kernel_size=5, strides=2, padding='same', kernel_initializer=RandomNormal(0, 0.02), use_bias=False)(x)))
|
||||||
|
else:
|
||||||
return LeakyReLU(0.1)(Conv2D(dim, kernel_size=5, strides=2, padding='same', kernel_initializer=RandomNormal(0, 0.02))(x))
|
return LeakyReLU(0.1)(Conv2D(dim, kernel_size=5, strides=2, padding='same', kernel_initializer=RandomNormal(0, 0.02))(x))
|
||||||
return func
|
return func
|
||||||
SAEModel.downscale = downscale
|
SAEModel.downscale = downscale
|
||||||
|
|
||||||
def downscale_sep (dim):
|
def downscale_sep (dim, use_bn=False):
|
||||||
def func(x):
|
def func(x):
|
||||||
|
if use_bn:
|
||||||
|
return LeakyReLU(0.1)(BatchNorm()(SeparableConv2D(dim, kernel_size=5, strides=2, padding='same', depthwise_initializer=RandomNormal(0, 0.02), pointwise_initializer=RandomNormal(0, 0.02), use_bias=False )(x)))
|
||||||
|
else:
|
||||||
return LeakyReLU(0.1)(SeparableConv2D(dim, kernel_size=5, strides=2, padding='same', depthwise_initializer=RandomNormal(0, 0.02), pointwise_initializer=RandomNormal(0, 0.02) )(x))
|
return LeakyReLU(0.1)(SeparableConv2D(dim, kernel_size=5, strides=2, padding='same', depthwise_initializer=RandomNormal(0, 0.02), pointwise_initializer=RandomNormal(0, 0.02) )(x))
|
||||||
return func
|
return func
|
||||||
SAEModel.downscale_sep = downscale_sep
|
SAEModel.downscale_sep = downscale_sep
|
||||||
|
|
||||||
def upscale (dim):
|
def upscale (dim, use_bn=False):
|
||||||
def func(x):
|
def func(x):
|
||||||
|
if use_bn:
|
||||||
|
return SubpixelUpscaler()(LeakyReLU(0.1)(BatchNorm()(Conv2D(dim * 4, kernel_size=3, strides=1, padding='same', kernel_initializer=RandomNormal(0,0.02), use_bias=False )(x))))
|
||||||
|
else:
|
||||||
return SubpixelUpscaler()(LeakyReLU(0.1)(Conv2D(dim * 4, kernel_size=3, strides=1, padding='same', kernel_initializer=RandomNormal(0, 0.02) )(x)))
|
return SubpixelUpscaler()(LeakyReLU(0.1)(Conv2D(dim * 4, kernel_size=3, strides=1, padding='same', kernel_initializer=RandomNormal(0, 0.02) )(x)))
|
||||||
return func
|
return func
|
||||||
SAEModel.upscale = upscale
|
SAEModel.upscale = upscale
|
||||||
|
@ -547,7 +561,7 @@ class SAEModel(ModelBase):
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def LIAEEncFlow(resolution, light_enc, ed_ch_dims=42):
|
def LIAEEncFlow(resolution, light_enc, ed_ch_dims=42, use_bn=False):
|
||||||
exec (nnlib.import_all(), locals(), globals())
|
exec (nnlib.import_all(), locals(), globals())
|
||||||
upscale = SAEModel.upscale
|
upscale = SAEModel.upscale
|
||||||
downscale = SAEModel.downscale
|
downscale = SAEModel.downscale
|
||||||
|
@ -559,20 +573,20 @@ class SAEModel(ModelBase):
|
||||||
x = input
|
x = input
|
||||||
x = downscale(ed_dims)(x)
|
x = downscale(ed_dims)(x)
|
||||||
if not light_enc:
|
if not light_enc:
|
||||||
x = downscale(ed_dims*2)(x)
|
x = downscale(ed_dims*2, use_bn=use_bn)(x)
|
||||||
x = downscale(ed_dims*4)(x)
|
x = downscale(ed_dims*4, use_bn=use_bn)(x)
|
||||||
x = downscale(ed_dims*8)(x)
|
x = downscale(ed_dims*8, use_bn=use_bn)(x)
|
||||||
else:
|
else:
|
||||||
x = downscale_sep(ed_dims*2)(x)
|
x = downscale_sep(ed_dims*2, use_bn=use_bn)(x)
|
||||||
x = downscale(ed_dims*4)(x)
|
x = downscale(ed_dims*4, use_bn=use_bn)(x)
|
||||||
x = downscale_sep(ed_dims*8)(x)
|
x = downscale_sep(ed_dims*8, use_bn=use_bn)(x)
|
||||||
|
|
||||||
x = Flatten()(x)
|
x = Flatten()(x)
|
||||||
return x
|
return x
|
||||||
return func
|
return func
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def LIAEInterFlow(resolution, ae_dims=256):
|
def LIAEInterFlow(resolution, ae_dims=256, use_bn=False):
|
||||||
exec (nnlib.import_all(), locals(), globals())
|
exec (nnlib.import_all(), locals(), globals())
|
||||||
upscale = SAEModel.upscale
|
upscale = SAEModel.upscale
|
||||||
lowest_dense_res=resolution // 16
|
lowest_dense_res=resolution // 16
|
||||||
|
@ -582,12 +596,12 @@ class SAEModel(ModelBase):
|
||||||
x = Dense(ae_dims)(x)
|
x = Dense(ae_dims)(x)
|
||||||
x = Dense(lowest_dense_res * lowest_dense_res * ae_dims*2)(x)
|
x = Dense(lowest_dense_res * lowest_dense_res * ae_dims*2)(x)
|
||||||
x = Reshape((lowest_dense_res, lowest_dense_res, ae_dims*2))(x)
|
x = Reshape((lowest_dense_res, lowest_dense_res, ae_dims*2))(x)
|
||||||
x = upscale(ae_dims*2)(x)
|
x = upscale(ae_dims*2, use_bn=use_bn)(x)
|
||||||
return x
|
return x
|
||||||
return func
|
return func
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def LIAEDecFlow(output_nc,ed_ch_dims=21, multiscale_count=1):
|
def LIAEDecFlow(output_nc,ed_ch_dims=21, multiscale_count=1, use_bn=False):
|
||||||
exec (nnlib.import_all(), locals(), globals())
|
exec (nnlib.import_all(), locals(), globals())
|
||||||
upscale = SAEModel.upscale
|
upscale = SAEModel.upscale
|
||||||
to_bgr = SAEModel.to_bgr
|
to_bgr = SAEModel.to_bgr
|
||||||
|
@ -597,17 +611,17 @@ class SAEModel(ModelBase):
|
||||||
x = input[0]
|
x = input[0]
|
||||||
|
|
||||||
outputs = []
|
outputs = []
|
||||||
x1 = upscale(ed_dims*8)( x )
|
x1 = upscale(ed_dims*8, use_bn=use_bn)( x )
|
||||||
|
|
||||||
if multiscale_count >= 3:
|
if multiscale_count >= 3:
|
||||||
outputs += [ to_bgr(output_nc) ( x1 ) ]
|
outputs += [ to_bgr(output_nc) ( x1 ) ]
|
||||||
|
|
||||||
x2 = upscale(ed_dims*4)( x1 )
|
x2 = upscale(ed_dims*4, use_bn=use_bn)( x1 )
|
||||||
|
|
||||||
if multiscale_count >= 2:
|
if multiscale_count >= 2:
|
||||||
outputs += [ to_bgr(output_nc) ( x2 ) ]
|
outputs += [ to_bgr(output_nc) ( x2 ) ]
|
||||||
|
|
||||||
x3 = upscale(ed_dims*2)( x2 )
|
x3 = upscale(ed_dims*2, use_bn=use_bn)( x2 )
|
||||||
|
|
||||||
outputs += [ to_bgr(output_nc) ( x3 ) ]
|
outputs += [ to_bgr(output_nc) ( x3 ) ]
|
||||||
|
|
||||||
|
|
|
@ -348,4 +348,3 @@ if device.backend is None:
|
||||||
else:
|
else:
|
||||||
#has NVSMI, no capable CUDA-devices, also plaidML was failed, then CPU only
|
#has NVSMI, no capable CUDA-devices, also plaidML was failed, then CPU only
|
||||||
device.backend = "tensorflow-cpu"
|
device.backend = "tensorflow-cpu"
|
||||||
|
|
||||||
|
|
|
@ -541,7 +541,6 @@ NLayerDiscriminator = nnlib.NLayerDiscriminator
|
||||||
result = CAInitializerMPSubprocessor ( [ (i, K.int_shape(conv_weights)) for i, conv_weights in enumerate(conv_weights_list) ], K.floatx(), K.image_data_format() ).run()
|
result = CAInitializerMPSubprocessor ( [ (i, K.int_shape(conv_weights)) for i, conv_weights in enumerate(conv_weights_list) ], K.floatx(), K.image_data_format() ).run()
|
||||||
for idx, weights in result:
|
for idx, weights in result:
|
||||||
K.set_value ( conv_weights_list[idx], weights )
|
K.set_value ( conv_weights_list[idx], weights )
|
||||||
|
|
||||||
nnlib.CAInitializerMP = CAInitializerMP
|
nnlib.CAInitializerMP = CAInitializerMP
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,4 +22,3 @@ class SampleGeneratorBase(object):
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
#implement your own iterator
|
#implement your own iterator
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -422,4 +422,3 @@ def reduce_colors (img_bgr, n_colors):
|
||||||
img_bgr = cv2.cvtColor( np.array(img_rgb_p, dtype=np.float32) / 255.0, cv2.COLOR_RGB2BGR )
|
img_bgr = cv2.cvtColor( np.array(img_rgb_p, dtype=np.float32) / 255.0, cv2.COLOR_RGB2BGR )
|
||||||
|
|
||||||
return img_bgr
|
return img_bgr
|
||||||
|
|
|
@ -3,4 +3,3 @@ import struct
|
||||||
def struct_unpack(data, counter, fmt):
|
def struct_unpack(data, counter, fmt):
|
||||||
fmt_size = struct.calcsize(fmt)
|
fmt_size = struct.calcsize(fmt)
|
||||||
return (counter+fmt_size,) + struct.unpack (fmt, data[counter:counter+fmt_size])
|
return (counter+fmt_size,) + struct.unpack (fmt, data[counter:counter+fmt_size])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue