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)


[2015-02-12 13:18:33.601273] > ... building the model

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]


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-9-280b60e43bbf> in <module>()
----> 1 da = sda.dA_layers[3]

IndexError: list index out of range

In [8]:
numpy.shape(da.W.get_value())


Out[8]:
(70, 70)

In [26]:
import gzip
train =  cPickle.load(gzip.open('train.pickle.gz', 'r'))

In [27]:
train


Out[27]:
(array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        ..., 
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.],
        [ 0.,  0.,  0., ...,  0.,  0.,  0.]], dtype=float32),
 array([5, 0, 4, ..., 8, 4, 8]))

In [3]:
ddn_display.map_to_input_space()


Out[3]:
[array([[ 0.04579591, -0.18277262,  0.12137735, ...,  0.18753509,
          0.11972587,  0.09042498],
        [ 0.13775837, -0.01091504, -0.12122336, ..., -0.12083928,
         -0.10891742, -0.18474402],
        [ 0.09298442,  0.10485994,  0.19065665, ...,  0.05653615,
          0.10360565,  0.19101664],
        ..., 
        [-0.12811485,  0.13664122,  0.04495057, ..., -0.10706387,
         -0.11928456,  0.06053942],
        [-0.01384088, -0.07372942,  0.20490818, ..., -0.14217353,
          0.12785897,  0.19635318],
        [ 0.19726098,  0.02721892,  0.12211317, ...,  0.13226026,
          0.0579107 ,  0.20831998]], dtype=float32),
 array([[-1.17797899,  0.29802224,  0.17742224, ..., -0.15063895,
         -1.26532018,  0.41980031],
        [ 1.26019645, -0.49960151, -0.28140855, ..., -0.14438808,
          0.31595966,  0.64643836],
        [ 0.2398041 ,  0.39951792,  0.64549249, ...,  0.54882926,
          0.39378491,  0.36607537],
        ..., 
        [-0.09850325,  0.17520493, -0.14378087, ..., -0.68869054,
          0.40776119,  0.77538145],
        [ 0.20951217, -1.08992922, -0.17817819, ..., -0.21313599,
          0.90888816, -0.15069214],
        [-0.30087399,  0.19739909, -0.0090945 , ..., -0.54674178,
          1.09623766,  0.15931991]], dtype=float32)]

In [12]:
sda.


Out[12]:
<models.sda.SdA at 0x4c4e910>

In [31]:
dnn.layers[4].W.get_value()


Out[31]:
array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       ..., 
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.]], dtype=float32)

In [18]:
2 + 1


Out[18]:
3

In [22]:
a = range(len([1,2,2,2,2])-1, -1, -1)

In [23]:
a


Out[23]:
[4, 3, 2, 1, 0]

In [ ]:


In [37]:
import numpy as np

In [38]:
a =np.random.random((9,3))

In [39]:



Out[39]:
array([[ 0.60616781,  0.6529921 ,  0.8874479 ],
       [ 0.53998917,  0.5409682 ,  0.08992238],
       [ 0.54627699,  0.42431642,  0.73976611],
       [ 0.25405443,  0.80976989,  0.2966003 ],
       [ 0.41475825,  0.30703943,  0.03069165],
       [ 0.6115559 ,  0.19603346,  0.07729197],
       [ 0.82587564,  0.74859706,  0.98171242],
       [ 0.08452298,  0.88848396,  0.55245313],
       [ 0.44521158,  0.16645095,  0.66663503]])

In [40]:
numpy.random.shuffle(a)

In [11]:
583+572+1623


Out[11]:
2778