Skip to content

Commit b5cb82c

Browse files
authored
Redirect Keras to tf.keras (#14121)
* Replace all code with tf.keras redirects
1 parent 7a39b6c commit b5cb82c

File tree

145 files changed

+696
-51171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

145 files changed

+696
-51171
lines changed

.travis.yml

Lines changed: 21 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,29 @@
1-
dist: trusty
21
language: python
3-
cache:
4-
directories:
5-
- $HOME/.theano
6-
matrix:
7-
include:
8-
- python: 3.6
9-
env: KERAS_BACKEND=tensorflow MODE=INTEGRATION_TESTS PIL=Pillow
10-
- python: 3.6
11-
env: KERAS_BACKEND=tensorflow MODE=PEP8_DOC PIL=Pillow
12-
- python: 3.6
13-
env: KERAS_BACKEND=tensorflow MODE=API
14-
- python: 2.7
15-
env: KERAS_BACKEND=tensorflow MODE=TF1
16-
- python: 3.6
17-
env: KERAS_BACKEND=tensorflow MODE=TF1
18-
- python: 2.7
19-
env: KERAS_BACKEND=tensorflow MODE=TF2
20-
- python: 3.6
21-
env: KERAS_BACKEND=tensorflow MODE=TF2
22-
- python: 2.7
23-
env: KERAS_BACKEND=theano THEANO_FLAGS=optimizer=fast_compile MKL="mkl mkl-service" RUN_ONLY_BACKEND_TESTS=1
24-
- python: 3.6
25-
env: KERAS_BACKEND=theano THEANO_FLAGS=optimizer=fast_compile MKL="mkl mkl-service"
26-
- python: 2.7
27-
env: KERAS_BACKEND=cntk PYTHONWARNINGS=ignore RUN_ONLY_BACKEND_TESTS=1
28-
- python: 3.6
29-
env: KERAS_BACKEND=cntk PYTHONWARNINGS=ignore
30-
install:
31-
# code below is taken from http://conda.pydata.org/docs/travis.html
32-
# We do this conditionally because it saves us some downloading if the
33-
# version is the same.
34-
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
35-
wget https://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh;
36-
else
37-
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
38-
fi
39-
- bash miniconda.sh -b -p $HOME/miniconda
40-
- export PATH="$HOME/miniconda/bin:$PATH"
41-
- hash -r
42-
- conda config --set always_yes yes --set changeps1 no
43-
- conda update -q conda
44-
# Useful for debugging any issues with conda
45-
- conda info -a
46-
47-
- travis_retry conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION
48-
- source activate test-environment
49-
50-
- travis_retry pip install --only-binary=numpy,scipy,pandas numpy nose scipy h5py theano pytest pytest-pep8 pandas --progress-bar off
51-
- pip install keras_applications keras_preprocessing --progress-bar off
52-
53-
# set library path
54-
- export LD_LIBRARY_PATH=$HOME/miniconda/envs/test-environment/lib/:$LD_LIBRARY_PATH
552

56-
# install pydot for visualization tests
57-
- travis_retry conda install -q $MKL pydot graphviz $PIL
3+
# sudo false implies containerized builds
4+
sudo: false
585

59-
- pip install -e .[tests] --progress-bar off
6+
python:
7+
- 3.6
608

61-
# install TensorFlow (CPU version).
62-
- if [[ "$MODE" == "TF2" ]]; then
63-
pip install tensorflow==2.0.0 --progress-bar off;
64-
else
65-
pip install tensorflow==1.14.0 --progress-bar off;
66-
fi
9+
before_install:
10+
# Here we download miniconda and install the dependencies
11+
- export MINICONDA=$HOME/miniconda
12+
- export PATH="$MINICONDA/bin:$PATH"
13+
- hash -r
14+
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
15+
- bash miniconda.sh -b -f -p $MINICONDA
16+
- conda config --set always_yes yes
17+
- conda update conda
18+
- conda info -a
19+
- travis_retry conda create -q -n testenv python=$TRAVIS_PYTHON_VERSION
20+
- source activate testenv
21+
- travis_retry pip install tf-nightly numpy scipy h5py pytest flaky pandas --progress-bar off
22+
- travis_retry conda install -q pydot graphviz Pillow
6723

68-
# install cntk
69-
- if [[ "$KERAS_BACKEND" == "cntk" ]] || [[ "$MODE" == "PEP8_DOC" ]] || [[ "$MODE" == "API" ]]; then
70-
./.travis/install_cntk.sh;
71-
fi
7224

73-
# Remove the current backend from the coverage exclusion.
74-
- sed -i "\/keras\/backend\/${KERAS_BACKEND}_backend.py/d" .coveragerc
75-
76-
# install mkdocs
77-
- pip install mkdocs --progress-bar off
78-
79-
# install pyux
80-
- pip install pyux
25+
install:
26+
- python setup.py install
8127

82-
# command to run tests
8328
script:
84-
- export MKL_THREADING_LAYER="GNU"
85-
# run keras backend init to initialize backend config
86-
- python -c "import keras.backend"
87-
# create dataset directory to avoid concurrent directory creation at runtime
88-
- mkdir ~/.keras/datasets
89-
# set up keras backend
90-
- sed -i -e 's/"backend":[[:space:]]*"[^"]*/"backend":\ "'$KERAS_BACKEND'/g' ~/.keras/keras.json;
91-
- echo -e "Running tests with the following config:\n$(cat ~/.keras/keras.json)"
92-
- if [[ "$MODE" == "INTEGRATION_TESTS" ]]; then
93-
PYTHONPATH=$PWD:$PYTHONPATH py.test tests/integration_tests;
94-
elif [[ "$MODE" == "PEP8_DOC" ]]; then
95-
PYTHONPATH=$PWD:$PYTHONPATH py.test --pep8 -m pep8 -n0 && py.test tests/docs;
96-
elif [[ "$MODE" == "API" ]]; then
97-
PYTHONPATH=$PWD:$PYTHONPATH pip install git+git://www.github.com/keras-team/keras.git && python update_api.py && pip install -e .[tests] --progress-bar off && py.test tests/test_api.py;
98-
elif [[ "$RUN_ONLY_BACKEND_TESTS" == "1" ]]; then
99-
PYTHONPATH=$PWD:$PYTHONPATH py.test tests/keras/backend/;
100-
else
101-
PYTHONPATH=$PWD:$PYTHONPATH py.test tests/ --ignore=tests/integration_tests --ignore=tests/docs --ignore=tests/keras/legacy/layers_test.py --ignore=tests/test_api.py --cov-config .coveragerc --cov=keras tests/;
102-
fi
29+
- pytest tests/ --ignore=tests/docs --ignore=tests/keras/legacy/layers_test.py --ignore=tests/test_api.py

.travis/install_cntk.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -5,199 +5,18 @@
55
[![Build Status](https://travis-ci.org/keras-team/keras.svg?branch=master)](https://travis-ci.org/keras-team/keras)
66
[![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/keras-team/keras/blob/master/LICENSE)
77

8-
## You have just found Keras.
98

10-
Keras is a high-level neural networks API, written in Python and capable of running on top of [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.*
11-
12-
Use Keras if you need a deep learning library that:
13-
14-
- Allows for easy and fast prototyping (through user friendliness, modularity, and extensibility).
15-
- Supports both convolutional networks and recurrent networks, as well as combinations of the two.
16-
- Runs seamlessly on CPU and GPU.
9+
Keras is a deep learning API written in Python, running on top of the machine learning platform TensorFlow.
1710

1811
Read the documentation at [Keras.io](https://keras.io).
1912

20-
Keras is compatible with: __Python 2.7-3.6__.
21-
2213

2314
------------------
2415

25-
## Multi-backend Keras and tf.keras:
16+
## Multi-backend Keras and tf.keras
2617

27-
**At this time, we recommend that Keras users who use multi-backend Keras with the TensorFlow backend switch to `tf.keras` in TensorFlow 2.0**. `tf.keras` is better maintained and has better integration with TensorFlow features (eager execution, distribution support and other).
18+
**Multi-backend Keras has been discontinued. At this time, we recommend that Keras users who use multi-backend Keras with the TensorFlow backend switch to `tf.keras` in TensorFlow 2.0**.
2819

2920
Keras 2.2.5 was the last release of Keras implementing the 2.2.* API. It was the last release to only support TensorFlow 1 (as well as Theano and CNTK).
3021

31-
The current release is Keras 2.3.0, which makes significant API changes and add support for TensorFlow 2.0. The 2.3.0 release will be the last major release of multi-backend Keras. Multi-backend Keras is superseded by `tf.keras`.
32-
33-
Bugs present in multi-backend Keras will only be fixed until April 2020 (as part of minor releases).
34-
35-
For more information about the future of Keras, see [the Keras meeting notes](http://bit.ly/keras-meeting-notes).
36-
37-
38-
------------------
39-
40-
## Guiding principles
41-
42-
- __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.
43-
44-
- __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.
45-
46-
- __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.
47-
48-
- __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.
49-
50-
51-
------------------
52-
53-
54-
## Getting started: 30 seconds to Keras
55-
56-
The core data structure of Keras is a __model__, a way to organize layers. The simplest type of model is the [`Sequential`](https://keras.io/getting-started/sequential-model-guide) model, a linear stack of layers. For more complex architectures, you should use the [Keras functional API](https://keras.io/getting-started/functional-api-guide), which allows to build arbitrary graphs of layers.
57-
58-
Here is the `Sequential` model:
59-
60-
```python
61-
from keras.models import Sequential
62-
63-
model = Sequential()
64-
```
65-
66-
Stacking layers is as easy as `.add()`:
67-
68-
```python
69-
from keras.layers import Dense
70-
71-
model.add(Dense(units=64, activation='relu', input_dim=100))
72-
model.add(Dense(units=10, activation='softmax'))
73-
```
74-
75-
Once your model looks good, configure its learning process with `.compile()`:
76-
77-
```python
78-
model.compile(loss='categorical_crossentropy',
79-
optimizer='sgd',
80-
metrics=['accuracy'])
81-
```
82-
83-
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).
84-
```python
85-
model.compile(loss=keras.losses.categorical_crossentropy,
86-
optimizer=keras.optimizers.SGD(lr=0.01, momentum=0.9, nesterov=True))
87-
```
88-
89-
You can now iterate on your training data in batches:
90-
91-
```python
92-
# x_train and y_train are Numpy arrays --just like in the Scikit-Learn API.
93-
model.fit(x_train, y_train, epochs=5, batch_size=32)
94-
```
95-
96-
Alternatively, you can feed batches to your model manually:
97-
98-
```python
99-
model.train_on_batch(x_batch, y_batch)
100-
```
101-
102-
Evaluate your performance in one line:
103-
104-
```python
105-
loss_and_metrics = model.evaluate(x_test, y_test, batch_size=128)
106-
```
107-
108-
Or generate predictions on new data:
109-
110-
```python
111-
classes = model.predict(x_test, batch_size=128)
112-
```
113-
114-
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?
115-
116-
For a more in-depth tutorial about Keras, you can check out:
117-
118-
- [Getting started with the Sequential model](https://keras.io/getting-started/sequential-model-guide)
119-
- [Getting started with the functional API](https://keras.io/getting-started/functional-api-guide)
120-
121-
In the [examples folder](https://github.com/keras-team/keras/tree/master/examples) of the repository, you will find more advanced models: question-answering with memory networks, text generation with stacked LSTMs, etc.
122-
123-
124-
------------------
125-
126-
127-
## Installation
128-
129-
Before installing Keras, please install one of its backend engines: TensorFlow, Theano, or CNTK. We recommend the TensorFlow backend.
130-
131-
- [TensorFlow installation instructions](https://www.tensorflow.org/install/).
132-
- [Theano installation instructions](http://deeplearning.net/software/theano/install.html#install).
133-
- [CNTK installation instructions](https://docs.microsoft.com/en-us/cognitive-toolkit/setup-cntk-on-your-machine).
134-
135-
You may also consider installing the following **optional dependencies**:
136-
137-
- [cuDNN](https://docs.nvidia.com/deeplearning/sdk/cudnn-install/) (recommended if you plan on running Keras on GPU).
138-
- HDF5 and [h5py](http://docs.h5py.org/en/latest/build.html) (required if you plan on saving Keras models to disk).
139-
- [graphviz](https://graphviz.gitlab.io/download/) and [pydot](https://github.com/erocarrera/pydot) (used by [visualization utilities](https://keras.io/visualization/) to plot model graphs).
140-
141-
Then, you can install Keras itself. There are two ways to install Keras:
142-
143-
- **Install Keras from PyPI (recommended):**
144-
145-
Note: These installation steps assume that you are on a Linux or Mac environment.
146-
If you are on Windows, you will need to remove `sudo` to run the commands below.
147-
148-
```sh
149-
sudo pip install keras
150-
```
151-
152-
If you are using a virtualenv, you may want to avoid using sudo:
153-
154-
```sh
155-
pip install keras
156-
```
157-
158-
- **Alternatively: install Keras from the GitHub source:**
159-
160-
First, clone Keras using `git`:
161-
162-
```sh
163-
git clone https://github.com/keras-team/keras.git
164-
```
165-
166-
Then, `cd` to the Keras folder and run the install command:
167-
```sh
168-
cd keras
169-
sudo python setup.py install
170-
```
171-
172-
------------------
173-
174-
175-
## Configuring your Keras backend
176-
177-
By default, Keras will use TensorFlow as its tensor manipulation library. [Follow these instructions](https://keras.io/backend/) to configure the Keras backend.
178-
179-
------------------
180-
181-
182-
## Support
183-
184-
You can ask questions and join the development discussion:
185-
186-
- On the [Keras Google group](https://groups.google.com/forum/#!forum/keras-users).
187-
- On the [Keras Slack channel](https://kerasteam.slack.com). Use [this link](https://keras-slack-autojoin.herokuapp.com/) to request an invitation to the channel.
188-
189-
You can also post **bug reports and feature requests** (only) in [GitHub issues](https://github.com/keras-team/keras/issues). Make sure to read [our guidelines](https://github.com/keras-team/keras/blob/master/CONTRIBUTING.md) first.
190-
191-
192-
------------------
193-
194-
195-
## Why this name, Keras?
196-
197-
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).
198-
199-
Keras was initially developed as part of the research effort of project ONEIROS (Open-ended Neuro-Electronic Intelligent Robot Operating System).
200-
201-
>_"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).
202-
203-
------------------
22+
The current release is Keras 2.4.0, which simply redirects to `tf.keras`.

examples/variational_autoencoder.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import division
1818
from __future__ import print_function
1919

20+
import keras
2021
from keras.layers import Lambda, Input, Dense
2122
from keras.models import Model
2223
from keras.datasets import mnist
@@ -186,10 +187,6 @@ def plot_results(models,
186187
vae_loss = K.mean(reconstruction_loss + kl_loss)
187188
vae.add_loss(vae_loss)
188189
vae.compile(optimizer='adam')
189-
vae.summary()
190-
plot_model(vae,
191-
to_file='vae_mlp.png',
192-
show_shapes=True)
193190

194191
if args.weights:
195192
vae.load_weights(args.weights)

keras/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import absolute_import
2-
31
from . import utils
42
from . import activations
53
from . import applications
@@ -23,4 +21,4 @@
2321
from .models import Model
2422
from .models import Sequential
2523

26-
__version__ = '2.3.1'
24+
from tensorflow.keras import __version__

0 commit comments

Comments
 (0)