-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from ragavvenkatesan/dev
Adding a pickle feature. This will enable saving the network down and…
- Loading branch information
Showing
7 changed files
with
101 additions
and
22 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ their documentations. | |
|
||
dataset | ||
graph | ||
pickle | ||
raster |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.. _pickle: | ||
|
||
:mod:`pickle` - provides a way to save the network' parameters as a pickle file. | ||
================================================================================ | ||
|
||
The file ``yann.utils.pickle.py`` contains the definition for the pickle methods. Use pickle | ||
method in the file to save the params down as a pickle file. Note that this only saves the | ||
parameters down and not the architecture or optimizers or other modules. The id of the layers | ||
will also be saved along as dictionary keys so you can use them to create a network. | ||
|
||
The documentation follows: | ||
|
||
.. automodule:: yann.utils.pickle | ||
:members: |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import cPickle | ||
import theano | ||
from collections import OrderedDict | ||
|
||
def pickle(net, name, verbose = 2): | ||
""" | ||
This method saves the weights of all the layers. | ||
Args: | ||
net: A yann network object | ||
name: What is the name of the file to pickle the network as. | ||
verbose: Blah.. | ||
""" | ||
if verbose >= 3: | ||
print "... Collecting Parameters" | ||
|
||
params = net.get_params(verbose = verbose) | ||
if verbose >= 3: | ||
print "... Dumping netowrk parameters" | ||
|
||
f = open(name, 'wb') | ||
cPickle.dump(params, f, protocol = cPickle.HIGHEST_PROTOCOL) | ||
f.close() | ||
|
||
def load(infile, verbose = 2): | ||
""" | ||
This method loads a pickled network and returns the parameters. | ||
Args: | ||
infile: Filename of the network pickled by this pickle method. | ||
Returns: | ||
params: A dictionary of parameters. | ||
""" | ||
if verbose >= 2: | ||
print ".. Loading the network." | ||
|
||
params = OrderedDict() | ||
if verbose >= 3: | ||
print "... Loading netowrk parameters" | ||
params_np = cPickle.load( open( infile, "rb" ) ) | ||
|
||
for lyr in params_np: | ||
shared_list = list() | ||
for p in params_np[lyr]: | ||
ps = theano.shared(value = p, borrow=True ) | ||
shared_list.append(ps) | ||
params [lyr] = shared_list | ||
return params |