keras/docs/sources/index.md

140 lines
6.5 KiB
Markdown
Raw Normal View History

2015-04-12 17:50:09 +00:00
# Keras: Theano-based Deep Learning library
2015-04-11 20:01:12 +00:00
## Overview
2015-07-11 23:10:13 +00:00
Keras is a minimalist, highly modular neural network library in the spirit of Torch, written in Python, that uses [Theano](http://deeplearning.net/software/theano/) under the hood for optimized tensor manipulation on GPU and CPU. It was developed with a focus on enabling fast experimentation.
2015-04-11 22:39:44 +00:00
Use Keras if you need a deep learning library that:
- allows for easy and fast prototyping (through total modularity, minimalism, and extensibility).
2015-07-18 10:49:10 +00:00
- supports both convolutional networks and recurrent networks, as well as combinations of the two.
- supports arbitrary connectivity schemes (including multi-input and multi-output training).
- runs seamlessly on CPU and GPU.
2015-04-11 20:01:12 +00:00
## Guiding principles
2015-07-11 23:10:13 +00:00
- __Modularity.__ A model is understood as a sequence or a graph of standalone, fully-configurable modules that can be plugged together with as little restrictions as possible. In particular, neural layers, cost functions, optimizers, initialization schemes, activation functions, regularization schemes are all standalone modules that you can combine to create new models.
2015-07-11 23:10:13 +00:00
- __Minimalism.__ Each module should be kept short and simple (<100 lines of code). Every piece of code should be transparent upon first reading. No black magic: it hurts iteration speed and ability to innovate.
2015-07-11 23:10:13 +00:00
- __Easy extensibility.__ New modules are dead simple to add (as new classes/functions), and existing modules provide ample examples. To be able to easily create new modules allows for total expressiveness, making Keras suitable for adavanced research.
2015-04-11 20:01:12 +00:00
2015-07-11 23:10:13 +00:00
- __Work with Python__. No separate models configuration files in a declarative format (like in Caffe or PyLearn2). Models are described in Python code, which is compact, easier to debug, and allows for ease of extensibility.
2015-04-11 20:01:12 +00:00
## Code
Find the code on Github: [fchollet/keras](https://github.com/fchollet/keras).
## License
Keras is licensed under the [MIT license](http://opensource.org/licenses/MIT).
## Getting started: 30 seconds to Keras
2015-04-11 22:39:44 +00:00
2015-07-11 23:10:13 +00:00
The core datastructure of Keras is a __model__, a way to organize layers. There are two types of models: [`Sequential`](/models/#sequential) and [`Graph`](/models/#graph).
Here's the `Sequential` model (a linear pile of layers):
2015-04-11 22:39:44 +00:00
```python
from keras.models import Sequential
model = Sequential()
```
Stacking layers is as easy as `.add()`:
```python
from keras.layers.core import Dense, Activation
2015-06-28 06:52:03 +00:00
model.add(Dense(input_dim=100, output_dim=64, init="glorot_uniform"))
2015-04-11 22:39:44 +00:00
model.add(Activation("relu"))
2015-06-28 06:52:03 +00:00
model.add(Dense(input_dim=64, output_dim=10, init="glorot_uniform"))
2015-04-11 22:39:44 +00:00
model.add(Activation("softmax"))
```
Once your model looks good, configure its learning process with `.compile()`:
```python
model.compile(loss='categorical_crossentropy', optimizer='sgd')
```
2015-04-12 17:50:09 +00:00
If you need to, you can further configure your optimizer. A core principle of Keras is make things 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).
2015-04-11 22:39:44 +00:00
```python
from keras.optimizers import SGD
model.compile(loss='categorical_crossentropy', optimizer=SGD(lr=0.01, momentum=0.9, nesterov=True))
```
2015-04-12 17:50:09 +00:00
You can now iterate on your training data in batches:
2015-04-11 22:39:44 +00:00
```python
model.fit(X_train, Y_train, nb_epoch=5, batch_size=32)
```
Alternatively, you can feed batches to your model manually:
```python
2015-07-05 22:04:20 +00:00
model.train_on_batch(X_batch, Y_batch)
2015-04-11 22:39:44 +00:00
```
Evaluate your performance in one line:
```python
objective_score = model.evaluate(X_test, Y_test, batch_size=32)
```
2015-04-12 17:50:09 +00:00
Or generate predictions on new data:
2015-04-11 22:39:44 +00:00
```python
classes = model.predict_classes(X_test, batch_size=32)
proba = model.predict_proba(X_test, batch_size=32)
```
2015-07-05 22:04:20 +00:00
Building a network of LSTMs, a deep CNN, a Neural Turing Machine, a word2vec embedder or any other model is just as fast. The ideas behind deep learning are simple, so why should their implementation be painful?
2015-04-11 22:39:44 +00:00
Have a look at the [examples](examples.md).
2015-04-12 17:50:09 +00:00
## Installation
Keras uses the following dependencies:
2015-07-11 23:10:13 +00:00
- __numpy__, __scipy__
2015-07-18 10:49:10 +00:00
- __pyyaml__
2015-07-11 23:10:13 +00:00
- __Theano__
2015-04-12 17:50:09 +00:00
- See [installation instructions](http://deeplearning.net/software/theano/install.html#install).
2015-07-11 23:10:13 +00:00
- __HDF5__ and __h5py__ (optional, required if you use model saving/loading functions)
- Optional but recommended if you use CNNs: __cuDNN__.
2015-04-12 17:50:09 +00:00
Once you have the dependencies installed, clone the repo:
```bash
git clone https://github.com/fchollet/keras.git
```
Go to the Keras folder and run the install command:
```bash
cd keras
sudo python setup.py install
```
2015-07-18 10:49:10 +00:00
You can also install Keras from PyPI:
```
sudo pip install keras
```
2015-04-11 22:39:44 +00:00
2015-04-16 03:15:32 +00:00
## Support
You can ask questions and join the development discussion on the [Keras Google group](https://groups.google.com/forum/#!forum/keras-users).
2015-04-11 20:01:12 +00:00
## Contribution Guidelines
Keras welcomes all contributions from the community.
2015-04-12 17:50:09 +00:00
- Keep a pragmatic mindset and avoid bloat. Only add to the source if that is the only path forward.
2015-04-11 20:01:12 +00:00
- New features should be documented. Make sure you update the documentation along with your Pull Request.
- The documentation for every new feature should include a usage example in the form of a code snippet.
2015-07-05 22:04:20 +00:00
- All changes should be tested. Make sure any new feature you add has a corresponding unit test.
2015-04-11 22:39:44 +00:00
- Even if you don't contribute to the Keras source code, if you have an application of Keras that is concise and powerful, please consider adding it to our collection of [examples](https://github.com/fchollet/keras/tree/master/examples).
2015-04-12 17:50:09 +00:00
## 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).
2015-07-05 22:04:20 +00:00
Keras was developed as part of the research effort of project __ONEIROS__ (*Open-ended Neuro-Electronic Intelligent Robot Operating System*).
2015-04-12 17:50:09 +00:00
2015-04-13 22:54:38 +00:00
> _"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).