From e15f846d086fa782932caa499c09747373c06be3 Mon Sep 17 00:00:00 2001 From: Colombo Date: Thu, 10 Oct 2019 22:56:57 +0400 Subject: [PATCH] SAE, SAEHD: random flip and learn mask options now can be overridden --- models/ModelBase.py | 7 ++++--- models/Model_SAE/Model.py | 8 ++++++-- models/Model_SAEHD/Model.py | 11 +++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/models/ModelBase.py b/models/ModelBase.py index ef27065..5c3dbae 100644 --- a/models/ModelBase.py +++ b/models/ModelBase.py @@ -123,10 +123,11 @@ class ModelBase(object): self.options['sort_by_yaw'] = self.options.get('sort_by_yaw', False) if ask_random_flip: - if (self.iter == 0): - self.options['random_flip'] = io.input_bool("Flip faces randomly? (y/n ?:help skip:y) : ", True, help_message="Predicted face will look more naturally without this option, but src faceset should cover all face directions as dst faceset.") + default_random_flip = self.options.get('random_flip', True) + if (self.iter == 0 or ask_override): + self.options['random_flip'] = io.input_bool(f"Flip faces randomly? (y/n ?:help skip:{yn_str[default_random_flip]}) : ", True, help_message="Predicted face will look more naturally without this option, but src faceset should cover all face directions as dst faceset.") else: - self.options['random_flip'] = self.options.get('random_flip', True) + self.options['random_flip'] = self.options.get('random_flip', default_random_flip) if ask_src_scale_mod: if (self.iter == 0): diff --git a/models/Model_SAE/Model.py b/models/Model_SAE/Model.py index ad3e1b3..ea8a3bd 100644 --- a/models/Model_SAE/Model.py +++ b/models/Model_SAE/Model.py @@ -20,7 +20,7 @@ class SAEModel(ModelBase): default_resolution = 128 default_archi = 'df' default_face_type = 'f' - default_learn_mask = True + if is_first_run: resolution = io.input_int("Resolution ( 64-256 ?:help skip:128) : ", default_resolution, help_message="More resolution requires more VRAM and time to train. Value will be adjusted to multiple of 16.") @@ -30,10 +30,14 @@ class SAEModel(ModelBase): self.options['resolution'] = resolution self.options['face_type'] = io.input_str ("Half or Full face? (h/f, ?:help skip:f) : ", default_face_type, ['h','f'], help_message="Half face has better resolution, but covers less area of cheeks.").lower() - self.options['learn_mask'] = io.input_bool ( f"Learn mask? (y/n, ?:help skip:{yn_str[default_learn_mask]} ) : " , default_learn_mask, help_message="Learning mask can help model to recognize face directions. Learn without mask can reduce model size, in this case converter forced to use 'not predicted mask' that is not smooth as predicted. Model with style values can be learned without mask and produce same quality result.") else: self.options['resolution'] = self.options.get('resolution', default_resolution) self.options['face_type'] = self.options.get('face_type', default_face_type) + + default_learn_mask = self.options.get('learn_mask', True) + if is_first_run or ask_override: + self.options['learn_mask'] = io.input_bool ( f"Learn mask? (y/n, ?:help skip:{yn_str[default_learn_mask]} ) : " , default_learn_mask, help_message="Learning mask can help model to recognize face directions. Learn without mask can reduce model size, in this case converter forced to use 'not predicted mask' that is not smooth as predicted. Model with style values can be learned without mask and produce same quality result.") + else: self.options['learn_mask'] = self.options.get('learn_mask', default_learn_mask) if (is_first_run or ask_override) and 'tensorflow' in self.device_config.backend: diff --git a/models/Model_SAEHD/Model.py b/models/Model_SAEHD/Model.py index 7d2b21f..f7c6934 100644 --- a/models/Model_SAEHD/Model.py +++ b/models/Model_SAEHD/Model.py @@ -20,7 +20,7 @@ class SAEv2Model(ModelBase): default_resolution = 128 default_archi = 'df' default_face_type = 'f' - default_learn_mask = True + if is_first_run: resolution = io.input_int("Resolution ( 64-256 ?:help skip:128) : ", default_resolution, help_message="More resolution requires more VRAM and time to train. Value will be adjusted to multiple of 16.") @@ -28,14 +28,17 @@ class SAEv2Model(ModelBase): while np.modf(resolution / 16)[0] != 0.0: resolution -= 1 self.options['resolution'] = resolution - self.options['face_type'] = io.input_str ("Half, mid full, or full face? (h/mf/f, ?:help skip:f) : ", default_face_type, ['h','mf','f'], help_message="Half face has better resolution, but covers less area of cheeks. Mid face is 30% wider than half face.").lower() - self.options['learn_mask'] = io.input_bool ( f"Learn mask? (y/n, ?:help skip:{yn_str[default_learn_mask]} ) : " , default_learn_mask, help_message="Learning mask can help model to recognize face directions. Learn without mask can reduce model size, in this case converter forced to use 'not predicted mask' that is not smooth as predicted.") else: self.options['resolution'] = self.options.get('resolution', default_resolution) self.options['face_type'] = self.options.get('face_type', default_face_type) - self.options['learn_mask'] = self.options.get('learn_mask', default_learn_mask) + default_learn_mask = self.options.get('learn_mask', True) + if is_first_run or ask_override: + self.options['learn_mask'] = io.input_bool ( f"Learn mask? (y/n, ?:help skip:{yn_str[default_learn_mask]} ) : " , default_learn_mask, help_message="Learning mask can help model to recognize face directions. Learn without mask can reduce model size, in this case converter forced to use 'not predicted mask' that is not smooth as predicted.") + else: + self.options['learn_mask'] = self.options.get('learn_mask', default_learn_mask) + if (is_first_run or ask_override) and 'tensorflow' in self.device_config.backend: def_optimizer_mode = self.options.get('optimizer_mode', 1) self.options['optimizer_mode'] = io.input_int ("Optimizer mode? ( 1,2,3 ?:help skip:%d) : " % (def_optimizer_mode), def_optimizer_mode, help_message="1 - no changes. 2 - allows you to train x2 bigger network consuming RAM. 3 - allows you to train x3 bigger network consuming huge amount of RAM and slower, depends on CPU power.")