Micah P. Dombrowski / Jul 16 2018
Keras CNTK Setup
Keras CNTK Setup
1. Installs
1.
Installs
1.1. GPU
1.1.
GPU
apt-get update > /dev/null apt-get install -y gnupg dpkg -i --no-debsig \ libcudnn7_7.1.4.18-1+cuda8.0_amd64.deb↩ \ libcudnn7-dev_7.1.4.18-1+cuda8.0_amd64.deb↩ \ nccl-repo-ubuntu1604-2.2.13-ga-cuda8.0_1-1_amd64.deb↩ sudo apt-key add /var/nccl-repo-2.2.13-ga-cuda8.0/7fa2af80.pub echo "pip >=10" >> /opt/conda/conda-meta/pinned # prevent downgrade by -c intel conda install -qy -c mpi4py -c intel -c anaconda \ openmpi=1.10 mkl-dnn opencv anaconda::tbb \ h5py graphviz pydot scipy cython ldconfig
CNTK_FILE="/tmp/cntk-2.3.1-cp36-cp36m-linux_x86_64.whl" cp cntk_gpu-2.3.1-cp36-cp36m-linux_x86_64.whl↩ $CNTK_FILE pip install $CNTK_FILE rm $CNTK_FILE
pip install keras # need a config file to use CNTK mkdir ~/.keras echo '{ "epsilon": 1e-07, "image_data_format": "channels_last", "backend": "cntk", "floatx": "float32" }' > ~/.keras/keras.json # make sure we're using the right libs echo '/opt/conda/lib' > /etc/ld.so.conf.d/conda.conf ldconfig
1.2. CPU
1.2.
CPU
CNTK_FILE="/tmp/cntk-2.3.1-cp36-cp36m-linux_x86_64.whl" cp cntk-2.3.1-cp36-cp36m-linux_x86_64.whl↩ $CNTK_FILE pip install $CNTK_FILE rm $CNTK_FILE
2. Python 2
2.
Python 2
2.1. GPU
2.1.
GPU
CNTK_FILE="/tmp/cntk-2.3.1-cp27-cp27mu-linux_x86_64.whl" cp cntk_gpu-2.3.1-cp27-cp27mu-linux_x86_64.whl↩ $CNTK_FILE pip install $CNTK_FILE rm $CNTK_FILE
2.2. CPU
2.2.
CPU
CNTK_FILE="/tmp/cntk-2.3.1-cp27-cp27mu-linux_x86_64.whl" cp cntk-2.3.1-cp27-cp27mu-linux_x86_64.whl↩ $CNTK_FILE pip install $CNTK_FILE rm $CNTK_FILE
3. Tests
3.
Tests
from keras.models import Sequential from keras.layers import Dense, Activation # For a single-input model with 2 classes (binary classification): model = Sequential() model.add(Dense(32, activation='relu', input_dim=100)) model.add(Dense(1, activation='sigmoid')) model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['accuracy']) # Generate dummy data import numpy as np data = np.random.random((1000, 100)) labels = np.random.randint(2, size=(1000, 1)) # Train the model, iterating on the data in batches of 32 samples model.fit(data, labels, epochs=10, verbose=2, batch_size=32)