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)


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

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]:
(784, 1024)

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 [0]:


In [2]:
1:3:9


  File "<ipython-input-2-1582b5cbd8c4>", line 1
    1:3:9
     ^
SyntaxError: invalid syntax

In [3]:
import numpy as np

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

In [12]:
a


Out[12]:
array([[ 0.3316921 ,  0.45697793,  0.76768057],
       [ 0.17804919,  0.0410704 ,  0.3993807 ],
       [ 0.06461295,  0.13618152,  0.7477251 ],
       [ 0.86962633,  0.19510187,  0.80228744],
       [ 0.43930027,  0.68310295,  0.61256254],
       [ 0.57360055,  0.67984962,  0.40531831],
       [ 0.12692393,  0.11198779,  0.32368955],
       [ 0.82722747,  0.13012019,  0.64956639],
       [ 0.13627412,  0.68581125,  0.04038417]])

In [17]:
a[1:5:8, :]


Out[17]:
array([[ 0.17804919,  0.0410704 ,  0.3993807 ]])