GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge remote branch 'upstream/master' · jekky/DeepLearningTutorials@d3d2a81

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README.rst
  • README
  • code
    • mlp.py
    • test.py
  • doc
    • contents.txt
    • dA.txt
    • intro.txt
    • lenet.txt
    • mcrbm.txt
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README‎

Copy file name to clipboardExpand all lines: README
-1Lines changed: 0 additions & 1 deletion
This file was deleted.
Collapse file

‎README.rst‎

Copy file name to clipboard
+38Lines changed: 38 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Deep Learning Tutorials
2+
=======================
3+
4+
Deep Learning is a new area of Machine Learning research, which has been
5+
introduced with the objective of moving Machine Learning closer to one of its
6+
original goals: Artificial Intelligence. Deep Learning is about learning
7+
multiple levels of representation and abstraction that help to make sense of
8+
data such as images, sound, and text. The tutorials presented here will
9+
introduce you to some of the most important deep learning algorithms and will
10+
also show you how to run them using Theano. Theano is a python library that
11+
makes writing deep learning models easy, and gives the option of training them
12+
on a GPU.
13+
14+
The easiest way to follow the tutorials is to `browse them online
15+
<http://deeplearning.net/tutorial/>`_.
16+
17+
`Main development <http://github.com/lisa-lab/DeepLearningTutorials>`_
18+
of this project.
19+
20+
21+
Project Layout
22+
--------------
23+
24+
Subdirectories:
25+
26+
- code - Python files corresponding to each tutorial
27+
- data - data and scripts to download data that is used by the tutorials
28+
- doc - restructured text used by Sphinx to build the tutorial website
29+
- html - built automatically by doc/Makefile, contains tutorial website
30+
- issues_closed - issue tracking
31+
- issues_open - issue tracking
32+
- misc - administrative scripts
33+
34+
35+
Build instructions
36+
------------------
37+
38+
To build the html version of the tutorials, install sphinx and run doc/Makefile
Collapse file

‎code/mlp.py‎

Copy file name to clipboardExpand all lines: code/mlp.py
+17-11Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232

3333
class HiddenLayer(object):
34-
def __init__(self, rng, input, n_in, n_out, activation = T.tanh):
34+
def __init__(self, rng, input, n_in, n_out, W = None, b = None, activation = T.tanh):
3535
"""
3636
Typical hidden layer of a MLP: units are fully-connected and have
3737
sigmoidal activation function. Weight matrix W is of shape (n_in,n_out)
@@ -70,19 +70,25 @@ def __init__(self, rng, input, n_in, n_out, activation = T.tanh):
7070
# should use 4 times larger initial weights for sigmoid
7171
# compared to tanh
7272
# We have no info for other function, so we use the same as tanh.
73-
W_values = numpy.asarray( rng.uniform(
74-
low = - numpy.sqrt(6./(n_in+n_out)),
75-
high = numpy.sqrt(6./(n_in+n_out)),
76-
size = (n_in, n_out)), dtype = theano.config.floatX)
77-
if activation == theano.tensor.nnet.sigmoid:
78-
W_values *= 4
73+
if W is None:
74+
W_values = numpy.asarray( rng.uniform(
75+
low = - numpy.sqrt(6./(n_in+n_out)),
76+
high = numpy.sqrt(6./(n_in+n_out)),
77+
size = (n_in, n_out)), dtype = theano.config.floatX)
78+
if activation == theano.tensor.nnet.sigmoid:
79+
W_values *= 4
7980

80-
self.W = theano.shared(value = W_values, name ='W')
81+
W = theano.shared(value = W_values, name ='W')
8182

82-
b_values = numpy.zeros((n_out,), dtype= theano.config.floatX)
83-
self.b = theano.shared(value= b_values, name ='b')
83+
if b is None:
84+
b_values = numpy.zeros((n_out,), dtype= theano.config.floatX)
85+
b = theano.shared(value= b_values, name ='b')
8486

85-
self.output = activation(T.dot(input, self.W) + self.b)
87+
self.W = W
88+
self.b = b
89+
90+
lin_output = T.dot(input, self.W) + self.b
91+
self.output = lin_output if activation is None else activation(lin_output)
8692
# parameters of the model
8793
self.params = [self.W, self.b]
8894

Collapse file

‎code/test.py‎

Copy file name to clipboard
+144-89Lines changed: 144 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import convolutional_mlp, logistic_cg, logistic_sgd, mlp, SdA, dA, rbm , DBN
2-
from nose.plugins.skip import SkipTest
3-
import numpy, theano
4-
import time, sys
1+
import sys
2+
3+
import numpy
4+
import theano
5+
6+
import convolutional_mlp, logistic_cg, logistic_sgd
7+
import mlp, SdA, dA, rbm, DBN
58

69

710
def test_logistic_sgd():
@@ -17,25 +20,24 @@ def test_mlp():
1720

1821

1922
def test_convolutional_mlp():
20-
convolutional_mlp.evaluate_lenet5(n_epochs=5,nkerns=[5,5])
23+
convolutional_mlp.evaluate_lenet5(n_epochs=5, nkerns=[5, 5])
2124

2225

2326
def test_dA():
24-
dA.test_dA(training_epochs = 3, output_folder = 'tmp_dA_plots')
27+
dA.test_dA(training_epochs=3, output_folder='tmp_dA_plots')
2528

2629

2730
def test_SdA():
28-
SdA.test_SdA(pretraining_epochs = 2, training_epochs = 3, batch_size = 300)
31+
SdA.test_SdA(pretraining_epochs=2, training_epochs=3, batch_size=300)
2932

3033

3134
def test_dbn():
32-
DBN.test_DBN(pretraining_epochs = 1, training_epochs = 2, batch_size =300)
33-
35+
DBN.test_DBN(pretraining_epochs=1, training_epochs=2, batch_size=300)
3436

3537

3638
def test_rbm():
37-
rbm.test_rbm(training_epochs = 1, batch_size = 300, n_chains = 1, n_samples = 1,
38-
output_folder = 'tmp_rbm_plots')
39+
rbm.test_rbm(training_epochs=1, batch_size=300, n_chains=1, n_samples=1,
40+
output_folder='tmp_rbm_plots')
3941

4042

4143
def speed():
@@ -44,133 +46,186 @@ def speed():
4446
I want it to be compatible with python2.4 so using try: finaly: is not an option.
4547
"""
4648

47-
import theano
48-
algo=['logistic_sgd','logistic_cg','mlp','convolutional_mlp','dA','SdA','DBN','rbm']
49-
to_exec=[True]*len(algo)
49+
algo = ['logistic_sgd', 'logistic_cg', 'mlp', 'convolutional_mlp',
50+
'dA', 'SdA', 'DBN', 'rbm']
51+
to_exec = [True] * len(algo)
5052
# to_exec=[False]*len(algo)
5153
# to_exec[-1]=True
52-
do_float64=True
53-
do_float32=True
54-
do_gpu=True
55-
56-
algo_executed = [s for idx,s in enumerate(algo) if to_exec[idx]]
57-
58-
expected_times_64=numpy.asarray([ 12.42313051, 28.09523582, 106.35365391, 116.79225969, 153.12310314,
59-
425.09175086, 642.72824597, 652.52828193])
60-
expected_times_32=numpy.asarray([ 13.29699826, 32.42813158, 68.03559947, 105.54640913, 107.00527334,
61-
242.41721797, 490.40798998, 528.88854146])
62-
expected_times_gpu=numpy.asarray([ 3.07663488, 7.55523491, 18.99226785, 9.58915591, 24.13007045,
63-
24.77524018, 92.66246653, 322.34032917])
64-
expected_times_64 = [s for idx,s in enumerate(expected_times_64) if to_exec[idx]]
65-
expected_times_32 = [s for idx,s in enumerate(expected_times_32) if to_exec[idx]]
66-
expected_times_gpu = [s for idx,s in enumerate(expected_times_gpu) if to_exec[idx]]
67-
68-
def time_test(m,l,idx,f,**kwargs):
54+
do_float64 = True
55+
do_float32 = True
56+
do_gpu = True
57+
58+
algo_executed = [s for idx, s in enumerate(algo) if to_exec[idx]]
59+
#Timming expected are from the buildbot that have
60+
# an i7-920 @ 2.67GHz with hyperthread enabled for the cpu
61+
# and an GeForce GTX 285 for the GPU.
62+
63+
expected_times_64 = numpy.asarray([10.7, 23.7, 84.8, 74.9, 124.6,
64+
384.9, 414.6, 558.1])
65+
expected_times_32 = numpy.asarray([9.8, 25.1, 56.7, 66.5, 85.4,
66+
211.0, 245.7, 432.8])
67+
# Number with just 1 decimal are new value that are faster with
68+
# the Theano version 0.5rc2 Other number are older. They are not
69+
# updated, as we where faster in the past!
70+
# TODO: find why and fix this!
71+
72+
# Here is the value for the buildbot on February 3th 2012.
73+
# sgd, cg mlp conv da
74+
# sda dbn rbm
75+
# gpu times[3.72957802, 9.94316864, 29.1772666, 9.13857198, 25.91144657,
76+
# 18.30802011, 53.38651466, 285.41386175]
77+
# expected [3.076634879, 7.555234910, 18.99226785, 9.58915591, 24.130070450,
78+
# 24.77524018, 92.66246653, 322.340329170]
79+
# sgd, cg mlp conv da
80+
# sda dbn rbm
81+
#expected/get [0.82492841, 0.75984178, 0.65092691, 1.04930573, 0.93125138
82+
# 1.35324519 1.7356905 1.12937868]
83+
expected_times_gpu = numpy.asarray([3.07663488, 7.55523491, 18.99226785,
84+
9.1, 24.13007045,
85+
18.3, 53.4, 285.4])
86+
expected_times_64 = [s for idx, s in enumerate(expected_times_64)
87+
if to_exec[idx]]
88+
expected_times_32 = [s for idx, s in enumerate(expected_times_32)
89+
if to_exec[idx]]
90+
expected_times_gpu = [s for idx, s in enumerate(expected_times_gpu)
91+
if to_exec[idx]]
92+
93+
def time_test(m, l, idx, f, **kwargs):
6994
if not to_exec[idx]:
7095
return
7196
print algo[idx]
72-
ts=m.call_time
97+
ts = m.call_time
7398
try:
7499
f(**kwargs)
75100
except Exception, e:
76101
print >> sys.stderr, 'test', algo[idx], 'FAILED', e
77102
l.append(numpy.nan)
78103
return
79-
te=m.call_time
80-
l.append(te-ts)
104+
te = m.call_time
105+
l.append(te - ts)
81106

82107
def do_tests():
83-
m=theano.compile.mode.get_default_mode()
84-
l=[]
85-
time_test(m,l,0, logistic_sgd.sgd_optimization_mnist,n_epochs=30)
86-
time_test(m,l,1, logistic_cg.cg_optimization_mnist,n_epochs=30)
87-
time_test(m,l,2, mlp.test_mlp, n_epochs=5)
88-
time_test(m,l,3, convolutional_mlp.evaluate_lenet5, n_epochs=5,nkerns=[5,5])
89-
time_test(m,l,4, dA.test_dA, training_epochs = 2, output_folder = 'tmp_dA_plots')
90-
time_test(m,l,5, SdA.test_SdA, pretraining_epochs = 1, training_epochs = 2, batch_size = 300)
91-
time_test(m,l,6, DBN.test_DBN, pretraining_epochs = 1, training_epochs = 2, batch_size = 300)
92-
time_test(m,l,7, rbm.test_rbm, training_epochs = 1, batch_size = 300, n_chains = 1, n_samples = 1, output_folder = 'tmp_rbm_plots')
108+
m = theano.compile.mode.get_default_mode()
109+
l = []
110+
time_test(m, l, 0, logistic_sgd.sgd_optimization_mnist, n_epochs=30)
111+
time_test(m, l, 1, logistic_cg.cg_optimization_mnist, n_epochs=30)
112+
time_test(m, l, 2, mlp.test_mlp, n_epochs=5)
113+
time_test(m, l, 3, convolutional_mlp.evaluate_lenet5, n_epochs=5,
114+
nkerns=[5, 5])
115+
time_test(m, l, 4, dA.test_dA, training_epochs=2,
116+
output_folde='tmp_dA_plots')
117+
time_test(m, l, 5, SdA.test_SdA, pretraining_epochs=1,
118+
training_epochs=2, batch_size=300)
119+
time_test(m, l, 6, DBN.test_DBN, pretraining_epochs=1,
120+
training_epochs=2, batch_size=300)
121+
time_test(m, l, 7, rbm.test_rbm, training_epochs=1, batch_size=300,
122+
n_chains=1, n_samples=1, output_folder='tmp_rbm_plots')
93123
return numpy.asarray(l)
94124

95-
96125
#test in float64 in FAST_RUN mode on the cpu
126+
import theano
97127
if do_float64:
98-
theano.config.floatX='float64'
99-
theano.config.mode='FAST_RUN'
100-
float64_times=do_tests()
128+
theano.config.floatX = 'float64'
129+
theano.config.mode = 'FAST_RUN'
130+
float64_times = do_tests()
101131
print >> sys.stderr, algo_executed
102-
print >> sys.stderr, 'float64 times',float64_times
103-
print >> sys.stderr, 'float64 expected',expected_times_64
104-
print >> sys.stderr, 'float64 % expected/get',expected_times_64/float64_times
132+
print >> sys.stderr, 'float64 times', float64_times
133+
print >> sys.stderr, 'float64 expected', expected_times_64
134+
print >> sys.stderr, 'float64 % expected/get', (
135+
expected_times_64 / float64_times)
105136

106137
#test in float32 in FAST_RUN mode on the cpu
107-
theano.config.floatX='float32'
138+
theano.config.floatX = 'float32'
108139
if do_float32:
109-
float32_times=do_tests()
140+
float32_times = do_tests()
110141
print >> sys.stderr, algo_executed
111-
print >> sys.stderr, 'float32 times',float32_times
112-
print >> sys.stderr, 'float32 expected',expected_times_32
113-
print >> sys.stderr, 'float32 % expected/get',expected_times_32/float32_times
142+
print >> sys.stderr, 'float32 times', float32_times
143+
print >> sys.stderr, 'float32 expected', expected_times_32
144+
print >> sys.stderr, 'float32 % expected/get', (
145+
expected_times_32 / float32_times)
114146

115147
if do_float64:
116-
print >> sys.stderr, 'float64/float32',float64_times/float32_times
148+
print >> sys.stderr, 'float64/float32', (
149+
float64_times / float32_times)
117150
print >> sys.stderr
118151
print >> sys.stderr, 'Duplicate the timing to have everything in one place'
119152
print >> sys.stderr, algo_executed
120-
print >> sys.stderr, 'float64 times',float64_times
121-
print >> sys.stderr, 'float64 expected',expected_times_64
122-
print >> sys.stderr, 'float64 % expected/get',expected_times_64/float64_times
123-
print >> sys.stderr, 'float32 times',float32_times
124-
print >> sys.stderr, 'float32 expected',expected_times_32
125-
print >> sys.stderr, 'float32 % expected/get',expected_times_32/float32_times
126-
127-
print >> sys.stderr, 'float64/float32',float64_times/float32_times
128-
print >> sys.stderr, 'expected float64/float32',expected_times_64/float32_times
153+
print >> sys.stderr, 'float64 times', float64_times
154+
print >> sys.stderr, 'float64 expected', expected_times_64
155+
print >> sys.stderr, 'float64 % expected/get', (
156+
expected_times_64 / float64_times)
157+
print >> sys.stderr, 'float32 times', float32_times
158+
print >> sys.stderr, 'float32 expected', expected_times_32
159+
print >> sys.stderr, 'float32 % expected/get', (
160+
expected_times_32 / float32_times)
161+
162+
print >> sys.stderr, 'float64/float32', (
163+
float64_times / float32_times)
164+
print >> sys.stderr, 'expected float64/float32', (
165+
expected_times_64 / float32_times)
129166

130167
#test in float32 in FAST_RUN mode on the gpu
131168
import theano.sandbox.cuda
132169
if do_gpu:
133170
theano.sandbox.cuda.use('gpu')
134-
gpu_times=do_tests()
171+
gpu_times = do_tests()
135172
print >> sys.stderr, algo_executed
136-
print >> sys.stderr, 'gpu times',gpu_times
137-
print >> sys.stderr, 'gpu expected',expected_times_gpu
138-
print >> sys.stderr, 'gpu % expected/get',expected_times_gpu/gpu_times
173+
print >> sys.stderr, 'gpu times', gpu_times
174+
print >> sys.stderr, 'gpu expected', expected_times_gpu
175+
print >> sys.stderr, 'gpu % expected/get', (
176+
expected_times_gpu / gpu_times)
177+
139178
if do_float64:
140-
print >> sys.stderr, 'float64/gpu',float64_times/gpu_times
179+
print >> sys.stderr, 'float64/gpu', float64_times / gpu_times
141180

142181
if (do_float64 + do_float32 + do_gpu) > 1:
143182
print >> sys.stderr
144183
print >> sys.stderr, 'Duplicate the timing to have everything in one place'
145184
print >> sys.stderr, algo_executed
146185
if do_float64:
147-
print >> sys.stderr, 'float64 times',float64_times
148-
print >> sys.stderr, 'float64 expected',expected_times_64
149-
print >> sys.stderr, 'float64 % expected/get',expected_times_64/float64_times
186+
print >> sys.stderr, 'float64 times', float64_times
187+
print >> sys.stderr, 'float64 expected', expected_times_64
188+
print >> sys.stderr, 'float64 % expected/get', (
189+
expected_times_64 / float64_times)
150190
if do_float32:
151-
print >> sys.stderr, 'float32 times',float32_times
152-
print >> sys.stderr, 'float32 expected',expected_times_32
153-
print >> sys.stderr, 'float32 % expected/get',expected_times_32/float32_times
191+
print >> sys.stderr, 'float32 times', float32_times
192+
print >> sys.stderr, 'float32 expected', expected_times_32
193+
print >> sys.stderr, 'float32 % expected/get', (
194+
expected_times_32 / float32_times)
154195
if do_gpu:
155-
print >> sys.stderr, 'gpu times',gpu_times
156-
print >> sys.stderr, 'gpu expected',expected_times_gpu
157-
print >> sys.stderr, 'gpu % expected/get',expected_times_gpu/gpu_times
196+
print >> sys.stderr, 'gpu times', gpu_times
197+
print >> sys.stderr, 'gpu expected', expected_times_gpu
198+
print >> sys.stderr, 'gpu % expected/get', (
199+
expected_times_gpu / gpu_times)
158200

159201
if do_float64 and do_float32:
160-
print >> sys.stderr, 'float64/float32',float64_times/float32_times
161-
print >> sys.stderr, 'expected float64/float32',expected_times_64/float32_times
202+
print >> sys.stderr, 'float64/float32', (
203+
float64_times / float32_times)
204+
print >> sys.stderr, 'expected float64/float32', (
205+
expected_times_64 / float32_times)
162206
if do_float64 and do_gpu:
163-
print >> sys.stderr, 'float64/gpu',float64_times/gpu_times
164-
print >> sys.stderr, 'expected float64/gpu',expected_times_64/gpu_times
207+
print >> sys.stderr, 'float64/gpu', float64_times / gpu_times
208+
print >> sys.stderr, 'expected float64/gpu', (
209+
expected_times_64 / gpu_times)
165210
if do_float32 and do_gpu:
166-
print >> sys.stderr, 'float32/gpu',float32_times/gpu_times
167-
print >> sys.stderr, 'expected float32/gpu',expected_times_32/gpu_times
211+
print >> sys.stderr, 'float32/gpu', float32_times / gpu_times
212+
print >> sys.stderr, 'expected float32/gpu', (
213+
expected_times_32 / gpu_times)
214+
215+
def compare(x, y):
216+
ratio = x / y
217+
# If there is more then 5% difference between the expected
218+
# time and the real time, we consider this an error.
219+
return sum((ratio < 0.95) + (ratio > 1.05))
168220

169221
if do_float64:
170-
print >> sys.stderr, 'speed_failure_float64='+str(sum((expected_times_64/float64_times)>0.95))
222+
err = compare(expected_times_64, float64_times)
223+
print >> sys.stderr, 'speed_failure_float64=' + str(err)
171224
if do_float32:
172-
print >> sys.stderr, 'speed_failure_float32='+str(sum((expected_times_32/float32_times)>0.95))
225+
err = compare(expected_times_32, float32_times)
226+
print >> sys.stderr, 'speed_failure_float32=' + str(err)
173227
if do_gpu:
174-
print >> sys.stderr, 'speed_failure_gpu='+str(sum((expected_times_gpu/gpu_times)>0.95))
228+
err = compare(expected_times_gpu, gpu_times)
229+
print >> sys.stderr, 'speed_failure_gpu=' + str(err)
175230

176231
assert not numpy.isnan(gpu_times).any()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.