Created
January 15, 2017 08:39
-
-
Save haoliplus/a5205e7e18119ca7fe1ed283142c0779 to your computer and use it in GitHub Desktop.
lasagne save&restore params
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
import cPickle as pickle | |
import os | |
import lasagne | |
def read_model_data(model, filename): | |
filename = os.path.join('./', '%s.param.theano' % filename) | |
with open(filename, 'r') as f: | |
data = pickle.load(f) | |
lasagne.layers.set_all_param_values(model, data) | |
def write_model_data(model, filename): | |
"""Pickels the parameters within a Lasagne model.""" | |
data = lasagne.layers.get_all_param_values(model) | |
filename = os.path.join('./', filename) | |
filename = '%s.%s' % (filename, PARAM_EXTENSION) | |
with open(filename, 'w') as f: | |
pickle.dump(data, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment