Skip to content

Instantly share code, notes, and snippets.

@haoliplus
Created January 15, 2017 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haoliplus/a5205e7e18119ca7fe1ed283142c0779 to your computer and use it in GitHub Desktop.
Save haoliplus/a5205e7e18119ca7fe1ed283142c0779 to your computer and use it in GitHub Desktop.
lasagne save&restore params
# -*- 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