Python
Clone or download
davidtvs and fchollet [ RELNOTES] Add `output_padding` in `Conv2DTranspose`
* Add output shape argument to transposed conv. to resolve ambiguity

* Remove deconv2d  legacy preprocessor

* Add unit tests for output shape in 2d/3d transpose

* Replace output_shape with output_padding

* Update docstrings

* deconv_length handles output_padding=None

* Unit tests

* Check if stride is greater than output padding

* Pull request revision

commit 65670e6
Author: David Silva <davidtvs10@gmail.com>
Date:   Tue Jun 19 06:00:55 2018 +0100

    Replace two spaces by br tag to force new line

commit d714193
Author: David Silva <davidtvs10@gmail.com>
Date:   Tue Jun 19 05:26:57 2018 +0100

    Add output shape equation to docstrings

commit 5f06a78
Author: David Silva <davidtvs10@gmail.com>
Date:   Sat Jun 16 17:26:20 2018 +0100

    Fixes following @fchollet revision

commit b4530ae
Merge: 6b99d23 5fcd832
Author: David Silva <davidtvs10@gmail.com>
Date:   Sat Jun 16 16:17:41 2018 +0100

    Merge remote-tracking branch 'upstream/master' into trans_out_pad_dev

commit 5fcd832
Author: Pavithra Vijay <psv@google.com>
Date:   Fri Jun 15 16:29:32 2018 -0700

    Fix small doc error (#10453)

commit 2ec486b
Author: Francois Chollet <francois.chollet@gmail.com>
Date:   Fri Jun 15 14:07:28 2018 -0700

    Model input validation fix.

commit ffa99d6
Author: Pavithra Vijay <psv@google.com>
Date:   Fri Jun 15 13:52:14 2018 -0700

    Fix use_bias in some convolutional layers (#10444)

    * Fix use_bias in some convolutional layers

    * Fix Conv2DTranspose test

commit 6aace30
Author: ebatuhankaynak <ebatuhankaynak@users.noreply.github.com>
Date:   Fri Jun 15 22:00:24 2018 +0300

    Update convolutional.py (#10452)

    Changed
    "# now model.output_shape == (None, 20, 16. 64)"
    to
    "# now model.output_shape == (None, 20, 16, 64)"

    (There is a dot instead of comma).

commit 2d183db
Author: Sachin Abeywardana <sachinruk@users.noreply.github.com>
Date:   Fri Jun 15 04:19:45 2018 +1000

    corrected batch norm implementation in cntk (#10427)

commit 52f608c
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Thu Jun 14 05:44:22 2018 +0900

    Add tests for inputs set dynamically (#10416)

commit a68c516
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Thu Jun 14 03:43:43 2018 +0900

    Update a CNTK version on Travis (#10419)

commit 4f90f95
Author: ebatuhankaynak <ebatuhankaynak@users.noreply.github.com>
Date:   Wed Jun 13 21:39:47 2018 +0300

    Update faq.md (#10422)

    Changed "Notes that the methods...." to "Note that the methods"

commit 8e5b853
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Thu Jun 14 03:39:13 2018 +0900

    Move `get_source_inputs` (#10415)

commit a40f335
Author: Max Pumperla <max.pumperla@googlemail.com>
Date:   Wed Jun 13 20:36:50 2018 +0200

    [docs] more details for adagrad/delta, clarifying usage of rho (#10410)

    * some more meat for ada docs

    * incorporate suggestions

    * line breaks

commit 29a22a8
Author: fuzzythecat <fuzzy0427@gmail.com>
Date:   Wed Jun 13 02:57:38 2018 +0900

    Add missing named arguments in ImageDataGenerator in examples (#10389)

commit 0237542
Author: EyeBool <diataha.personal@gmail.com>
Date:   Mon Jun 11 09:44:02 2018 -0700

    Fixed a type: repeated 'in common'. (#10394)

commit 3eab610
Author: Francois Chollet <francois.chollet@gmail.com>
Date:   Thu Jun 7 16:09:58 2018 -0700

    Preserve input shape data when serializing deferred-build Sequential models.

commit db849f8
Author: jlopezpena <jlopezpena@users.noreply.github.com>
Date:   Thu Jun 7 19:54:51 2018 +0100

    Doc update (#10376)

    A couple of variables are "used" in two examples without being defined. For consistency with other examples where auxiliary dimensions are defined, I think it would be better to explicitly assign them a value. I just used made up values, feel free to change to whatever makes more sense!

commit 67e242d
Author: Max Pumperla <max.pumperla@googlemail.com>
Date:   Thu Jun 7 20:54:23 2018 +0200

    Add spatial dropout and 3D global pooling to docs (#10373)

    * spatial dropout in docs

    * 3d global pooling in docs

commit 4e82971
Author: Francois Chollet <francois.chollet@gmail.com>
Date:   Wed Jun 6 16:17:29 2018 -0700

    Update docs for 2.2.0.

commit 632560d
Author: Francois Chollet <francois.chollet@gmail.com>
Date:   Wed Jun 6 11:53:18 2018 -0700

    Style fix

commit bbf4283
Author: Bohumír Zámečník <bohumir.zamecnik@gmail.com>
Date:   Wed Jun 6 20:52:26 2018 +0200

    CuDNN RNN layers nested in TimeDistributed are not converted when loading (#10357)

    * Add a unit test for CuDNNGRU conversion with TimeDistributed.

    * Extract duplicated function convert_model() to _convert_model_weights().

    * #10356 Convert weights of CuDNN/plain RNN nested in TimeDistributed.

    Same case as for Bidirectional, except that in TimeDistributed there's only
    one nested layer instead of two.

commit 13548e8
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Thu Jun 7 03:51:37 2018 +0900

    Add tests for inputs set dynamically (#10367)

commit 56b255c
Author: Francois Chollet <francois.chollet@gmail.com>
Date:   Wed Jun 6 10:51:06 2018 -0700

    Update to Keras Applications 1.0.2 (fixes NASNet issue).

commit 513f7b1
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Thu Jun 7 00:47:37 2018 +0900

    Fix a version number (#10361)

commit 9a58f7b
Author: Francois Chollet <francois.chollet@gmail.com>
Date:   Tue Jun 5 17:40:44 2018 -0700

    Prepare 2.2.0 release.

commit 3f4ccbb
Author: Francois Chollet <francois.chollet@gmail.com>
Date:   Tue Jun 5 17:30:48 2018 -0700

    Add error message when calling `summary` on unbuilt subclassed models.

commit 25d0193
Author: tiferet <tgazit@gmail.com>
Date:   Tue Jun 5 21:23:27 2018 +0300

    Supporting channels_first data format with crossentropy losses (#9715)

commit 1e80c1a
Author: KuzMenachem <35711942+KuzMenachem@users.noreply.github.com>
Date:   Tue Jun 5 20:10:43 2018 +0200

     Fix HDF5Matrix issue when working in conjunction with TimeSeriesGenerator (#10334)

    * Fix issue when working in conjunction with TimeSeriesGenerator

    The TimeSeriesGenerator class uses xrange through six which caused an IndexError

    * Add test

    * Add corresponding test

    * Fix for python3

    * Simplified code

    * Fix indent

    * Fix test

commit ce56322
Author: David Schwertfeger <david.schwertfeger@googlemail.com>
Date:   Tue Jun 5 00:15:25 2018 +0200

    FIX: Tensorboard callback only supports logging Embeddings layer weights (#7766)

    * Embed layer-outputs rather than layer-weights in TensorBoard callback

    * Update docstring and allow multiple inputs

    * Fix tests

    * Renaming

    * Set learning phase

    * Compute embeddings in batches

    * Pass embedding data explicitly

    * Actually process embeddings in batches

    * Allow multiple inputs and validate input data

    * Add example

    * Delete utils.py

    * Revert uncorrectly resolved merge-conflict

    * Minor renaming

    * Add comment clarifying the design choice

commit b217648
Author: Tommi Koivisto <tkoivisto@users.noreply.github.com>
Date:   Mon Jun 4 20:26:41 2018 +0300

    Add an advanced activation layer for ReLU (#10322)

    The max_value argument can not be used in a layer, except
    custom layer or Lambda. Hence, similarly to LeakyReLU or
    for example Softmax, this PR adds a layer for ReLU,
    enabling also a capped ReLU to be used.

commit 1365ed5
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Tue Jun 5 02:07:23 2018 +0900

    Reduce tests for applications (#10346)

    * Reduce tests for applications

    * Make selection over all models random

commit 52e3f98
Author: Anirudh Swaminathan <aniswami97@gmail.com>
Date:   Sun Jun 3 01:22:09 2018 +0800

    Improve the docstring of Conv3DTranspose (#10342)

    * Add depth as third dimension in docstring of
      Conv3DTranspose in convolutional.py in keras.layers

commit f89b339
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Sun Jun 3 02:21:06 2018 +0900

    Move tests for applications (#10341)

commit c9cb608
Author: François Chollet <francois.chollet@gmail.com>
Date:   Fri Jun 1 23:53:49 2018 -0700

    Split `applications` and `preprocessing` modules. (#10339)

    * Split `applications` and `preprocessing` modules.

    * Fix dependencies.

commit a366424
Author: Zhengping Che <Peterche1990@Hotmail.com>
Date:   Sat Jun 2 07:13:24 2018 +0800

    Handle `mask` in `TimeDistributed` wrapper. (#10242)

    * equip TimeDistributed with mask and unspecified input length

    * fix bugs in theano. add test on timedistributed + masking

    * skip tests on cntk with multiple unspecified time lengths.

    * move static shape inference to theano_backend, add docstring, etc.

    * fix format

commit 7365a99
Author: fuzzythecat <fuzzy0427@gmail.com>
Date:   Fri Jun 1 04:45:26 2018 +0900

    Fix doc (#10327)

    Fixed doc

commit fe06696
Author: fuzzythecat <fuzzy0427@gmail.com>
Date:   Wed May 30 13:49:44 2018 +0900

    Add pooling options in MobileNetV2 (#10313)

    * Add pooling option

    * Add pooling test

commit 315a80a
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Wed May 30 01:43:37 2018 +0900

    Improve docstrings of applications (#10310)

commit 25283ea
Author: Francois Chollet <francois.chollet@gmail.com>
Date:   Tue May 29 09:31:14 2018 -0700

    Fix typo

commit 0de2adf
Author: fuzzythecat <fuzzy0427@gmail.com>
Date:   Tue May 29 13:58:18 2018 +0900

    Fix doc  (#10308)

    * Fix naming convention

    * Add missing doc

commit 9bff5b1
Author: r-kellerm <34206121+r-kellerm@users.noreply.github.com>
Date:   Mon May 28 03:45:35 2018 +0300

    Typo fix (#10293)

commit 794f814
Author: Botty Dimanov <bottydim@users.noreply.github.com>
Date:   Fri May 25 22:21:41 2018 +0100

    Handle capitalised extensions in list_pictures (#10220)

    #10219

commit 84aa7b5
Author: Wang, Zhiming <zhiming.wang@intel.com>
Date:   Sat May 26 05:20:57 2018 +0800

    Non training Batch Norm operator has bad performance for it running into tensorflow's non fused batch norm API (#10207)

    * When use tensorflow as backend, let batch norm run into fused batch norm as much as possible, which has better performance.

    fix issue: http://www.oddjack.com/?certs=keras-team/keras/issues/10058

    * In Tensorflow backend, let batch norm call to FusedBatchNorm only NHWC format, also gamma and beta are not None.

    Test result:
    test env: with Tensorflow(commit a543d9471047ca3f6881c87105fcbe2cdff9207d Date:   Thu May 10 17:43:30 2018, local build), python3.4, centos7.4
    test cases:
      "pytest  ./tests/keras/layers/normalization_test.py"  <all passed>
      "pytest  ./tests"      <keep same result as without this commit's modification on BN>

    * fix code sytle.

    * 1. Add axis parameter in backend's batch_normalization functions.
    2. Refine the batch_normalization function in tensorflow backend, Let's it call to fused batch norm as much as possible.

    Thanks the coments from fchollet.

    * Trigger

    * 1. add default value -1 for parameter axis in batch_normalization function in backend.
    2. fix some code style.
    Thanks the comments from fchollet.

commit e6d2179
Author: Stanley Bileschi <bileschi@google.com>
Date:   Fri May 25 17:19:38 2018 -0400

    Adds to and alphabetizes documentation of Layer base class. (#10282)

    * Alphabetizes and adds to layers doc.

    * Responding to @cais comments

    * fix spacing.  Remove in(out)bound_nodes

commit 5eecd55
Author: Amir Alavi <s.amir.alavi@gmail.com>
Date:   Thu May 24 16:54:20 2018 -0400

    load_weights will fail if shape mismatch (#10266)

    Fix for #10265

commit d476ecc
Author: jnphilipp <mail@jnphilipp.org>
Date:   Thu May 24 19:52:11 2018 +0200

    Use count_params function for non_trainable_count. (#10280)

commit a07d9f3
Author: Stefano Cappellini <contact@stefanocappellini.com>
Date:   Thu May 24 19:50:21 2018 +0200

    Fixes automatic doc generation problem with nested lists. Adds a new test (#10212)

    * Fixes automatic doc generation problem with indented lists. Adds a new test

    * Some style fixes on doc automatic generation files

    * Fixes a bad space in convolutional_recurrent.py

    * Changes the test_doc_auto_generation in order to include a doc string taken from the codebase. Allows text lines following nested lists

commit 5a48df2
Author: Clemens Tolboom <clemens@build2be.com>
Date:   Thu May 24 00:00:42 2018 +0200

    Make Dot documentation inline with Concatenate (#10271)

    Doc expects a list containing 2 tensors.

commit 2064477
Author: askskro <ak@aiascience.com>
Date:   Wed May 23 23:59:58 2018 +0200

    Typo in docstring for softplus (#10277)

    Softplus docstring missing a parenthesis.

commit c77267a
Author: Brian Nemsick <brian.nemsick@gmail.com>
Date:   Wed May 23 11:54:36 2018 -0700

    Remove deprecated model.model from engine/saving (#10275)

commit 08c8736
Author: vkk800 <vkk800@users.noreply.github.com>
Date:   Tue May 22 23:03:51 2018 +0200

    Refactor ImageDataGenerator (#10130)

    * Create get_random_transform and refactor

    * Fix style and add tests

    * Add more tests

    * Fix documentation error

    * Fix documentation style issue

    * add apply_affine_transform

    * document transformation dictionary

    * Doc style fix

commit 25a8973
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Wed May 23 04:18:46 2018 +0900

    Increase test coverages by factorizing CNTK pads (#10259)

commit abd0294
Author: brge17 <33430930+brge17@users.noreply.github.com>
Date:   Mon May 21 18:42:07 2018 -0700

    Remove Sequential.model deprecation warning (#10256)

    * Remove Sequential.model deprecation warning

    * Remove dead line of code

commit 2eed2a5
Author: Taehoon Lee <me@taehoonlee.com>
Date:   Tue May 22 03:11:43 2018 +0900

    Increase test coverages by adding invalid CNTK usecases (#10236)

* Revert "Pull request revision"

This reverts commit fb7c367.

* Pull request revision (v2)

* Replace HTML markup by markdown
Latest commit 3d7f5f0 Jun 21, 2018

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, 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):
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 http://www.oddjack.com/?certs=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).