mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-08-14 02:37:00 -07:00
Upgraded to TF version 1.13.2
Removed the wait at first launch for most graphics cards. Increased speed of training by 10-20%, but you have to retrain all models from scratch. SAEHD: added option 'use float16' Experimental option. Reduces the model size by half. Increases the speed of training. Decreases the accuracy of the model. The model may collapse or not train. Model may not learn the mask in large resolutions. true_face_training option is replaced by "True face power". 0.0000 .. 1.0 Experimental option. Discriminates the result face to be more like the src face. Higher value - stronger discrimination. Comparison - https://i.imgur.com/czScS9q.png
This commit is contained in:
parent
a3dfcb91b9
commit
76ca79216e
49 changed files with 1320 additions and 1297 deletions
|
@ -136,7 +136,7 @@ class PackedFaceset():
|
|||
samples_configs = pickle.loads ( f.read(sizeof_samples_bytes) )
|
||||
samples = []
|
||||
for sample_config in samples_configs:
|
||||
sample_config = pickle.loads(pickle.dumps (sample_config))
|
||||
sample_config = pickle.loads(pickle.dumps (sample_config))
|
||||
samples.append ( Sample (**sample_config) )
|
||||
|
||||
offsets = [ struct.unpack("Q", f.read(8) )[0] for _ in range(len(samples)+1) ]
|
||||
|
|
|
@ -31,7 +31,7 @@ class Sample(object):
|
|||
'source_filename',
|
||||
'person_name',
|
||||
'pitch_yaw_roll',
|
||||
'_filename_offset_size',
|
||||
'_filename_offset_size',
|
||||
]
|
||||
|
||||
def __init__(self, sample_type=None,
|
||||
|
@ -39,10 +39,10 @@ class Sample(object):
|
|||
face_type=None,
|
||||
shape=None,
|
||||
landmarks=None,
|
||||
ie_polys=None,
|
||||
ie_polys=None,
|
||||
eyebrows_expand_mod=None,
|
||||
source_filename=None,
|
||||
person_name=None,
|
||||
person_name=None,
|
||||
pitch_yaw_roll=None,
|
||||
**kwargs):
|
||||
|
||||
|
@ -55,15 +55,15 @@ class Sample(object):
|
|||
self.eyebrows_expand_mod = eyebrows_expand_mod
|
||||
self.source_filename = source_filename
|
||||
self.person_name = person_name
|
||||
self.pitch_yaw_roll = pitch_yaw_roll
|
||||
|
||||
self.pitch_yaw_roll = pitch_yaw_roll
|
||||
|
||||
self._filename_offset_size = None
|
||||
|
||||
|
||||
def get_pitch_yaw_roll(self):
|
||||
if self.pitch_yaw_roll is None:
|
||||
self.pitch_yaw_roll = LandmarksProcessor.estimate_pitch_yaw_roll(landmarks)
|
||||
return self.pitch_yaw_roll
|
||||
|
||||
|
||||
def set_filename_offset_size(self, filename, offset, size):
|
||||
self._filename_offset_size = (filename, offset, size)
|
||||
|
||||
|
|
|
@ -14,11 +14,11 @@ from samplelib import (SampleGeneratorBase, SampleHost, SampleProcessor,
|
|||
|
||||
|
||||
class SampleGeneratorFaceTemporal(SampleGeneratorBase):
|
||||
def __init__ (self, samples_path, debug, batch_size,
|
||||
temporal_image_count=3,
|
||||
sample_process_options=SampleProcessor.Options(),
|
||||
output_sample_types=[],
|
||||
generators_count=2,
|
||||
def __init__ (self, samples_path, debug, batch_size,
|
||||
temporal_image_count=3,
|
||||
sample_process_options=SampleProcessor.Options(),
|
||||
output_sample_types=[],
|
||||
generators_count=2,
|
||||
**kwargs):
|
||||
super().__init__(samples_path, debug, batch_size)
|
||||
|
||||
|
@ -35,11 +35,11 @@ class SampleGeneratorFaceTemporal(SampleGeneratorBase):
|
|||
samples_len = len(samples)
|
||||
if samples_len == 0:
|
||||
raise ValueError('No training data provided.')
|
||||
|
||||
|
||||
mult_max = 1
|
||||
l = samples_len - ( (self.temporal_image_count)*mult_max - (mult_max-1) )
|
||||
index_host = mplib.IndexHost(l+1)
|
||||
|
||||
|
||||
pickled_samples = pickle.dumps(samples, 4)
|
||||
if self.debug:
|
||||
self.generators = [ThisThreadGenerator ( self.batch_func, (pickled_samples, index_host.create_cli(),) )]
|
||||
|
@ -64,9 +64,9 @@ class SampleGeneratorFaceTemporal(SampleGeneratorBase):
|
|||
|
||||
while True:
|
||||
batches = None
|
||||
|
||||
|
||||
indexes = index_host.multi_get(bs)
|
||||
|
||||
|
||||
for n_batch in range(self.batch_size):
|
||||
idx = indexes[n_batch]
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class SampleGeneratorImageTemporal(SampleGeneratorBase):
|
|||
|
||||
mult_max = 4
|
||||
samples_sub_len = samples_len - ( (self.temporal_image_count)*mult_max - (mult_max-1) )
|
||||
|
||||
|
||||
if samples_sub_len <= 0:
|
||||
raise ValueError('Not enough samples to fit temporal line.')
|
||||
|
||||
|
|
|
@ -15,10 +15,6 @@ from .Sample import Sample, SampleType
|
|||
|
||||
|
||||
class SampleHost:
|
||||
|
||||
|
||||
|
||||
|
||||
samples_cache = dict()
|
||||
@staticmethod
|
||||
def get_person_id_max_count(samples_path):
|
||||
|
@ -47,7 +43,7 @@ class SampleHost:
|
|||
if sample_type == SampleType.IMAGE:
|
||||
if samples[sample_type] is None:
|
||||
samples[sample_type] = [ Sample(filename=filename) for filename in io.progress_bar_generator( pathex.get_image_paths(samples_path), "Loading") ]
|
||||
|
||||
|
||||
elif sample_type == SampleType.FACE:
|
||||
if samples[sample_type] is None:
|
||||
try:
|
||||
|
@ -61,12 +57,12 @@ class SampleHost:
|
|||
if result is None:
|
||||
result = SampleHost.load_face_samples( pathex.get_image_paths(samples_path) )
|
||||
samples[sample_type] = result
|
||||
|
||||
|
||||
elif sample_type == SampleType.FACE_TEMPORAL_SORTED:
|
||||
result = SampleHost.load (SampleType.FACE, samples_path)
|
||||
result = SampleHost.upgradeToFaceTemporalSortedSamples(result)
|
||||
samples[sample_type] = result
|
||||
|
||||
|
||||
return samples[sample_type]
|
||||
|
||||
@staticmethod
|
||||
|
@ -92,17 +88,17 @@ class SampleHost:
|
|||
source_filename=source_filename,
|
||||
))
|
||||
return sample_list
|
||||
|
||||
|
||||
"""
|
||||
@staticmethod
|
||||
def load_face_samples ( image_paths):
|
||||
sample_list = []
|
||||
|
||||
|
||||
for filename in io.progress_bar_generator (image_paths, desc="Loading"):
|
||||
dflimg = DFLIMG.load (Path(filename))
|
||||
dflimg = DFLIMG.load (Path(filename))
|
||||
if dflimg is None:
|
||||
io.log_err (f"{filename} is not a dfl image file.")
|
||||
else:
|
||||
else:
|
||||
sample_list.append( Sample(filename=filename,
|
||||
sample_type=SampleType.FACE,
|
||||
face_type=FaceType.fromString ( dflimg.get_face_type() ),
|
||||
|
@ -114,15 +110,15 @@ class SampleHost:
|
|||
))
|
||||
return sample_list
|
||||
"""
|
||||
|
||||
|
||||
@staticmethod
|
||||
def upgradeToFaceTemporalSortedSamples( samples ):
|
||||
new_s = [ (s, s.source_filename) for s in samples]
|
||||
new_s = sorted(new_s, key=operator.itemgetter(1))
|
||||
|
||||
return [ s[0] for s in new_s]
|
||||
|
||||
|
||||
|
||||
|
||||
class FaceSamplesLoaderSubprocessor(Subprocessor):
|
||||
#override
|
||||
def __init__(self, image_paths ):
|
||||
|
|
|
@ -37,7 +37,7 @@ opts:
|
|||
|
||||
'resolution' : N
|
||||
'motion_blur' : (chance_int, range) - chance 0..100 to apply to face (not mask), and max_size of motion blur
|
||||
'ct_mode' :
|
||||
'ct_mode' :
|
||||
'normalize_tanh' : bool
|
||||
|
||||
"""
|
||||
|
@ -94,11 +94,11 @@ class SampleProcessor(object):
|
|||
@staticmethod
|
||||
def process (samples, sample_process_options, output_sample_types, debug, ct_sample=None):
|
||||
SPTF = SampleProcessor.Types
|
||||
|
||||
|
||||
sample_rnd_seed = np.random.randint(0x80000000)
|
||||
|
||||
|
||||
outputs = []
|
||||
for sample in samples:
|
||||
for sample in samples:
|
||||
sample_bgr = sample.load_bgr()
|
||||
ct_sample_bgr = None
|
||||
ct_sample_mask = None
|
||||
|
@ -123,9 +123,11 @@ class SampleProcessor(object):
|
|||
normalize_vgg = opts.get('normalize_vgg', False)
|
||||
motion_blur = opts.get('motion_blur', None)
|
||||
gaussian_blur = opts.get('gaussian_blur', None)
|
||||
|
||||
|
||||
ct_mode = opts.get('ct_mode', 'None')
|
||||
normalize_tanh = opts.get('normalize_tanh', False)
|
||||
data_format = opts.get('data_format', 'NHWC')
|
||||
|
||||
|
||||
img_type = SPTF.NONE
|
||||
target_face_type = SPTF.NONE
|
||||
|
@ -149,7 +151,7 @@ class SampleProcessor(object):
|
|||
img = l
|
||||
elif img_type == SPTF.IMG_PITCH_YAW_ROLL or img_type == SPTF.IMG_PITCH_YAW_ROLL_SIGMOID:
|
||||
pitch_yaw_roll = sample.get_pitch_yaw_roll()
|
||||
|
||||
|
||||
if params['flip']:
|
||||
yaw = -yaw
|
||||
|
||||
|
@ -174,7 +176,7 @@ class SampleProcessor(object):
|
|||
if len(mask.shape) == 2:
|
||||
mask = mask[...,np.newaxis]
|
||||
|
||||
|
||||
|
||||
return img, mask
|
||||
|
||||
img = sample_bgr
|
||||
|
@ -202,7 +204,7 @@ class SampleProcessor(object):
|
|||
if gaussian_blur is not None:
|
||||
chance, kernel_max_size = gaussian_blur
|
||||
chance = np.clip(chance, 0, 100)
|
||||
|
||||
|
||||
if np.random.randint(100) < chance:
|
||||
img = cv2.GaussianBlur(img, ( np.random.randint( kernel_max_size )*2+1 ,) *2 , 0)
|
||||
|
||||
|
@ -221,7 +223,7 @@ class SampleProcessor(object):
|
|||
img = cv2.resize( img, (resolution,resolution), cv2.INTER_CUBIC )
|
||||
else:
|
||||
img, mask = do_transform (img, mask)
|
||||
|
||||
|
||||
mat = LandmarksProcessor.get_transform_mat (sample.landmarks, resolution, target_ft)
|
||||
img = cv2.warpAffine( img, mat, (resolution,resolution), borderMode=(cv2.BORDER_REPLICATE if border_replicate else cv2.BORDER_CONSTANT), flags=cv2.INTER_CUBIC )
|
||||
mask = cv2.warpAffine( mask, mat, (resolution,resolution), borderMode=cv2.BORDER_CONSTANT, flags=cv2.INTER_CUBIC )
|
||||
|
@ -256,7 +258,7 @@ class SampleProcessor(object):
|
|||
img_bgr = imagelib.reinhard_color_transfer ( np.clip( (img_bgr*255).astype(np.uint8), 0, 255),
|
||||
np.clip( (ct_sample_bgr_resized*255).astype(np.uint8), 0, 255) )
|
||||
img_bgr = np.clip( img_bgr.astype(np.float32) / 255.0, 0.0, 1.0)
|
||||
elif ct_mode == 'mkl':
|
||||
elif ct_mode == 'mkl':
|
||||
img_bgr = imagelib.color_transfer_mkl (img_bgr, ct_sample_bgr_resized)
|
||||
elif ct_mode == 'idt':
|
||||
img_bgr = imagelib.color_transfer_idt (img_bgr, ct_sample_bgr_resized)
|
||||
|
@ -271,21 +273,21 @@ class SampleProcessor(object):
|
|||
img_bgr[:,:,0] -= 103.939
|
||||
img_bgr[:,:,1] -= 116.779
|
||||
img_bgr[:,:,2] -= 123.68
|
||||
|
||||
|
||||
if mode_type == SPTF.MODE_BGR:
|
||||
img = img_bgr
|
||||
elif mode_type == SPTF.MODE_BGR_SHUFFLE:
|
||||
rnd_state = np.random.RandomState (sample_rnd_seed)
|
||||
img = np.take (img_bgr, rnd_state.permutation(img_bgr.shape[-1]), axis=-1)
|
||||
|
||||
|
||||
elif mode_type == SPTF.MODE_BGR_RANDOM_HSV_SHIFT:
|
||||
rnd_state = np.random.RandomState (sample_rnd_seed)
|
||||
hsv = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2HSV)
|
||||
h, s, v = cv2.split(hsv)
|
||||
h, s, v = cv2.split(hsv)
|
||||
h = (h + rnd_state.randint(360) ) % 360
|
||||
s = np.clip ( s + rnd_state.random()-0.5, 0, 1 )
|
||||
v = np.clip ( v + rnd_state.random()-0.5, 0, 1 )
|
||||
hsv = cv2.merge([h, s, v])
|
||||
hsv = cv2.merge([h, s, v])
|
||||
img = np.clip( cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) , 0, 1 )
|
||||
elif mode_type == SPTF.MODE_G:
|
||||
img = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)[...,None]
|
||||
|
@ -300,9 +302,13 @@ class SampleProcessor(object):
|
|||
else:
|
||||
img = np.clip (img, 0.0, 1.0)
|
||||
|
||||
if data_format == "NCHW":
|
||||
img = np.transpose(img, (2,0,1) )
|
||||
|
||||
|
||||
outputs_sample.append ( img )
|
||||
outputs += [outputs_sample]
|
||||
|
||||
|
||||
return outputs
|
||||
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue