diff --git a/CHANGELOG.md b/CHANGELOG.md index a4783e5..889cce3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - [Freezeable layers (encoder/decoder/etc.)](https://github.com/faceshiftlabs/DeepFaceLab/tree/feature/freezable-weights) - [GAN stability improvements](https://github.com/faceshiftlabs/DeepFaceLab/tree/feature/gan-updates) +## [1.3.0] - 2020-03-20 +### Added +- [Background Power training option](doc/features/background-power/README.md) + ## [1.2.1] - 2020-03-20 ### Fixed - Fixes bug with `fs-aug` color mode. @@ -49,7 +53,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Reset stale master branch to [seranus/DeepFaceLab](https://github.com/seranus/DeepFaceLab), 21 commits ahead of [iperov/DeepFaceLab](https://github.com/iperov/DeepFaceLab) ([compare](https://github.com/iperov/DeepFaceLab/compare/4818183...seranus:3f5ae05)) -[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.2.1...HEAD +[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.3.0...HEAD +[1.3.0]: https://github.com/faceshiftlabs/DeepFaceLab/compare/v1.2.1...v1.3.0 [1.2.1]: https://github.com/faceshiftlabs/DeepFaceLab/compare/v1.2.0...v1.2.1 [1.2.0]: https://github.com/faceshiftlabs/DeepFaceLab/compare/v1.1.5...v1.2.0 [1.1.5]: https://github.com/faceshiftlabs/DeepFaceLab/compare/v1.1.4...v1.1.5 diff --git a/doc/features/background-power/README.md b/doc/features/background-power/README.md new file mode 100644 index 0000000..0c83e52 --- /dev/null +++ b/doc/features/background-power/README.md @@ -0,0 +1,32 @@ +# Background Power option + +Allows you to train the model to include the background, which may help with areas around the mask. +Unlike **Background Style Power**, this does not use any additional VRAM, and does not require lowering the batch size. + +- [DESCRIPTION](#description) +- [USAGE](#usage) +- [DIFFERENCE WITH BACKGROUND STYLE POWER](#difference-with-background-style-power) + +*Examples trained with background power `0.3`:* + +![](example.jpeg)![](example2.jpeg) + +## DESCRIPTION + +Applies the same loss calculation used for the area *inside* the mask, to the area *outside* the mask, multiplied with +the chosen background power value. + +E.g. (simplified): Source Loss = Masked area image difference + Background Power * Non-masked area image difference + +## USAGE + +`[0.0] Background power ( 0.0..1.0 ?:help ) : 0.3` + +## DIFFERENCE WITH BACKGROUND STYLE POWER + +**Background Style Power** applies a loss to the source by comparing the background of the dest to that of the +predicted src/dest (5th column). This operation requires additional VRAM, due to the face that the predicted src/dest +outputs are not normally used in training (other then being viewable in the preview window). + +**Background Power** does *not* use the src/dest images whatsoever, instead comparing the background of the predicted +source to that of the original source, and the same for the background of the dest images. diff --git a/doc/features/background-power/example.jpeg b/doc/features/background-power/example.jpeg new file mode 100644 index 0000000..004d149 Binary files /dev/null and b/doc/features/background-power/example.jpeg differ diff --git a/doc/features/background-power/example2.jpeg b/doc/features/background-power/example2.jpeg new file mode 100644 index 0000000..7d00de9 Binary files /dev/null and b/doc/features/background-power/example2.jpeg differ diff --git a/models/Model_SAEHD/Model.py b/models/Model_SAEHD/Model.py index 6ffa9d7..476d0f0 100644 --- a/models/Model_SAEHD/Model.py +++ b/models/Model_SAEHD/Model.py @@ -54,6 +54,7 @@ class SAEHDModel(ModelBase): default_lr_dropout = self.options['lr_dropout'] = lr_dropout default_random_warp = self.options['random_warp'] = self.load_or_def_option('random_warp', True) + default_background_power = self.options['background_power'] = self.load_or_def_option('background_power', 0.0) default_true_face_power = self.options['true_face_power'] = self.load_or_def_option('true_face_power', 0.0) default_face_style_power = self.options['face_style_power'] = self.load_or_def_option('face_style_power', 0.0) default_bg_style_power = self.options['bg_style_power'] = self.load_or_def_option('bg_style_power', 0.0) @@ -164,6 +165,8 @@ Examples: df, liae, df-d, df-ud, liae-ud, ... else: self.options['true_face_power'] = 0.0 + self.options['background_power'] = np.clip ( io.input_number("Background power", default_background_power, add_info="0.0..1.0", help_message="Learn the area outside of the mask. Helps smooth out area near the mask boundaries. Can be used at any time"), 0.0, 1.0 ) + self.options['face_style_power'] = np.clip ( io.input_number("Face style power", default_face_style_power, add_info="0.0..100.0", help_message="Learn the color of the predicted face to be the same as dst inside mask. If you want to use this option with 'whole_face' you have to use XSeg trained mask. Warning: Enable it only after 10k iters, when predicted face is clear enough to start learn style. Start from 0.001 value and check history changes. Enabling this option increases the chance of model collapse."), 0.0, 100.0 ) self.options['bg_style_power'] = np.clip ( io.input_number("Background style power", default_bg_style_power, add_info="0.0..100.0", help_message="Learn the area outside mask of the predicted face to be the same as dst. If you want to use this option with 'whole_face' you have to use XSeg trained mask. For whole_face you have to use XSeg trained mask. This can make face more like dst. Enabling this option increases the chance of model collapse. Typical value is 2.0"), 0.0, 100.0 ) @@ -413,12 +416,15 @@ Examples: df, liae, df-d, df-ud, liae-ud, ... gpu_target_dst_style_anti_masked = gpu_target_dst*(1.0 - gpu_target_dstm_style_blur) gpu_target_src_anti_masked = gpu_target_src*(1.0-gpu_target_srcm_blur) + gpu_target_dst_anti_masked = gpu_target_dst_style_anti_masked + gpu_target_src_masked_opt = gpu_target_src*gpu_target_srcm_blur if masked_training else gpu_target_src gpu_target_dst_masked_opt = gpu_target_dst_masked if masked_training else gpu_target_dst gpu_pred_src_src_masked_opt = gpu_pred_src_src*gpu_target_srcm_blur if masked_training else gpu_pred_src_src gpu_pred_src_src_anti_masked = gpu_pred_src_src*(1.0-gpu_target_srcm_blur) gpu_pred_dst_dst_masked_opt = gpu_pred_dst_dst*gpu_target_dstm_blur if masked_training else gpu_pred_dst_dst + gpu_pred_dst_dst_anti_masked = gpu_pred_dst_dst*(1.0-gpu_target_dstm_blur) gpu_psd_target_dst_style_masked = gpu_pred_src_dst*gpu_target_dstm_style_blur gpu_psd_target_dst_style_anti_masked = gpu_pred_src_dst*(1.0 - gpu_target_dstm_style_blur) @@ -442,6 +448,15 @@ Examples: df, liae, df-d, df-ud, liae-ud, ... gpu_src_loss += tf.reduce_mean ( 10*tf.square( gpu_target_srcm - gpu_pred_src_srcm ),axis=[1,2,3] ) + if self.options['background_power'] > 0: + bg_factor = self.options['background_power'] + if resolution < 256: + gpu_src_loss += bg_factor * tf.reduce_mean ( 10*nn.dssim(gpu_target_src_anti_masked, gpu_pred_src_src_anti_masked, max_val=1.0, filter_size=int(resolution/11.6)), axis=[1]) + else: + gpu_src_loss += bg_factor * tf.reduce_mean ( 5*nn.dssim(gpu_target_src_anti_masked, gpu_pred_src_src_anti_masked, max_val=1.0, filter_size=int(resolution/11.6)), axis=[1]) + gpu_src_loss += bg_factor * tf.reduce_mean ( 5*nn.dssim(gpu_target_src_anti_masked, gpu_pred_src_src_anti_masked, max_val=1.0, filter_size=int(resolution/23.2)), axis=[1]) + gpu_src_loss += bg_factor * tf.reduce_mean ( 10*tf.square ( gpu_target_src_anti_masked - gpu_pred_src_src_anti_masked ), axis=[1,2,3]) + face_style_power = self.options['face_style_power'] / 100.0 if face_style_power != 0 and not self.pretrain: gpu_src_loss += nn.style_loss(gpu_psd_target_dst_style_masked, gpu_target_dst_style_masked, gaussian_blur_radius=resolution//16, loss_weight=10000*face_style_power) @@ -469,6 +484,15 @@ Examples: df, liae, df-d, df-ud, liae-ud, ... gpu_dst_loss += tf.reduce_mean ( 300*tf.abs ( gpu_target_dst*gpu_target_part_mask - gpu_pred_dst_dst*gpu_target_part_mask ), axis=[1,2,3]) + if self.options['background_power'] > 0: + bg_factor = self.options['background_power'] + if resolution < 256: + gpu_dst_loss += bg_factor * tf.reduce_mean ( 10*nn.dssim(gpu_target_dst_anti_masked, gpu_pred_dst_dst_anti_masked, max_val=1.0, filter_size=int(resolution/11.6)), axis=[1]) + else: + gpu_dst_loss += bg_factor * tf.reduce_mean ( 5*nn.dssim(gpu_target_dst_anti_masked, gpu_pred_dst_dst_anti_masked, max_val=1.0, filter_size=int(resolution/11.6)), axis=[1]) + gpu_dst_loss += bg_factor * tf.reduce_mean ( 5*nn.dssim(gpu_target_dst_anti_masked, gpu_pred_dst_dst_anti_masked, max_val=1.0, filter_size=int(resolution/23.2)), axis=[1]) + gpu_dst_loss += bg_factor * tf.reduce_mean ( 10*tf.square ( gpu_target_dst_anti_masked - gpu_pred_dst_dst_anti_masked ), axis=[1,2,3]) + gpu_dst_loss += tf.reduce_mean ( 10*tf.square( gpu_target_dstm - gpu_pred_dst_dstm ),axis=[1,2,3] ) gpu_src_losses += [gpu_src_loss]