2018年4月24日火曜日

Run keras on android with CNTK backend

[Abstract]
Run keras with CNTK backend on ArchLinux (TermuxArch) on android.

[Details]
-Prepare TermuxArch, OpenBLAS and etc.
See below URL for the details.
http://oregaji.blogspot.jp/2018/04/how-to-create-keras-development.html?m=1

-Build CNTK from source code.
-Build procedure is the below.
https://docs.microsoft.com/en-us/cognitive-toolkit/Setup-CNTK-on-Linux#quick-test-of-cntk-build-functionality

-Install protobuf via pacman.
-Modify CNTK/configure. Replace string "libprotobuf.a" to "libprotobuf.so"
(In my environment, there is no libprotobuf.a file...)

> pacman -S swig
> mkdir -p build/release
> cd build/release
> ../../configure --with-openblas=/usr/local --with-swig --with-py36-path

-Modify CNTK/Makefile. Replace from
SSE_FLAGS = -msse4.1 -mssse3
to
SSE_FLAGS =

> make -j 2 all

- if sys/io.h not found Error occured, fix source code to sys/uio.h

-if failed to build Multiverso, build and install Multiverso manually.
> cd CNTK/Source/Multiverso
> cmake
> make
> make install
And comment out Multiverso part from CNTK/Makefile.
> cd CNTK
> make -j 2 all

After build success,
("make install" is not available, So...)
> cd build/release
> cp bin/cntk bin/cntk.core.bs /usr/local/bin/
> cp -r /usr/local/lib

(libmpi.so.12 not found error will happen when running cntk. So, create symlink.)
> ln -s /usr/lib/openmpi/libmpi.so /usr/lib/openmpi/libmpi.so.12

-Install python bindings.
> cd CNTK/bindins/python
> python setup.py install

-Set keras backend to CNTK.
Modify ~/.keras/keras.json as "backend": "cntk"

-Run keras MNIST sample.
-Do git clone keras.
> cd keras/keras/example
> python mnist_cnn.py
If it works well, CNTK backend  installation success!
In my 2017 high-end smartphone, It takes about 33 minites per 1 epoch.
It's slower than mxnet backend in my environment...

0 件のコメント:

コメントを投稿