Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ docs/_build/

# PyBuilder
target/

#ipython notebook
.ipynb_checkpoints/
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ Theano-Tutorials
================

Bare bones introduction to machine learning from linear regression to convolutional neural networks using Theano.

See [ipython notebooks](http://nbviewer.ipython.org/github/udibr/Theano-Tutorials/blob/master/notebooks/index.ipynb)

10 changes: 5 additions & 5 deletions load.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ def one_hot(x,n):

def mnist(ntrain=60000,ntest=10000,onehot=True):
data_dir = os.path.join(datasets_dir,'mnist/')
fd = open(os.path.join(data_dir,'train-images.idx3-ubyte'))
fd = open(os.path.join(data_dir,'train-images-idx3-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
trX = loaded[16:].reshape((60000,28*28)).astype(float)

fd = open(os.path.join(data_dir,'train-labels.idx1-ubyte'))
fd = open(os.path.join(data_dir,'train-labels-idx1-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
trY = loaded[8:].reshape((60000))

fd = open(os.path.join(data_dir,'t10k-images.idx3-ubyte'))
fd = open(os.path.join(data_dir,'t10k-images-idx3-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
teX = loaded[16:].reshape((10000,28*28)).astype(float)

fd = open(os.path.join(data_dir,'t10k-labels.idx1-ubyte'))
fd = open(os.path.join(data_dir,'t10k-labels-idx1-ubyte'))
loaded = np.fromfile(file=fd,dtype=np.uint8)
teY = loaded[8:].reshape((10000))

Expand All @@ -45,4 +45,4 @@ def mnist(ntrain=60000,ntest=10000,onehot=True):
trY = np.asarray(trY)
teY = np.asarray(teY)

return trX,teX,trY,teY
return trX,teX,trY,teY
143 changes: 143 additions & 0 deletions notebooks/0_multiply.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"metadata": {
"name": "",
"signature": "sha256:f13eb3b414e3e34aa7531d120d38fcd6602672de65630585a7952395a63c3f7e"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"import Theano"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"tensor is the section of theano that deals with data (like numpy)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import theano\n",
"from theano import tensor as T"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"create Theano symbolic variables"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"a = T.scalar()\n",
"b = T.scalar()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"our model"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"y = a * b"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"compile to a python function (to CPU or GPU depending on configuration)"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"multiply = theano.function(inputs=[a, b], outputs=y)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and use the function"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"multiply(1, 2)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
"array(2.0)"
]
}
],
"prompt_number": 5
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"multiply(3, 3)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"text": [
"array(9.0)"
]
}
],
"prompt_number": 6
}
],
"metadata": {}
}
]
}
Loading