Saturday, February 20, 2016

A complete guide to install Theano and Keras in windows + BLAS libray

The first step: 

For my case, to install theano  I followed the following link:
http://stackoverflow.com/questions/33687103/how-to-install-theano-on-anaconda-python-2-7-x64-on-windows

The second step:

As the Keras is run on top of theano, install the theano is required before installing Keras. To ensure the Keras can run correctly, be sure to install the latest version of Theano. For example, if you meet following error when runing Theano:
"max_pool_2d() got an unexpected keyword argument 'mode' "
which means that you are in old version. If you have already installed the old version of Theano, you can update it to the latest version by following command in cmd window:
You can upgrade by typing pip install -r https://raw.githubusercontent.com/Lasagne/Lasagne/master/requirements.txt

This command uses the 'git', if you didn't install it on window, you can install GIT by following link:
https://git-scm.com/

After your above installation, you need to add its path to the system variable. Following below link to add your path for GIT. There are several different instructions in the thread, please find a correct one for you case. 
http://stackoverflow.com/questions/26620312/installing-git-in-path-with-github-client-for-windows

Check your installation for git by ' git --version' in the cmd (Make sure re-open the cmd window to check).


Third step (if needed): 

Up to now, you can check you Theano in cmd window by
(restart your cmd window first please)
python
import theano
theano.test()

If passed, you are done. If you got following error:
Problem occurred during compilation with the command line below:
g++.exe -shared -g -O3 -fno-math-errno -Wno-unused-label -Wno-unused-variable -Wno-write-strings -march=haswell -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mmovbe -maes -mno-sha -mpclmul -mpopcnt -mabm -mno-lwp -mfma -mno-fma4 -mno-xop -mbmi -mbmi2 -mno-tbm -mavx -mavx2 -msse4.2 -msse4.1 -mlzcnt -mrtm -mhle -mrdrnd -mf16c -mfsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=haswell -D NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION -m64 -DMS_WIN64 -IC:\scisoft\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\lib\site-packages\numpy\core\include -IC:\scisoft\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\include -IC:\scisoft\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\lib\site-packages\theano\gof -o C:\Users\Michal\AppData\Local\Theano\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-3.4.3-64\tmpgdh7ov2i\mf217e5b3a6b61b4ef70844368439f6cb.pyd C:\Users\Michal\AppData\Local\Theano\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-3.4.3-64\tmpgdh7ov2i\mod.cpp -LC:\scisoft\WinPython-64bit-3.4.3.7\python-3.4.3.amd64\libs -LC:\scisoft\WinPython-64bit-3.4.3.7\python-3.4.3.amd64 -lpython34
or 
Exception: ('The following error happened while compiling the node', CorrMM{valid, (1, 1)}(input.input, Subtensor{::, ::, ::int64, ::int64}.0), '\n', "Compilation failed (return status=1): C:\\Users\\Michal\\AppData\\Local\\Theano\\compiledir_Windows-8-6.2.9200-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-3.4.3-64\\tmpgdh7ov2i\\mod.cpp: In member function 'int {anonymous}::__struct_compiled_op_mf217e5b3a6b61b4ef70844368439f6cb::r
It means your BLAS library is in trouble. Please follow the post of "IshanAntony" in #7 in following thread:
https://www.kaggle.com/c/otto-group-product-classification-challenge/forums/t/13973/a-few-tips-to-install-theano-on-windows-64-bits

and then follow the posts of #13, #15 and #19 in above thread to set the THEANO_FLAG, PATH and modify the path in blas.py.

Now, I believe every thing should be done.

Final step: 

If you believe everything is done, it's a better way to close all related windows, like cmd, spyder, ....., then reopen them again to check!!
For my case, it works when I reopen spyder. otherwise, it still looks weird.