In [1]:
import sys
sys.path.append('/home/du/workspace/pdnn/')
import cPickle
import gzip
import os
import sys
import time
import numpy
import theano
import theano.tensor as T
from theano.tensor.shared_randomstreams import RandomStreams
from models.dnn import DNN
from models.dropout_nnet import DNN_Dropout
from io_func.model_io import _nnet2file, _cfg2file, _file2nnet, log
from utils.utils import parse_arguments
from utils.learn_rates import _lrate2file, _file2lrate
from utils.network_config import NetworkConfig
from learning.sgd import train_sgd, validate_by_minibatch
sys.path.append('/home/du/Dropbox/Project/libs/')
from DL_libs import NetworkDisplayer
In [3]:
from DL_libs import *
cfg = NetworkConfig()
arguments = {}
arguments['ptr_file'] = 'sda.mdl'
arguments['ptr_layer_number'] = 2
# parse pre-training options
# pre-training files and layer number (how many layers are set to the pre-training parameters)
ptr_layer_number = 2; ptr_file = ''
if arguments.has_key('ptr_file') and arguments.has_key('ptr_layer_number'):
ptr_file = arguments['ptr_file']
ptr_layer_number = int(arguments['ptr_layer_number'])
cfg.hidden_layers_sizes = [200,200]
cfg.n_ins = 28*28
cfg.n_outs = 10
numpy_rng = numpy.random.RandomState(89677)
theano_rng = RandomStreams(numpy_rng.randint(2 ** 30))
log('> ... building the model')
# setup model
if cfg.do_dropout:
dnn = DNN_Dropout(theano_rng = theano_rng, cfg = cfg)
else:
dnn = DNN(numpy_rng=numpy_rng, theano_rng = theano_rng, cfg = cfg)
# initialize model parameters
# if not resuming training, initialized from the specified pre-training file
# if resuming training, initialized from the tmp model file
resume_training = False
if (ptr_layer_number > 0) and (resume_training is False):
_file2nnet(dnn.layers, set_layer_num = ptr_layer_number, filename = ptr_file)
In [4]:
ddn_display = NetworkDisplayer(dnn)
In [34]:
sda = cPickle.load(open('sda.pickle', 'r'))
ddn_display = NetworkDisplayer(sda)
In [ ]:
In [36]:
ddn_display.save_to_file('5layers_Sda')
In [9]:
da = sda.dA_layers[3]
In [8]:
numpy.shape(da.W.get_value())
Out[8]:
In [26]:
import gzip
train = cPickle.load(gzip.open('train.pickle.gz', 'r'))
In [27]:
train
Out[27]:
In [3]:
ddn_display.map_to_input_space()
Out[3]:
In [12]:
sda.
Out[12]:
In [31]:
dnn.layers[4].W.get_value()
Out[31]:
In [18]:
2 + 1
Out[18]:
In [22]:
a = range(len([1,2,2,2,2])-1, -1, -1)
In [23]:
a
Out[23]:
In [ ]:
In [37]:
import numpy as np
In [38]:
a =np.random.random((9,3))
In [39]:
Out[39]:
In [40]:
numpy.random.shuffle(a)
In [11]:
583+572+1623
Out[11]: