Permalink
Browse files

fix loss history

  • Loading branch information...
iperov committed Jan 11, 2019
1 parent e6fa021 commit 2473dabf374edd0c5eac6b37e2119cb48e269418
Showing with 49 additions and 32 deletions.
  1. +1 −1 README.md
  2. +26 −30 mainscripts/Trainer.py
  3. +1 −1 models/ModelBase.py
  4. +21 −0 nnlib/nnlib.py
@@ -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:

@@ -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]
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)
]


plist_min = [ [ min (plist_max[col][p],
plist_max[col][p],
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(0,loss_count)
for p in range(loss_count)
]
for col in range(0, w)
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 )

@@ -49,7 +49,7 @@ def __init__(self, model_path, training_data_src_path=None, training_data_dst_pa
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.")
@@ -40,6 +40,7 @@ class nnlib(object):
DSSIMMaskLoss = None
PixelShuffler = None
SubpixelUpscaler = None
AddUniformNoise = None

ResNet = None
UNet = None
@@ -101,6 +102,7 @@ class nnlib(object):
DSSIMMaskLoss = nnlib.DSSIMMaskLoss
PixelShuffler = nnlib.PixelShuffler
SubpixelUpscaler = nnlib.SubpixelUpscaler
AddUniformNoise = nnlib.AddUniformNoise
"""
code_import_keras_contrib_string = \
"""
@@ -541,6 +543,25 @@ def get_config(self):
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:

0 comments on commit 2473dab

Please sign in to comment.