mirror of
https://github.com/iperov/DeepFaceLab.git
synced 2025-07-06 04:52:13 -07:00
SAEHD: added new option GAN power 0.0 .. 10.0 Train the network in Generative Adversarial manner. Forces the neural network to learn small details of the face. You can enable/disable this option at any time, but better to enable it when the network is trained enough. Typical value is 1.0 GAN power with pretrain mode will not work. Example of enabling GAN on 81k iters +5k iters https://i.imgur.com/OdXHLhU.jpg https://i.imgur.com/CYAJmJx.jpg dfhd: default Decoder dimensions are now 48 the preview for 256 res is now correctly displayed fixed model naming/renaming/removing Improvements for those involved in post-processing in AfterEffects: Codec is reverted back to x264 in order to properly use in AfterEffects and video players. Merger now always outputs the mask to workspace\data_dst\merged_mask removed raw modes except raw-rgb raw-rgb mode now outputs selected face mask_mode (before square mask) 'export alpha mask' button is replaced by 'show alpha mask'. You can view the alpha mask without recompute the frames. 8) 'merged *.bat' now also output 'result_mask.' video file. 8) 'merged lossless' now uses x264 lossless codec (before PNG codec) result_mask video file is always lossless. Thus you can use result_mask video file as mask layer in the AfterEffects.
81 lines
3 KiB
Python
81 lines
3 KiB
Python
import traceback
|
|
|
|
import cv2
|
|
import numpy as np
|
|
|
|
from core.joblib import SubprocessGenerator, ThisThreadGenerator
|
|
from samplelib import (SampleGeneratorBase, SampleLoader, SampleProcessor,
|
|
SampleType)
|
|
|
|
|
|
'''
|
|
output_sample_types = [
|
|
[SampleProcessor.TypeFlags, size, (optional)random_sub_size] ,
|
|
...
|
|
]
|
|
'''
|
|
class SampleGeneratorImageTemporal(SampleGeneratorBase):
|
|
def __init__ (self, samples_path, debug, batch_size, temporal_image_count, sample_process_options=SampleProcessor.Options(), output_sample_types=[], **kwargs):
|
|
super().__init__(samples_path, debug, batch_size)
|
|
|
|
self.temporal_image_count = temporal_image_count
|
|
self.sample_process_options = sample_process_options
|
|
self.output_sample_types = output_sample_types
|
|
|
|
self.samples = SampleLoader.load (SampleType.IMAGE, self.samples_path)
|
|
|
|
self.generator_samples = [ self.samples ]
|
|
self.generators = [iter_utils.ThisThreadGenerator ( self.batch_func, 0 )] if self.debug else \
|
|
[iter_utils.SubprocessGenerator ( self.batch_func, 0 )]
|
|
|
|
self.generator_counter = -1
|
|
|
|
def __iter__(self):
|
|
return self
|
|
|
|
def __next__(self):
|
|
self.generator_counter += 1
|
|
generator = self.generators[self.generator_counter % len(self.generators) ]
|
|
return next(generator)
|
|
|
|
def batch_func(self, generator_id):
|
|
samples = self.generator_samples[generator_id]
|
|
samples_len = len(samples)
|
|
if samples_len == 0:
|
|
raise ValueError('No training data provided.')
|
|
|
|
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.')
|
|
|
|
shuffle_idxs = []
|
|
|
|
while True:
|
|
|
|
batches = None
|
|
for n_batch in range(self.batch_size):
|
|
|
|
if len(shuffle_idxs) == 0:
|
|
shuffle_idxs = [ *range(samples_sub_len) ]
|
|
np.random.shuffle (shuffle_idxs)
|
|
|
|
idx = shuffle_idxs.pop()
|
|
|
|
temporal_samples = []
|
|
mult = np.random.randint(mult_max)+1
|
|
for i in range( self.temporal_image_count ):
|
|
sample = samples[ idx+i*mult ]
|
|
try:
|
|
temporal_samples += SampleProcessor.process ([sample], self.sample_process_options, self.output_sample_types, self.debug)[0]
|
|
except:
|
|
raise Exception ("Exception occured in sample %s. Error: %s" % (sample.filename, traceback.format_exc() ) )
|
|
|
|
if batches is None:
|
|
batches = [ [] for _ in range(len(temporal_samples)) ]
|
|
|
|
for i in range(len(temporal_samples)):
|
|
batches[i].append ( temporal_samples[i] )
|
|
|
|
yield [ np.array(batch) for batch in batches]
|