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 = 0; 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 [2]:
sda = cPickle.load(open('sda.pickle', 'r'))
ddn_display = NetworkDisplayer(sda)
In [4]:
ddn_display.save_to_file('2layers_Sda')
In [7]:
da = sda.dA_layers[0]
In [12]:
numpy.shape(da.W.get_value())
Out[12]:
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 [0]:
In [2]:
1:3:9
In [3]:
import numpy as np
In [11]:
a =np.random.random((9,3))
In [12]:
a
Out[12]:
In [17]:
a[1:5:8, :]
Out[17]: