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.
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.)
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__)"
Sample programs and tutorials are available below.
python -m cntk.sample_installer
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"
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.
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.
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
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