diff --git a/README.md b/README.md index fd87e07..4489e15 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ Only H64 model reasonable to train on home CPU. ### Mac/linux/docker script support. -This repo supports only windows build of scripts. If you want to support mac/linux/docker - create such fork, it will be referenced here. +This repo supports only windows build of scripts. If you want to support mac/linux/docker - create fork, it will be referenced here. ### Prebuilt windows app: diff --git a/mainscripts/Trainer.py b/mainscripts/Trainer.py index 8b45dcd..d79818e 100644 --- a/mainscripts/Trainer.py +++ b/mainscripts/Trainer.py @@ -196,43 +196,42 @@ def previewThread (input_queue, output_queue): lh_len = len(loss_history) l_per_col = lh_len / w - plist_max = [ [ max (0.0, 0.0, *[ loss_history[i_ab][p] - for i_ab in range( int(col*l_per_col), int((col+1)*l_per_col) ) - ] - ) - for p in range(0,loss_count) - ] - for col in range(0, w) - ] - - - plist_min = [ [ min (plist_max[col][p], - plist_max[col][p], + plist_max = [ [ max (0.0, loss_history[int(col*l_per_col)][p], *[ loss_history[i_ab][p] for i_ab in range( int(col*l_per_col), int((col+1)*l_per_col) ) ] ) - for p in range(0,loss_count) + for p in range(loss_count) ] - for col in range(0, w) + for col in range(w) ] + + plist_min = [ [ min (plist_max[col][p], loss_history[int(col*l_per_col)][p], + *[ loss_history[i_ab][p] + for i_ab in range( int(col*l_per_col), int((col+1)*l_per_col) ) + ] + ) + for p in range(loss_count) + ] + for col in range(w) + ] + plist_abs_max = np.mean(loss_history[ len(loss_history) // 5 : ]) * 2 - - if l_per_col >= 1.0: - for col in range(0, w): - for p in range(0,loss_count): - point_color = [1.0]*c - point_color[0:3] = colorsys.hsv_to_rgb ( p * (1.0/loss_count), 1.0, 1.0 ) - - ph_max = int ( (plist_max[col][p] / plist_abs_max) * (lh_height-1) ) - ph_max = np.clip( ph_max, 0, lh_height-1 ) - - ph_min = int ( (plist_min[col][p] / plist_abs_max) * (lh_height-1) ) - ph_min = np.clip( ph_min, 0, lh_height-1 ) - - for ph in range(ph_min, ph_max+1): - lh_img[ (lh_height-ph-1), col ] = point_color - + + for col in range(0, w): + for p in range(0,loss_count): + point_color = [1.0]*c + point_color[0:3] = colorsys.hsv_to_rgb ( p * (1.0/loss_count), 1.0, 1.0 ) + + ph_max = int ( (plist_max[col][p] / plist_abs_max) * (lh_height-1) ) + ph_max = np.clip( ph_max, 0, lh_height-1 ) + + ph_min = int ( (plist_min[col][p] / plist_abs_max) * (lh_height-1) ) + ph_min = np.clip( ph_min, 0, lh_height-1 ) + + for ph in range(ph_min, ph_max+1): + lh_img[ (lh_height-ph-1), col ] = point_color + lh_lines = 5 lh_line_height = (lh_height-1)/lh_lines for i in range(0,lh_lines+1): @@ -241,10 +240,7 @@ def previewThread (input_queue, output_queue): last_line_t = int((lh_lines-1)*lh_line_height) last_line_b = int(lh_lines*lh_line_height) - if epoch != 0: - lh_text = 'Loss history. Epoch: %d' % (epoch) - else: - lh_text = 'Loss history.' + lh_text = 'Epoch: %d' % (epoch) if epoch != 0 else '' lh_img[last_line_t:last_line_b, 0:w] += image_utils.get_text_image ( (w,last_line_b-last_line_t,c), lh_text, color=head_text_color ) diff --git a/models/ModelBase.py b/models/ModelBase.py index dcad4bf..a8e4355 100644 --- a/models/ModelBase.py +++ b/models/ModelBase.py @@ -49,7 +49,7 @@ class ModelBase(object): self.loss_history = model_data['loss_history'] if 'loss_history' in model_data.keys() else [] self.sample_for_preview = model_data['sample_for_preview'] if 'sample_for_preview' in model_data.keys() else None - ask_override = self.is_training_mode and self.epoch != 0 and input_in_time ("Press enter during 2 seconds to override some model settings.", 2) + ask_override = self.is_training_mode and self.epoch != 0 and input_in_time ("Press enter in 2 seconds to override some model settings.", 2) if self.epoch == 0: print ("\nModel first run. Enter model options as default for each run.") diff --git a/nnlib/nnlib.py b/nnlib/nnlib.py index 79d9d29..3ce3fd8 100644 --- a/nnlib/nnlib.py +++ b/nnlib/nnlib.py @@ -40,6 +40,7 @@ class nnlib(object): DSSIMMaskLoss = None PixelShuffler = None SubpixelUpscaler = None + AddUniformNoise = None ResNet = None UNet = None @@ -101,6 +102,7 @@ DSSIMLoss = nnlib.DSSIMLoss DSSIMMaskLoss = nnlib.DSSIMMaskLoss PixelShuffler = nnlib.PixelShuffler SubpixelUpscaler = nnlib.SubpixelUpscaler +AddUniformNoise = nnlib.AddUniformNoise """ code_import_keras_contrib_string = \ """ @@ -541,6 +543,25 @@ NLayerDiscriminator = nnlib.NLayerDiscriminator nnlib.PixelShuffler = PixelShuffler nnlib.SubpixelUpscaler = PixelShuffler + class AddUniformNoise(keras.layers.Layer): + def __init__(self, power=1.0, minval=-1.0, maxval=1.0, **kwargs): + super(AddUniformNoise, self).__init__(**kwargs) + self.power = power + self.supports_masking = True + self.minval = minval + self.maxval = maxval + + def call(self, inputs, training=None): + def noised(): + return inputs + self.power*K.random_uniform(shape=K.shape(inputs), minval=self.minval, maxval=self.maxval) + return K.in_train_phase(noised, inputs, training=training) + + def get_config(self): + config = {'power': self.power, 'minval': self.minval, 'maxval': self.maxval} + base_config = super(AddUniformNoise, self).get_config() + return dict(list(base_config.items()) + list(config.items())) + nnlib.AddUniformNoise = AddUniformNoise + @staticmethod def import_keras_contrib(device_config = None): if nnlib.keras_contrib is not None: