Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
update installation instruction for deep learning
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Aug 20, 2017
1 parent dd6234c commit 97807fc
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 80 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Setup
(do not add the interpreter on the default PATH)
* `R 3.2.2 <https://cran.r-project.org/bin/windows/base/old/3.2.2/>`_
* `Scite <http://www.scintilla.org/SciTE.html>`_
* `TDM-GCC 64bit <http://tdm-gcc.tdragon.net/>`_ (theano)
* `mingw-w64 <https://mingw-w64.org/doku.php>`_ (theano)
* `Visual Studio 2015 Community Edition <https://www.visualstudio.com/fr/vs/community/>`_
(check C++, C#, Python, CLang) (Cython)

Expand Down
130 changes: 60 additions & 70 deletions _doc/notebooks/td2a_ml/ml_deep_python.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -21,12 +19,11 @@
"<script>\n",
"function repeat_indent_string(n){\n",
" var a = \"\" ;\n",
" for ( ; n > 0 ; --n) {\n",
" for ( ; n > 0 ; --n)\n",
" a += \" \";\n",
" }\n",
" return a;\n",
"}\n",
"var update_menu_string = function(begin, lfirst, llast, sformat, send, keep_item) {\n",
"var update_menu_string = function(begin, lfirst, llast, sformat, send, keep_item, begin_format, end_format) {\n",
" var anchors = document.getElementsByClassName(\"section\");\n",
" if (anchors.length == 0) {\n",
" anchors = document.getElementsByClassName(\"text_cell_render rendered_html\");\n",
Expand All @@ -39,9 +36,9 @@
" var href;\n",
" var tags = [];\n",
" var main_item = 0;\n",
" for (i = 0; i <= llast; i++) {\n",
" var format_open = 0;\n",
" for (i = 0; i <= llast; i++)\n",
" tags.push(\"h\" + i);\n",
" }\n",
"\n",
" for (i = 0; i < anchors.length; i++) {\n",
" text_memo += \"**\" + anchors[i].id + \"--\\n\";\n",
Expand All @@ -54,7 +51,7 @@
"break;\n",
" }\n",
" }\n",
" if (child == null){\n",
" if (child == null) {\n",
" text_memo += \"null\\n\";\n",
" continue;\n",
" }\n",
Expand Down Expand Up @@ -82,15 +79,16 @@
" continue ;\n",
" }\n",
" if (title.endsWith('\u00b6')) {\n",
" title = title.substring(0,title.length-1).replace(\"<\", \"&lt;\").replace(\">\", \"&gt;\").replace(\"&\", \"&amp;\")\n",
" title = title.substring(0,title.length-1).replace(\"<\", \"&lt;\")\n",
" .replace(\">\", \"&gt;\").replace(\"&\", \"&amp;\");\n",
" }\n",
"\n",
" if (title.length == 0) {\n",
" continue;\n",
" }\n",
"\n",
" while (level < memo_level) {\n",
" text_menu += \"</ul>\\n\";\n",
" text_menu += end_format + \"</ul>\\n\";\n",
" format_open -= 1;\n",
" memo_level -= 1;\n",
" }\n",
" if (level == lfirst) {\n",
Expand All @@ -104,22 +102,33 @@
" text_menu += \"<ul>\\n\";\n",
" memo_level += 1;\n",
" }\n",
" text_menu += repeat_indent_string(level-2) + sformat.replace(\"__HREF__\", href).replace(\"__TITLE__\", title);\n",
" text_menu += repeat_indent_string(level-2);\n",
" text_menu += begin_format + sformat.replace(\"__HREF__\", href).replace(\"__TITLE__\", title);\n",
" format_open += 1;\n",
" }\n",
" while (1 < memo_level) {\n",
" text_menu += \"</ul>\\n\";\n",
" text_menu += end_format + \"</ul>\\n\";\n",
" memo_level -= 1;\n",
" format_open -= 1;\n",
" }\n",
" text_menu += send;\n",
" //text_menu += \"\\n\" + text_memo;\n",
"\n",
" while (format_open > 0) {\n",
" text_menu += end_format;\n",
" format_open -= 1;\n",
" }\n",
" return text_menu;\n",
"};\n",
"var update_menu = function() {\n",
" var sbegin = \"\";\n",
" var sformat = '<li><a href=\"#__HREF__\">__TITLE__</a></li>';\n",
" var sformat = '<a href=\"#__HREF__\">__TITLE__</a>';\n",
" var send = \"\";\n",
" var begin_format = '<li>';\n",
" var end_format = '</li>';\n",
" var keep_item = -1;\n",
" var text_menu = update_menu_string(sbegin, 2, 4, sformat, send, keep_item);\n",
" var text_menu = update_menu_string(sbegin, 2, 4, sformat, send, keep_item,\n",
" begin_format, end_format);\n",
" var menu = document.getElementById(\"my_id_menu_nb\");\n",
" menu.innerHTML=text_menu;\n",
"};\n",
Expand All @@ -143,9 +152,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
Expand All @@ -163,14 +170,7 @@
"\n",
"[documentation](http://deeplearning.net/software/theano/index.html) [tutorial MNIST](http://deeplearning.net/tutorial/logreg.html) [tutorial Logisitic Regression](http://deeplearning.net/tutorial/logreg.html)\n",
"\n",
"Le module [theano](http://deeplearning.net/software/theano/) propose une API pour \u00e9crire des algorithmes num\u00e9riques utilisant le [GPU](https://en.wikipedia.org/wiki/Graphics_processing_unit). Il n'est pas sp\u00e9cialis\u00e9 dans le deep learning m\u00eame s'il propose de nombreuses fonctionnalit\u00e9s pour cela. Le module impl\u00e9mente ses propres container. Il faut voir [theano](http://deeplearning.net/software/theano/) comme une sorte de *numpy GPU*. Le module est \u00e9crit de telle sorte qu'il cherche \u00e0 optimiser la vitesse de calcul en transformant le code Python en C++ qui est ensuite compil\u00e9. Sous Linux, le compilateur est int\u00e9gr\u00e9. Sous Windows, il faut installer [TDM 64bit](http://tdm-gcc.tdragon.net/). L'absence du compilateur se traduit par :"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"WARNING (theano.configdefaults): g++ not detected !"
"Le module [theano](http://deeplearning.net/software/theano/) propose une API pour \u00e9crire des algorithmes num\u00e9riques utilisant le [GPU](https://en.wikipedia.org/wiki/Graphics_processing_unit). Il n'est pas sp\u00e9cialis\u00e9 dans le deep learning m\u00eame s'il propose de nombreuses fonctionnalit\u00e9s pour cela. Le module impl\u00e9mente ses propres container. Il faut voir [theano](http://deeplearning.net/software/theano/) comme une sorte de *numpy GPU*. Le module est \u00e9crit de telle sorte qu'il cherche \u00e0 optimiser la vitesse de calcul en transformant le code Python en C++ qui est ensuite compil\u00e9. Pour l'installation et notamment un compilateur C++, il faut le d\u00e9but de la partie relative au [deep learning](http://www.xavierdupre.fr/app/ensae_teaching_cs/helpsphinx3/td_2a_mlplus.html#deep-learning)."
]
},
{
Expand All @@ -194,24 +194,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Using Theano backend.\n",
"WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to execute optimized C-implementations (for both CPU and GPU) and will default to Python implementations. Performance will be severely degraded. To remove this warning, set Theano flags cxx to an empty string.\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading data from https://s3.amazonaws.com/img-datasets/mnist.pkl.gz\n",
"15269888/15296311 [============================>.] - ETA: 0s"
"Using TensorFlow backend.\n"
]
}
],
Expand All @@ -223,9 +212,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -252,15 +239,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from keras.datasets import mnist\n",
"from keras.models import Sequential\n",
"from keras.layers import Dense, Dropout, Activation, Flatten\n",
"from keras.layers import Convolution2D, MaxPooling2D\n",
"from keras.layers import Conv2D, MaxPooling2D\n",
"from keras.utils import np_utils\n",
"from keras import backend as K\n",
"\n",
Expand Down Expand Up @@ -294,9 +279,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -308,7 +291,7 @@
{
"data": {
"text/plain": [
"<keras.models.Sequential at 0x1de63e52160>"
"<keras.models.Sequential at 0x21d2848dd68>"
]
},
"execution_count": null,
Expand All @@ -332,11 +315,9 @@
" else:\n",
" input_shape = (img_rows, img_cols, 1)\n",
"\n",
" model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1],\n",
" border_mode='valid',\n",
" input_shape=input_shape))\n",
" model.add(Conv2D(nb_filters, kernel_size, padding='valid', input_shape=input_shape))\n",
" model.add(Activation('relu'))\n",
" model.add(Convolution2D(nb_filters, kernel_size[0], kernel_size[1]))\n",
" model.add(Conv2D(nb_filters, kernel_size))\n",
" model.add(Activation('relu'))\n",
" model.add(MaxPooling2D(pool_size=pool_size))\n",
" model.add(Dropout(0.25))\n",
Expand Down Expand Up @@ -367,40 +348,48 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[keras_fit] nb_classes=10\n",
"Train on 60000 samples, validate on 10000 samples\n",
"Epoch 1/1\n"
"Epoch 1/1\n",
"60000/60000 [==============================] - 123s - loss: 0.3694 - acc: 0.8873 - val_loss: 0.0883 - val_acc: 0.9721\n"
]
}
],
"source": [
"def keras_fit(model, X_train, Y_train, X_test, Y_test, batch_size=128,\n",
" nb_classes=None, nb_epoch=12):\n",
" nb_classes=None, epochs=12):\n",
" if nb_classes is None:\n",
" nb_classes = Y_train.shape[1]\n",
" print(\"[keras_fit] nb_classes=%d\" % nb_classes)\n",
" model.fit(X_train, Y_train, batch_size=batch_size, nb_epoch=nb_epoch,\n",
" model.fit(X_train, Y_train, batch_size=batch_size, epochs=epochs,\n",
" verbose=1, validation_data=(X_test, Y_test))\n",
" \n",
"keras_fit(model, X_train, Y_train, X_test, Y_test, batch_size=128,\n",
" nb_classes=None, nb_epoch=1) "
" nb_classes=None, epochs=1) "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[0.088284374502673749, 0.97209999999999996]"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def keras_predict(model, X_test, Y_test):\n",
" return model.evaluate(X_test, Y_test, verbose=0)\n",
Expand All @@ -414,7 +403,7 @@
"source": [
"## tensorflow\n",
"\n",
"[tensorflow](https://www.tensorflow.org/) uniquement sous Linux"
"[tensorflow](https://www.tensorflow.org/)"
]
},
{
Expand All @@ -432,7 +421,7 @@
"source": [
"## CNTK\n",
"\n",
"[CNTK](https://github.com/Microsoft/CNTK/wiki), bient\u00f4t accessible depuis Python, uniquement en ligne de commande."
"[CNTK](https://docs.microsoft.com/en-us/cognitive-toolkit/)"
]
},
{
Expand All @@ -451,7 +440,8 @@
"## Comparatifs\n",
"\n",
"* [DL4J vs. Torch vs. Theano vs. Caffe vs. TensorFlow](https://deeplearning4j.org/compare-dl4j-torch7-pylearn)\n",
"* [Evaluation of Deep Learning Toolkits](https://github.com/zer0n/deepframeworks/blob/master/README.md)"
"* [Evaluation of Deep Learning Toolkits](https://github.com/zer0n/deepframeworks/blob/master/README.md)\n",
"* [Benchmarking CNTK on Keras: is it Better at Deep Learning than TensorFlow?](http://minimaxir.com/2017/06/keras-cntk/) (2017)"
]
},
{
Expand Down Expand Up @@ -480,7 +470,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.0"
"version": "3.6.1"
}
},
"nbformat": 4,
Expand Down
26 changes: 26 additions & 0 deletions _doc/sphinxdoc/source/blog/2017/2017-08-20_theano_keras_tf.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

.. blogpost::
:title: Installer theano et un compilateur C++
:keywords: python, theano, keras
:date: 2017-08-20
:categories: modules
:lid: blog-install-theno-keras

epkg:`theano` est un module difficile à installer
car il utilise une compilation C++ pour optimiser les
calculer que le programmeur demmande. Cela veut dire qu'il
fait appel à un compilateur C++ pour convertir des instructions
:epkg:`Python` en un code qui s'exécute rapidement.
Les portables ont peu souvent des processeurs GPU mais rien n'empêche
de développer un programme de deep learning en CPU d'abord.
C'est plus facile sous Linux (ou sous
`Windows Subsystem for Linux <https://blogs.windows.com/buildingapps/2017/08/08/windows-subsystem-linux-windows-server/>`_.
Il suffit d'installer `g++ <https://en.wikipedia.org/wiki/GNU_Compiler_Collection>`_ :

::

sudo apt-get install g++

Sous Windows, c'est un peu plus compliqué mais à peine plus long.
Il faut lire l'article de blog :
`Theano and Mingw <http://www.xavierdupre.fr/app/pymyinstall/helpsphinx/blog/2017/2017-08-17_theano.html>`_.
Loading

0 comments on commit 97807fc

Please sign in to comment.