"Enable autobackup" option is replaced by

"Autobackup every N hour" 0..24 (default 0 disabled), Autobackup model files with preview every N hour
This commit is contained in:
Colombo 2020-02-02 20:53:18 +04:00
parent ee27bb0aac
commit 5620763ccf
3 changed files with 21 additions and 15 deletions

View file

@ -165,7 +165,7 @@ class ModelBase(object):
# save as default options only for first run model initialize # save as default options only for first run model initialize
self.default_options_path.write_bytes( pickle.dumps (self.options) ) self.default_options_path.write_bytes( pickle.dumps (self.options) )
self.autobackup = self.options.get('autobackup', False) self.autobackup_hour = self.options.get('autobackup_hour', 0)
self.write_preview_history = self.options.get('write_preview_history', False) self.write_preview_history = self.options.get('write_preview_history', False)
self.target_iter = self.options.get('target_iter',0) self.target_iter = self.options.get('target_iter',0)
self.random_flip = self.options.get('random_flip',True) self.random_flip = self.options.get('random_flip',True)
@ -179,8 +179,8 @@ class ModelBase(object):
self.preview_history_path = self.saved_models_path / ( f'{self.get_model_name()}_history' ) self.preview_history_path = self.saved_models_path / ( f'{self.get_model_name()}_history' )
self.autobackups_path = self.saved_models_path / ( f'{self.get_model_name()}_autobackups' ) self.autobackups_path = self.saved_models_path / ( f'{self.get_model_name()}_autobackups' )
if self.autobackup: if self.autobackup_hour != 0:
self.autobackup_current_hour = time.localtime().tm_hour self.autobackup_start_hour = int(time.time() // 3600)
if not self.autobackups_path.exists(): if not self.autobackups_path.exists():
self.autobackups_path.mkdir(exist_ok=True) self.autobackups_path.mkdir(exist_ok=True)
@ -256,9 +256,9 @@ class ModelBase(object):
def ask_override(self): def ask_override(self):
return self.is_training and self.iter != 0 and io.input_in_time ("Press enter in 2 seconds to override model settings.", 5 if io.is_colab() else 2 ) return self.is_training and self.iter != 0 and io.input_in_time ("Press enter in 2 seconds to override model settings.", 5 if io.is_colab() else 2 )
def ask_enable_autobackup(self): def ask_autobackup_hour(self):
default_autobackup = self.options['autobackup'] = self.load_or_def_option('autobackup', False) default_autobackup_hour = self.options['autobackup_hour'] = self.load_or_def_option('autobackup_hour', 0)
self.options['autobackup'] = io.input_bool(f"Enable autobackup", default_autobackup, help_message="Autobackup model files with preview every hour for last 15 hours. Latest backup located in model/<>_autobackups/01") self.options['autobackup_hour'] = io.input_int(f"Autobackup every N hour", default_autobackup_hour, add_info="0..24", help_message="Autobackup model files with preview every N hour. Latest backup located in model/<>_autobackups/01")
def ask_write_preview_history(self): def ask_write_preview_history(self):
default_write_preview_history = self.load_or_def_option('write_preview_history', False) default_write_preview_history = self.load_or_def_option('write_preview_history', False)
@ -358,10 +358,11 @@ class ModelBase(object):
} }
pathex.write_bytes_safe (self.model_data_path, pickle.dumps(model_data) ) pathex.write_bytes_safe (self.model_data_path, pickle.dumps(model_data) )
if self.autobackup: if self.autobackup_hour != 0:
current_hour = time.localtime().tm_hour current_hour = int(time.time() // 3600)
if self.autobackup_current_hour != current_hour: diff_hour = self.autobackup_start_hour - current_hour
self.autobackup_current_hour = current_hour if diff_hour > 0 and diff_hour % self.autobackup_hour == 0:
self.autobackup_start_hour = current_hour
self.create_backup() self.create_backup()
def create_backup(self): def create_backup(self):
@ -373,7 +374,7 @@ class ModelBase(object):
bckp_filename_list = [ self.get_strpath_storage_for_file(filename) for _, filename in self.get_model_filename_list() ] bckp_filename_list = [ self.get_strpath_storage_for_file(filename) for _, filename in self.get_model_filename_list() ]
bckp_filename_list += [ str(self.get_summary_path()), str(self.model_data_path) ] bckp_filename_list += [ str(self.get_summary_path()), str(self.model_data_path) ]
for i in range(15,0,-1): for i in range(24,0,-1):
idx_str = '%.2d' % i idx_str = '%.2d' % i
next_idx_str = '%.2d' % (i+1) next_idx_str = '%.2d' % (i+1)
@ -381,7 +382,7 @@ class ModelBase(object):
next_idx_packup_path = self.autobackups_path / next_idx_str next_idx_packup_path = self.autobackups_path / next_idx_str
if idx_backup_path.exists(): if idx_backup_path.exists():
if i == 15: if i == 24:
pathex.delete_all_files(idx_backup_path) pathex.delete_all_files(idx_backup_path)
else: else:
next_idx_packup_path.mkdir(exist_ok=True) next_idx_packup_path.mkdir(exist_ok=True)

View file

@ -48,7 +48,7 @@ class SAEHDModel(ModelBase):
ask_override = self.ask_override() ask_override = self.ask_override()
if self.is_first_run() or ask_override: if self.is_first_run() or ask_override:
self.ask_enable_autobackup() self.ask_autobackup_hour()
self.ask_write_preview_history() self.ask_write_preview_history()
self.ask_target_iter() self.ask_target_iter()
self.ask_random_flip() self.ask_random_flip()

View file

@ -154,9 +154,14 @@ class SampleProcessor(object):
if motion_blur is not None: if motion_blur is not None:
chance, mb_max_size = motion_blur chance, mb_max_size = motion_blur
chance = np.clip(chance, 0, 100) chance = np.clip(chance, 0, 100)
rnd_state = np.random.RandomState (sample_rnd_seed)
mblur_rnd_chance = rnd_state.randint(100)
mblur_rnd_kernel = rnd_state.randint(mb_max_size)+1
mblur_rnd_deg = rnd_state.randint(360)
if np.random.randint(100) < chance: if mblur_rnd_chance < chance:
img = imagelib.LinearMotionBlur (img, np.random.randint( mb_max_size )+1, np.random.randint(360) ) img = imagelib.LinearMotionBlur (img, mblur_rnd_kernel, mblur_rnd_deg )
if gaussian_blur is not None: if gaussian_blur is not None:
chance, kernel_max_size = gaussian_blur chance, kernel_max_size = gaussian_blur