Run Keras with CNTK backend from CentOS

Run Keras with CNTK backend from CentOS

Keras now supports CNTK. https://docs.microsoft.com/en-us/cognitive-toolkit/Using-CNTK-with-Keras

I installed it and tried it, so I will introduce the procedure.

environment

CentOS 7.3 and Python 3.5, CPU only. Looking at the Microsoft site, only Ubuntu is written about how to build a Linux environment, but Centos 7.3 also worked fine. (Boyaki: Deep learning has become the strongest in Ubuntu.)

CNTK installation

The official procedure is below. https://docs.microsoft.com/en-us/cognitive-toolkit/setup-linux-python?tabs=cntkpy21

Here, we will show you how to install it on Centos 7.3.

First, install Anaconda3. Select the version from the following and install it. https://www.continuum.io/downloads

If you want to install from the command line, you can install it as follows.

wget https://repo.continuum.io/archive/Anaconda3-4.3.1-Linux-x86_64.sh
bash Anaconda3-4.3.1-Linux-x86_64.sh -b -p /opt/anaconda3
echo 'export PATH="/opt/anaconda3/bin:$PATH"' >> /etc/profile
source /etc/profile

CNTK requires OpenMPI. Install it on CentOS7.3 with the following and set environment variables as well.

yum -y install openmpi openmpi-devel
export PATH=/usr/lib64/openmpi/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH

It's finally time to install CNTK. Specify the URL that suits your environment with pip install. For Linux, CPUonly, Python3.5, it will be as follows.

pip install https://cntk.ai/PythonWheel/CPU-Only/cntk-2.1-cp35-cp35m-linux_x86_64.whl

Below is a list of URLs to specify. https://docs.microsoft.com/en-us/cognitive-toolkit/setup-linux-python?tabs=cntkpy21

If the installation is successful, you can see the CNTK version below.

python -c "import cntk; print(cntk.__version__)"

1.PNG

Sample programs and tutorials are available below.

python -m cntk.sample_installer

Use with Keras

You need to change the backend to use CNTK with Keras. https://keras.io/ja/backend/

The backend is changed in /User'sHOME/.keras/keras.json, but at this stage the .keras directory is not yet there. You need to call Keras from Python once and create it.

python -c "import keras"

2.PNG

I think TensorFlow is the backend by default. Edit /User'sHOME/.keras/keras.json.

#Before editing
{
    "floatx": "float32",
    "image_data_format": "channels_last",
    "epsilon": 1e-07,
    "backend": "cntk"
}

#After editing
{
    "floatx": "float32",
    "image_data_format": "channels_last",
    "epsilon": 1e-07,
    "backend": "cntk"
}

You can now use Keras with the CNTK backend.

If you do import Keras on Jupyter Notebook, you can see that the backend is CNTK.

3.PNG

For the time being, MNIST

For the time being, I tried running the MNIST MLP sample. https://github.com/fchollet/keras/blob/master/examples/mnist_mlp.py

It is such a network.

4.PNG

The program works as it is from the existing Keras. No editing required.

Overview and results --Training data: 60,000 28x28 images --Test data: 10000 28x28 images --Batch size: 128 --Epoch: 20 --CNTK backend training time: 314 seconds --CNTK backend test results: Loss 0.106430094829, Accuracy 0.9835

Digression

There are a lot of deep learning frameworks, but DL4J makes a comparison. It is surprisingly well organized. https://deeplearning4j.org/ja/compare-dl4j-torch7-pylearn

Recommended Posts

Run Keras with CNTK backend from CentOS
Use the Cognitive Took Kit (CNTK) with the Keras backend
Run Aprili from Python with Orange
Boot CentOS 8 from Windows 10 with Wake On LAN
Run Flask on CentOS with python3.4, Gunicorn + Nginx.
Play with CentOS 8
Run with CentOS7 + Apache2.4 + Python3.6 for the time being
Identify the name from the flower image with keras (tensorflow)
Run iphone safari from mac with python + selenium + safari-webdriver
Run prepDE.py with python3
Image recognition with keras
Run python from excel
Keras starting from nothing
Run Blender with python
CIFAR-10 tutorial with Keras
Multivariate LSTM with Keras
Run BigQuery from Lambda
Run iperf with python
[TensorFlow 2 / Keras] How to run learning with CTC Loss in Keras
Connect to centos6 on virtualbox with ssh connection from Mac