close
The Wayback Machine - https://web.archive.org/web/20190803122103/https://github.com/keras-team/keras
Skip to content
Deep Learning for humans
Python Other
  1. Python 99.9%
  2. Other 0.1%
Branch: master
Clone or download
farizrahman4u and fchollet RNN initial state: bug fix + suppress false warning (#13138)
* suppress serde warning

* add test

* pep8

* python2

* theano fix

* theano fix

* pop before call

* few fixes

* fix wrappers

* mooore fix
Latest commit c10d249 Jul 26, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Image .github Update a--tensorflow-backend-users.md (#12644) Apr 12, 2019
Image .travis Skipping the CNTK install in some travis jobs to speed up tests (#11562) Nov 5, 2018
Image docker Docker WORKDIR should be /data (#11991) Jan 9, 2019
Image docs Sync up with keras-applications (#13044) Jul 3, 2019
Image examples Update pretrained_word_embeddings.py (#13073) Jul 9, 2019
Image keras RNN initial state: bug fix + suppress false warning (#13138) Jul 25, 2019
Image tests RNN initial state: bug fix + suppress false warning (#13138) Jul 25, 2019
Image .coveragerc Exclude the numpy backend when reporting coverages (#12493) Mar 17, 2019
Image .gitignore Update gitignore Dec 1, 2018
Image .travis.yml .travis.yml: The 'sudo' tag is now deprecated in Travis CI (#12842) May 21, 2019
Image CONTRIBUTING.md Update strings from Python 3.5 to 3.6 (#9062) Jan 12, 2018
Image ISSUE_TEMPLATE.md updated links to point to the new new githup repo (#8790) Dec 14, 2017
Image LICENSE Updated the copyright years (#12506) Mar 17, 2019
Image MANIFEST.in Update CONTRIBUTING.md and include it in future releases. Nov 8, 2017
Image PULL_REQUEST_TEMPLATE.md Added pull request templates. (#12135) Jan 28, 2019
Image README.md Updated README.md for windows users (#12780) May 2, 2019
Image pytest.ini Suppress several warnings (#12496) Mar 17, 2019
Image setup.cfg Update setup.py and setup.cfg for pypi release Jun 14, 2015
Image setup.py Made the docstring processing test more robust by parsing with markdo… Dec 2, 2018
Image update_api.py Add pyux test (#12137) Feb 24, 2019

README.md

Keras: Deep Learning for humans

Keras logo

Build Status license

You have just found Keras.

Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlow, CNTK, or 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:

  • Allows for easy and fast prototyping (through user friendliness, modularity, and extensibility).
  • Supports both convolutional networks and recurrent networks, as well as combinations of the two.
  • Runs seamlessly on CPU and GPU.

Read the documentation at Keras.io.

Keras is compatible with: Python 2.7-3.6.


Guiding principles

  • User friendliness. Keras is an API designed for human beings, not machines. It puts user experience front and center. Keras follows best practices for reducing cognitive load: it offers consistent & simple APIs, it minimizes the number of user actions required for common use cases, and it provides clear and actionable feedback upon user error.

  • Modularity. A model is understood as a sequence or a graph of standalone, fully configurable modules that can be plugged together with as few restrictions as possible. In particular, neural layers, cost functions, optimizers, initialization schemes, activation functions and regularization schemes are all standalone modules that you can combine to create new models.

  • Easy extensibility. New modules are simple to add (as new classes and functions), and existing modules provide ample examples. To be able to easily create new modules allows for total expressiveness, making Keras suitable for advanced research.

  • Work with Python. No separate models configuration files in a declarative format. Models are described in Python code, which is compact, easier to debug, and allows for ease of extensibility.


Getting started: 30 seconds to Keras

The core data structure of Keras is a model, a way to organize layers. The simplest type of model is the Sequential model, a linear stack of layers. For more complex architectures, you should use the Keras functional API, which allows to build arbitrary graphs of layers.

Here is the Sequential model:

from keras.models import Sequential

model = Sequential()

Stacking layers is as easy as .add():

from keras.layers import Dense

model.add(Dense(units=64, activation='relu', input_dim=100))
model.add(Dense(units=10, activation='softmax'))

Once your model looks good, configure its learning process with .compile():

model.compile(loss='categorical_crossentropy',
              optimizer='sgd',
              metrics=['accuracy'])

If you need to, you can further configure your optimizer. A core principle of Keras is to make things reasonably simple, while allowing the user to be fully in control when they need to (the ultimate control being the easy extensibility of the source code).

model.compile(loss=keras.losses.categorical_crossentropy,
              optimizer=keras.optimizers.SGD(lr=0.01, momentum=0.9, nesterov=True))

You can now iterate on your training data in batches:

# x_train and y_train are Numpy arrays --just like in the Scikit-Learn API.
model.fit(x_train, y_train, epochs=5, batch_size=32)

Alternatively, you can feed batches to your model manually:

model.train_on_batch(x_batch, y_batch)

Evaluate your performance in one line:

loss_and_metrics = model.evaluate(x_test, y_test, batch_size=128)

Or generate predictions on new data:

classes = model.predict(x_test, batch_size=128)

Building a question answering system, an image classification model, a Neural Turing Machine, or any other model is just as fast. The ideas behind deep learning are simple, so why should their implementation be painful?

For a more in-depth tutorial about Keras, you can check out:

In the examples folder of the repository, you will find more advanced models: question-answering with memory networks, text generation with stacked LSTMs, etc.


Installation

Before installing Keras, please install one of its backend engines: TensorFlow, Theano, or CNTK. We recommend the TensorFlow backend.

You may also consider installing the following optional dependencies:

Then, you can install Keras itself. There are two ways to install Keras:

  • Install Keras from PyPI (recommended):

Note: These installation steps assume that you are on a Linux or Mac environment. If you are on Windows, you will need to remove sudo to run the commands below.

sudo pip install keras

If you are using a virtualenv, you may want to avoid using sudo:

pip install keras
  • Alternatively: install Keras from the GitHub source:

First, clone Keras using git:

git clone https://github.com/keras-team/keras.git

Then, cd to the Keras folder and run the install command:

cd keras
sudo python setup.py install

Configuring your Keras backend

By default, Keras will use TensorFlow as its tensor manipulation library. Follow these instructions to configure the Keras backend.


Support

You can ask questions and join the development discussion:

You can also post bug reports and feature requests (only) in GitHub issues. Make sure to read our guidelines first.


Why this name, Keras?

Keras (κέρας) means horn in Greek. It is a reference to a literary image from ancient Greek and Latin literature, first found in the Odyssey, where dream spirits (Oneiroi, singular Oneiros) are divided between those who deceive men with false visions, who arrive to Earth through a gate of ivory, and those who announce a future that will come to pass, who arrive through a gate of horn. It's a play on the words κέρας (horn) / κραίνω (fulfill), and ἐλέφας (ivory) / ἐλεφαίρομαι (deceive).

Keras was initially developed as part of the research effort of project ONEIROS (Open-ended Neuro-Electronic Intelligent Robot Operating System).

"Oneiroi are beyond our unravelling --who can be sure what tale they tell? Not all that men look for comes to pass. Two gates there are that give passage to fleeting Oneiroi; one is made of horn, one of ivory. The Oneiroi that pass through sawn ivory are deceitful, bearing a message that will not be fulfilled; those that come out through polished horn have truth behind them, to be accomplished for men who see them." Homer, Odyssey 19. 562 ff (Shewring translation).


You can’t perform that action at this time.