Skip to content

Commit

Permalink
notebook updates
Browse files Browse the repository at this point in the history
  • Loading branch information
denizyuret committed Jan 21, 2019
1 parent c95ef34 commit b82f0cc
Show file tree
Hide file tree
Showing 9 changed files with 3,296 additions and 531 deletions.
61 changes: 42 additions & 19 deletions tutorial/15.quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Quick start"
"# Quick start\n",
"(c) Deniz Yuret, 2019\n",
"\n",
"This notebook is for the impatient reader who wants to get a flavor of Julia/Knet possibly to compare it with other deep learning frameworks. In 15 lines of code and 30 seconds of GPU time we define, train, and evaluate the LeNet convolutional neural network model from scratch without any predefined layers."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -18,31 +21,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Define convolutional layer:\n",
"struct Conv; w; b; f; end\n",
"(c::Conv)(x) = c.f.(pool(conv4(c.w, x) .+ c.b))\n",
"Conv(w1,w2,cx,cy,f=relu) = Conv(param(w1,w2,cx,cy), param0(1,1,cy,1), f)"
"Conv(w1,w2,cx,cy,f=relu) = Conv(param(w1,w2,cx,cy), param0(1,1,cy,1), f);"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Define dense layer:\n",
"struct Dense; w; b; f; end\n",
"(d::Dense)(x) = d.f.(d.w * mat(x) .+ d.b)\n",
"Dense(i::Int,o::Int,f=relu) = Dense(param(o,i), param0(o), f)"
"Dense(i::Int,o::Int,f=relu) = Dense(param(o,i), param0(o), f);"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -54,33 +57,53 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"┌ Info: Loading MNIST...\n",
"└ @ Main /home/deniz/.julia/dev/Knet/data/mnist.jl:33\n"
]
}
],
"source": [
"# Load MNIST data\n",
"include(Knet.dir(\"data\",\"mnist.jl\"))\n",
"dtrn, dtst = mnistdata()"
"dtrn, dtst = mnistdata();"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3.40e-02 100.00%┣████████████████████████████████████████████████████████████┫ 6000/6000 [00:25/00:25, 238.78i/s]\n"
]
},
{
"data": {
"text/plain": [
"0.9921"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Train and test LeNet (about 30 secs on a gpu to reach 99% accuracy)\n",
"LeNet = Chain(Conv(5,5,1,20), Conv(5,5,20,50), Dense(800,500), Dense(500,10,identity))\n",
"progress!(adam(LeNet, repeat(dtrn,10)))\n",
"accuracy(LeNet, dtst)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
29 changes: 9 additions & 20 deletions tutorial/20.mnist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,16 @@
},
"source": [
"# Load and minibatch MNIST data\n",
"(c) Deniz Yuret, 2019"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"* Objective: Load the [MNIST](http://yann.lecun.com/exdb/mnist) dataset, convert into Julia arrays, split into minibatches using Knet's [minibatch](http://denizyuret.github.io/Knet.jl/latest/reference.html#Knet.minibatch) function and [Data](https://github.com/denizyuret/Knet.jl/blob/master/src/data.jl) iterator type.\n",
"(c) Deniz Yuret, 2019\n",
"* Objective: Load the [MNIST](http://yann.lecun.com/exdb/mnist) dataset, convert into Julia arrays, split into minibatches using Knet's [minibatch](http://denizyuret.github.io/Knet.jl/latest/reference/#Knet.minibatch) function and [Data](https://github.com/denizyuret/Knet.jl/blob/master/src/data.jl) iterator type.\n",
"* Prerequisites: [Julia arrays](https://docs.julialang.org/en/v1/manual/arrays)\n",
"* New functions: [dir](http://denizyuret.github.io/Knet.jl/latest/reference.html#Knet.dir), [minibatch, Data](http://denizyuret.github.io/Knet.jl/latest/reference.html#Knet.minibatch), [mnist, mnistview](https://github.com/denizyuret/Knet.jl/blob/master/data/mnist.jl)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the next few notebooks, we build classification models for the MNIST handwritten digit recognition dataset. MNIST has 60000 training and 10000 test examples. Each input x consists of 784 pixels representing a 28x28 image. The corresponding output indicates the identity of the digit 0..9."
"* New functions: [dir](http://denizyuret.github.io/Knet.jl/latest/reference/#Knet.dir), [minibatch, Data](http://denizyuret.github.io/Knet.jl/latest/reference/#Knet.minibatch), [mnist, mnistview](https://github.com/denizyuret/Knet.jl/blob/master/data/mnist.jl)\n",
"\n",
"In the next few notebooks, we build classification models for the MNIST handwritten digit recognition dataset. MNIST has 60000 training and 10000 test examples. Each input x consists of 784 pixels representing a 28x28 image. The corresponding output indicates the identity of the digit 0..9.\n",
"\n",
"![](http://yann.lecun.com/exdb/lenet/gifs/asamples.gif \"MNIST\")\n",
"\n",
"[image source](http://yann.lecun.com/exdb/lenet)"
]
},
{
Expand Down
Loading

0 comments on commit b82f0cc

Please sign in to comment.