Skip to content

Commit

Permalink
Add CNTK backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
chentaMS authored and fchollet committed Jun 7, 2017
1 parent 552978d commit 75d9415
Show file tree
Hide file tree
Showing 29 changed files with 3,298 additions and 609 deletions.
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ matrix:
env: KERAS_BACKEND=theano
- python: 3.5
env: KERAS_BACKEND=theano
- python: 2.7
env: KERAS_BACKEND=cntk
- python: 3.5
env: KERAS_BACKEND=cntk
install:
# code below is taken from http://conda.pydata.org/docs/travis.html
# We do this conditionally because it saves us some downloading if the
Expand Down Expand Up @@ -49,6 +53,22 @@ install:

# install TensorFlow (CPU version).
- pip install tensorflow

# install cntk
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
pip install https://cntk.ai/PythonWheel/CPU-Only/cntk-2.0-cp27-cp27mu-linux_x86_64.whl;
elif [[ "$TRAVIS_PYTHON_VERSION" == "3.5" ]]; then
pip install https://cntk.ai/PythonWheel/CPU-Only/cntk-2.0-cp35-cp35m-linux_x86_64.whl;
fi

#install open mpi
- rm -rf ~/mpi
- mkdir ~/mpi
- pushd ~/mpi
- wget http://cntk.ai/PythonWheel/ForKeras/depends/openmpi_1.10-3.zip
- unzip ./openmpi_1.10-3.zip
- sudo dpkg -i openmpi_1.10-3.deb
- popd

# command to run tests
script:
Expand Down
4 changes: 4 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ All contributions by Google:
Copyright (c) 2015, Google, Inc.
All rights reserved.

All contributions by Microsoft:
Copyright (c) 2017, Microsoft, Inc.
All rights reserved.

All other contributions:
Copyright (c) 2015 - 2017, the respective contributors.
All rights reserved.
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Keras: Deep Learning library for TensorFlow and Theano
# Keras: Deep Learning library for TensorFlow, CNTK, and Theano

[![Build Status](https://travis-ci.org/fchollet/keras.svg?branch=master)](https://travis-ci.org/fchollet/keras)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/fchollet/keras/blob/master/LICENSE)

## You have just found Keras.

Keras is a high-level neural networks API, written in Python and capable of running on top of either [TensorFlow](https://github.com/tensorflow/tensorflow) or [Theano](https://github.com/Theano/Theano). It was developed with a focus on enabling fast experimentation. *Being able to go from idea to result with the least possible delay is key to doing good research.*
Keras is a high-level neural networks API, written in Python and capable of running on top of either [TensorFlow](https://github.com/tensorflow/tensorflow) [CNTK](https://github.com/Microsoft/cntk) or [Theano](https://github.com/Theano/Theano). It was developed with a focus on enabling fast experimentation. *Being able to go from idea to result with the least possible delay is key to doing good research.*

Use Keras if you need a deep learning library that:

Expand Down Expand Up @@ -125,6 +125,11 @@ Keras uses the following dependencies:
- TensorFlow
- [See installation instructions](https://www.tensorflow.org/install/).

*When using the CNTK backend:*

- CNTK
- [See installation instructions](https://docs.microsoft.com/en-us/cognitive-toolkit/setup-cntk-on-your-machine).

*When using the Theano backend:*

- Theano
Expand All @@ -143,7 +148,7 @@ sudo pip install keras
------------------


## Switching from TensorFlow to Theano
## Switching from TensorFlow to CNTK or Theano

By default, Keras will use TensorFlow as its tensor manipulation library. [Follow these instructions](http://keras.io/backend/) to configure the Keras backend.

Expand Down
9 changes: 5 additions & 4 deletions docs/templates/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

Keras is a model-level library, providing high-level building blocks for developing deep learning models. It does not handle itself low-level operations such as tensor products, convolutions and so on. Instead, it relies on a specialized, well-optimized tensor manipulation library to do so, serving as the "backend engine" of Keras. Rather than picking one single tensor library and making the implementation of Keras tied to that library, Keras handles the problem in a modular way, and several different backend engines can be plugged seamlessly into Keras.

At this time, Keras has two backend implementations available: the **TensorFlow** backend and the **Theano** backend.
At this time, Keras has three backend implementations available: the **TensorFlow** backend, the **Theano** backend, and the **CNTK** backend.

- [TensorFlow](http://www.tensorflow.org/) is an open-source symbolic tensor manipulation framework developed by Google, Inc.
- [Theano](http://deeplearning.net/software/theano/) is an open-source symbolic tensor manipulation framework developed by LISA/MILA Lab at Université de Montréal.
- [CNTK](https://www.microsoft.com/en-us/cognitive-toolkit/) is an open-source, commercial-grade toolkit for deep learning developed by Microsoft.

In the future, we are likely to add more backend options. Go ask Microsoft about how their CNTK backend project is doing.
In the future, we are likely to add more backend options.

----

Expand All @@ -34,7 +35,7 @@ The default configuration file looks like this:
}
```

Simply change the field `backend` to either `"theano"` or `"tensorflow"`, and Keras will use the new configuration next time you run any Keras code.
Simply change the field `backend` to `"theano"`, `"tensorflow"`, or `"cntk"`, and Keras will use the new configuration next time you run any Keras code.

You can also define the environment variable ``KERAS_BACKEND`` and this will
override what is defined in your config file :
Expand Down Expand Up @@ -65,7 +66,7 @@ You can change these settings by editing `$HOME/.keras/keras.json`.
- For 3D data, `"channels_last"` assumes `(conv_dim1, conv_dim2, conv_dim3, channels)` while `"channels_first"` assumes `(channels, conv_dim1, conv_dim2, conv_dim3)`.
* `epsilon`: float, a numeric fuzzing constant used to avoid dividing by zero in some operations.
* `floatx`: string, `"float16"`, `"float32"`, or `"float64"`. Default float precision.
* `backend`: string, `"tensorflow"` or `"theano"`.
* `backend`: string, `"tensorflow"`, `"theano"`, or `"cntk"`.

----

Expand Down
2 changes: 1 addition & 1 deletion docs/templates/getting-started/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Please cite Keras in your publications if it helps your research. Here is an exa

### How can I run Keras on GPU?

If you are running on the TensorFlow backend, your code will automatically run on GPU if any available GPU is detected.
If you are running on the TensorFlow or CNTK backends, your code will automatically run on GPU if any available GPU is detected.

If you are running on the Theano backend, you can use one of the following methods:

Expand Down
2 changes: 1 addition & 1 deletion docs/templates/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Keras: Deep Learning library for Theano and TensorFlow
# Keras: The Python Deep Learning library

{{autogenerated}}
9 changes: 6 additions & 3 deletions keras/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
_epsilon = _config.get('epsilon', epsilon())
assert isinstance(_epsilon, float)
_backend = _config.get('backend', _BACKEND)
assert _backend in {'theano', 'tensorflow'}
assert _backend in {'theano', 'tensorflow', 'cntk'}
_image_data_format = _config.get('image_data_format',
image_data_format())
assert _image_data_format in {'channels_last', 'channels_first'}
Expand Down Expand Up @@ -68,11 +68,14 @@
# Set backend based on KERAS_BACKEND flag, if applicable.
if 'KERAS_BACKEND' in os.environ:
_backend = os.environ['KERAS_BACKEND']
assert _backend in {'theano', 'tensorflow'}
assert _backend in {'theano', 'tensorflow', 'cntk'}
_BACKEND = _backend

# Import backend functions.
if _BACKEND == 'theano':
if _BACKEND == 'cntk':
sys.stderr.write('Using CNTK backend\n')
from .cntk_backend import *
elif _BACKEND == 'theano':
sys.stderr.write('Using Theano backend.\n')
from .theano_backend import *
elif _BACKEND == 'tensorflow':
Expand Down
Loading

0 comments on commit 75d9415

Please sign in to comment.