Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added reset() function to sequential model #1908

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion keras/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def model_from_json(json_string, custom_objects={}):
return model_from_config(config, custom_objects=custom_objects)


def model_from_config(config, custom_objects={}):
def model_from_config(config, custom_objects={}, reset=False):
'''
'''
model_name = config.get('name')
Expand All @@ -181,6 +181,9 @@ def model_from_config(config, custom_objects={}):
elif model_name == 'Sequential':
model.__class__ = Sequential
model.name = model_name
if reset:
for layer in model.layers:
layer.build()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break if layer is a container.


if 'optimizer' in config:
# if it has an optimizer, the model is assumed to be compiled
Expand Down Expand Up @@ -463,6 +466,14 @@ def summary(self):
'''
model_summary(self)

def reset(self):
''' Reset all weights and biases to random values, then recompiles

Returns: Model
'''

return model_from_config(self.get_config(), reset=True)


class Sequential(Model, containers.Sequential):
'''Linear stack of layers.
Expand Down