2018年4月15日日曜日

How to create Keras development environment on Android at April 2018.

[Abstract]
Creating Keras development environment in order to develop Deep Learning anytime, anywhere.

[Conclusion]
-This environment is too slow to learn data firmly, but this is useful to try tiny Keras code quickly.
-It's useful to be available full Linux distribution on the smartphone.
-Perfect development environment while sleeping in the bedroom have been constructed! :-)

[Install procedure]
-Install Termux from Google Play.
-Install Hacker's keyboard from Google Play too.
-Install ArchLinux via TermuxArch (https://sdrausty.github.io/TermuxArch/)
(-Install yaourt) *optional (https://wiki.archlinux.jp/index.php/Yaourt)
-Build and install OpenBLAS. (https://github.com/xianyi/OpenBLAS)
-Build and install mxnet. (https://github.com/apache/incubator-mxnet)
-Install latest version keras which support mxnet_backend.

[Difficult points of install]
-In some device, "proot" of termux apt-get causes error on execute. So get termux/proot from github and build from source and install. Then success.
-ArchLinux on TermuxArch works on user privilege in proot file system container. So, some command which require real root privilege will be failed.
-Server URL for yaourt AUR in /etc/pacman.conf must be
Server = http://repo.archlinux.fr/arm
not
Server = http://repo.archlinux.fr/$arch
-fix /usr/bin/makepkg as https://github.com/sdrausty/TermuxArch/issues/38. Then yaourt is available.

-Build and install OpenBLAS from source.
-Use make command for building OpenBLAS, not use cmake command.

-Add link path and include path like followings.
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$LD_LIBRARY_PATH
export CPATH=/usr/local/include:$CPATH

-Install openmp and others via pacman -S command before building mxnet.
-Use "git clone --recursive" to get mxnet source code.
-Use cmake command for building mxnet.
-Fix CMakeLists.txt. add the following line just under add_library(mxnet_static STATIC ${SOURCE}).
   set_property(TARGET mxnet_static PROPERTY POSITION_INDEPENDENT_CODE ON)
Shared library works well by this.
-Use clang for building mxnet. gcc causes halt on compling some place of code.
-Use clang by the following.
> cmake -C ~/use-clang.cmake ..
~/use-clang.cmake is like followings:
set(CMAKE_C_COMPILER "/usr/bin/clang" CACHE string "clang compiler" FORCE)
set(CMAKE_CXX_COMPILER "/usr/bin/clang++" CACHE string "clang++ compiler" FORCE)
set(CMAKE_ASM_COMPILER "/usr/bin/clang")
#set(CMAKE_SYSTEM_PROCESSOR "aarch64")

-At building mxnet, do follow commands.
> cmake -C ~/use-clang.cmake ..
> ccmake -C ~/use-clang.cmake ..
-In ccmake command, turn off build sample, cuda related, mkl related, atlas, gperftools(tcmalloc), jemalloc, opencv, sse.
-Turn BUILD_SHARED on.
-Set BLAS=Open.
-Press "c" after setting ccmake.
> cmake -C ~/use-clang.cmake ..
> make -j 4
-It takes about 20 minites to build mxnet.
> make install
> mv /usr/local/lib64/libmxnet.a /usr/local/lib/
> mv /usr/local/lib64/libmxnet.so /usr/local/lib/

-In python3, install cython, setuptools, keras(keras_mxnet==2.1.5b3 latest version which support keras2_mxnet_backend) and others via pip command.
> cd python/
> python setup.py install

- Do git clone keras.
> cd keras/keras/example
> python mnist_cnn.py
If it works well, keras installation success!
In my 2017 high-end smartphone, It takes 24 minites per 1 epoch.

0 件のコメント:

コメントを投稿