Skip to content

Commit

Permalink
Re-wrote reset_weights... just recompile the model
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Sep 12, 2018
1 parent 4c0d2da commit d588e61
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions conx/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ def summary(self):
else:
print("Compile network in order to see summary.")

def reset(self, clear=False, compile=False, **overrides):
def reset(self, clear=False, **overrides):
"""
Reset all of the weights/biases in a network.
The magnitude is based on the size of the network.
Expand All @@ -869,24 +869,11 @@ def reset(self, clear=False, compile=False, **overrides):
np.random.seed(self.seed)
del overrides["seed"]
## Reset all weights and biases:
self.reset_weights()
## Recompile with possibly new options:
if compile or clear:
if clear:
self.compile_options = {}
self.compile_options.update(overrides)
self.compile(**self.compile_options)

def reset_weights(self):
"""
Reset weights and biases.
"""
session = K.get_session()
for layer in self.model.layers:
if hasattr(layer, 'kernel'):
layer.kernel.initializer.run(session=session)
elif hasattr(layer, 'cell'):
layer.cell.kernel.initializer.run(session=session)
if clear:
self.compile_options = {}
self.compile_options.update(overrides)
self.compile_model(**self.compile_options)

def test(self, batch_size=32, show=False, tolerance=None, force=False,
show_inputs=True, show_outputs=True,
Expand Down

0 comments on commit d588e61

Please sign in to comment.