Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fchollet/keras into pr_7508
Browse files Browse the repository at this point in the history
* 'master' of github.com:fchollet/keras: (57 commits)
  Minor README edit
  Speed up Travis tests (keras-team#9386)
  fix typo (keras-team#9391)
  Fix style issue in docstring
  Prepare 2.1.4 release.
  Fix activity regularizer + model composition test
  Corrected copyright years (keras-team#9375)
  Change default interpolation from nearest to bilinear. (keras-team#8849)
  a capsule cnn on cifar-10 (keras-team#9193)
  Enable us to use sklearn to do cv for functional api (keras-team#9320)
  Add support for stateful metrics. (keras-team#9253)
  The type of list keys was float (keras-team#9324)
  Fix mnist sklearn wrapper example (keras-team#9317)
  keras-team#9287 Fix most of the file-handle resource leaks. (keras-team#9309)
  Pass current learning rate to schedule() in LearningRateScheduler (keras-team#8865)
  Simplify with from six.moves import input (keras-team#9216)
  fixed RemoteMonitor: Json to handle np.float32 and np.int32 types (keras-team#9261)
  Update tweet length from 140 to 280 in docs
  Add `depthconv_conv2d` tests (keras-team#9225)
  Remove `force` option in progbar
  ...
  • Loading branch information
ahundt committed Feb 16, 2018
2 parents dca5a7a + 40e64a8 commit e736fb4
Show file tree
Hide file tree
Showing 68 changed files with 1,240 additions and 552 deletions.
12 changes: 11 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
[report]
fail_under = 84
# Regexes for lines to exclude from consideration
exclude_lines =
# Don't complain if tests don't hit defensive assertion code:
raise ImportError
raise NotImplementedError

# Don't complain if legacy support codes are not performed:
if original_keras_version == '1':

fail_under = 85
show_missing = True
omit =
keras/applications/*
keras/datasets/*
keras/legacy/*
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ install:
# Useful for debugging any issues with conda
- conda info -a

- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy nose scipy matplotlib pandas pytest h5py
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION pytest pandas
- source activate test-environment
- pip install --only-binary=numpy,scipy numpy nose scipy matplotlib h5py theano
- conda install mkl mkl-service
- pip install theano

# set library path
- export LD_LIBRARY_PATH=$HOME/miniconda/envs/test-environment/lib/:$LD_LIBRARY_PATH
Expand Down Expand Up @@ -111,5 +111,5 @@ script:
elif [[ "$TEST_MODE" == "DOC" ]]; then
PYTHONPATH=$PWD:$PYTHONPATH py.test tests/test_documentation.py;
else
PYTHONPATH=$PWD:$PYTHONPATH py.test tests/ --ignore=tests/integration_tests --ignore=tests/test_documentation.py --cov-config .coveragerc --cov=keras tests/;
PYTHONPATH=$PWD:$PYTHONPATH py.test tests/ --ignore=tests/integration_tests --ignore=tests/test_documentation.py --ignore=tests/keras/legacy/layers_test.py --cov-config .coveragerc --cov=keras tests/;
fi
8 changes: 4 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
COPYRIGHT

All contributions by François Chollet:
Copyright (c) 2015, François Chollet.
Copyright (c) 2015 - 2018, François Chollet.
All rights reserved.

All contributions by Google:
Copyright (c) 2015, Google, Inc.
Copyright (c) 2015 - 2018, Google, Inc.
All rights reserved.

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

All other contributions:
Copyright (c) 2015 - 2017, the respective contributors.
Copyright (c) 2015 - 2018, the respective contributors.
All rights reserved.

Each contributor holds copyright over their respective contributions.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ sudo python setup.py install
------------------


## Switching from TensorFlow to CNTK or Theano
## Using a different backend than TensorFlow

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

Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG cuda_version=8.0
ARG cudnn_version=6
ARG cuda_version=9.0
ARG cudnn_version=7
FROM nvidia/cuda:${cuda_version}-cudnn${cudnn_version}-devel

ENV CONDA_DIR /opt/conda
Expand Down
4 changes: 2 additions & 2 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ DOCKER_FILE=Dockerfile
DOCKER=GPU=$(GPU) nvidia-docker
BACKEND=tensorflow
PYTHON_VERSION?=3.6
CUDA_VERSION?=8.0
CUDNN_VERSION?=6
CUDA_VERSION?=9.0
CUDNN_VERSION?=7
TEST=tests/
SRC?=$(shell dirname `pwd`)

Expand Down
20 changes: 13 additions & 7 deletions docs/autogen.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,13 +489,18 @@ def process_docstring(docstring):
new_fpath = fpath.replace('templates', 'sources')
shutil.copy(fpath, new_fpath)


# Take care of index page.
readme = open('../README.md').read()
index = open('templates/index.md').read()
def read_file(path):
with open(path) as f:
return f.read()


readme = read_file('../README.md')
index = read_file('templates/index.md')
index = index.replace('{{autogenerated}}', readme[readme.find('##'):])
f = open('sources/index.md', 'w')
f.write(index)
f.close()
with open('sources/index.md', 'w') as f:
f.write(index)

print('Starting autogeneration.')
for page_data in PAGES:
Expand Down Expand Up @@ -564,7 +569,7 @@ def process_docstring(docstring):
page_name = page_data['page']
path = os.path.join('sources', page_name)
if os.path.exists(path):
template = open(path).read()
template = read_file(path)
assert '{{autogenerated}}' in template, ('Template found for ' + path +
' but missing {{autogenerated}} tag.')
mkdown = template.replace('{{autogenerated}}', mkdown)
Expand All @@ -574,6 +579,7 @@ def process_docstring(docstring):
subdir = os.path.dirname(path)
if not os.path.exists(subdir):
os.makedirs(subdir)
open(path, 'w').write(mkdown)
with open(path, 'w') as f:
f.write(mkdown)

shutil.copyfile('../CONTRIBUTING.md', 'sources/contributing.md')
12 changes: 6 additions & 6 deletions docs/templates/getting-started/functional-api-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ One way to achieve this is to build a model that encodes two tweets into two vec

Because the problem is symmetric, the mechanism that encodes the first tweet should be reused (weights and all) to encode the second tweet. Here we use a shared LSTM layer to encode the tweets.

Let's build this with the functional API. We will take as input for a tweet a binary matrix of shape `(140, 256)`, i.e. a sequence of 140 vectors of size 256, where each dimension in the 256-dimensional vector encodes the presence/absence of a character (out of an alphabet of 256 frequent characters).
Let's build this with the functional API. We will take as input for a tweet a binary matrix of shape `(280, 256)`, i.e. a sequence of 280 vectors of size 256, where each dimension in the 256-dimensional vector encodes the presence/absence of a character (out of an alphabet of 256 frequent characters).

```python
import keras
from keras.layers import Input, LSTM, Dense
from keras.models import Model

tweet_a = Input(shape=(140, 256))
tweet_b = Input(shape=(140, 256))
tweet_a = Input(shape=(280, 256))
tweet_b = Input(shape=(280, 256))
```

To share a layer across different inputs, simply instantiate the layer once, then call it on as many inputs as you want:
Expand Down Expand Up @@ -222,7 +222,7 @@ In previous versions of Keras, you could obtain the output tensor of a layer ins
As long as a layer is only connected to one input, there is no confusion, and `.output` will return the one output of the layer:

```python
a = Input(shape=(140, 256))
a = Input(shape=(280, 256))

lstm = LSTM(32)
encoded_a = lstm(a)
Expand All @@ -232,8 +232,8 @@ assert lstm.output == encoded_a

Not so if the layer has multiple inputs:
```python
a = Input(shape=(140, 256))
b = Input(shape=(140, 256))
a = Input(shape=(280, 256))
b = Input(shape=(280, 256))

lstm = LSTM(32)
encoded_a = lstm(a)
Expand Down
6 changes: 3 additions & 3 deletions docs/templates/preprocessing/image.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ Generate batches of tensor image data with real-time data augmentation. The data
- __batch_size__: int (default: 32).
- __shuffle__: boolean (default: True).
- __seed__: int (default: None).
- __save_to_dir__: None or str (default: None). This allows you to optimally specify a directory to which to save the augmented pictures being generated (useful for visualizing what you are doing).
- __save_to_dir__: None or str (default: None). This allows you to optionally specify a directory to which to save the augmented pictures being generated (useful for visualizing what you are doing).
- __save_prefix__: str (default: `''`). Prefix to use for filenames of saved pictures (only relevant if `save_to_dir` is set).
- __save_format__: one of "png", "jpeg" (only relevant if `save_to_dir` is set). Default: "png".
- __yields__: Tuples of `(x, y)` where `x` is a numpy array of image data and `y` is a numpy array of corresponding labels.
The generator loops indefinitely.
- __flow_from_directory(directory)__: Takes the path to a directory, and generates batches of augmented/normalized data. Yields batches indefinitely, in an infinite loop.
- __Arguments__:
- __directory__: path to the target directory. It should contain one subdirectory per class.
Any PNG, JPG, BMP or PPM images inside each of the subdirectories directory tree will be included in the generator.
Any PNG, JPG, BMP, PPM or TIF images inside each of the subdirectories directory tree will be included in the generator.
See [this script](https://gist.github.com/fchollet/0830affa1f7f19fd47b06d4cf89ed44d) for more details.
- __target_size__: tuple of integers `(height, width)`, default: `(256, 256)`.
The dimensions to which all images found will be resized.
Expand All @@ -100,7 +100,7 @@ Generate batches of tensor image data with real-time data augmentation. The data
- __batch_size__: size of the batches of data (default: 32).
- __shuffle__: whether to shuffle the data (default: True)
- __seed__: optional random seed for shuffling and transformations.
- __save_to_dir__: None or str (default: None). This allows you to optimally specify a directory to which to save the augmented pictures being generated (useful for visualizing what you are doing).
- __save_to_dir__: None or str (default: None). This allows you to optionally specify a directory to which to save the augmented pictures being generated (useful for visualizing what you are doing).
- __save_prefix__: str. Prefix to use for filenames of saved pictures (only relevant if `save_to_dir` is set).
- __save_format__: one of "png", "jpeg" (only relevant if `save_to_dir` is set). Default: "png".
- __follow_links__: whether to follow symlinks inside class subdirectories (default: False).
Expand Down
4 changes: 3 additions & 1 deletion docs/templates/preprocessing/text.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ keras.preprocessing.text.Tokenizer(num_words=None,
filters='!"#$%&()*+,-./:;<=>?@[\\]^_`{|}~\t\n',
lower=True,
split=" ",
char_level=False)
char_level=False,
oov_token=None)
```

Class for vectorizing texts, or/and turning texts into sequences (=list of word indexes, where the word of rank i in the dataset (starting at 1) has index i).

- __Arguments__: Same as `text_to_word_sequence` above.
- __num_words__: None or int. Maximum number of words to work with (if set, tokenization will be restricted to the top num_words most common words in the dataset).
- __char_level__: if True, every character will be treated as a token.
- __oov_token__: None or str. If given, it will be added to word_index and used to replace out-of-vocabulary words during text_to_sequence calls.

- __Methods__:

Expand Down
4 changes: 2 additions & 2 deletions docs/templates/why-use-keras.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Your Keras models can be easily deployed across a greater range of platforms tha
- On Android, via the TensorFlow Android runtime. Example: [Not Hotdog app](https://medium.com/@timanglade/how-hbos-silicon-valley-built-not-hotdog-with-mobile-tensorflow-keras-react-native-ef03260747f3)
- In the browser, via GPU-accelerated JavaScript runtimes such as [Keras.js](https://transcranial.github.io/keras-js/#/) and [WebDNN](https://mil-tokyo.github.io/webdnn/)
- On Google Cloud, via [TensorFlow-Serving](https://www.tensorflow.org/serving/)
- In a Python webapp backend (such as a Flask app)
- [In a Python webapp backend (such as a Flask app)](https://blog.keras.io/building-a-simple-keras-deep-learning-rest-api.html)
- On the JVM, via [DL4J model import provided by SkyMind](https://deeplearning4j.org/model-import-keras)
- On Raspberry Pi

Expand All @@ -54,7 +54,7 @@ As such, your Keras model can be trained on a number of different hardware platf

- [NVIDIA GPUs](https://developer.nvidia.com/deep-learning)
- [Google TPUs](https://cloud.google.com/tpu/), via the TensorFlow backend and Google Cloud
- OpenGL-enabled GPUs, such as those from AMD, via [the PlaidML Keras backend](https://github.com/plaidml/plaidml)
- OpenCL-enabled GPUs, such as those from AMD, via [the PlaidML Keras backend](https://github.com/plaidml/plaidml)

---

Expand Down
7 changes: 4 additions & 3 deletions examples/babi_memnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def vectorize_stories(data):
'$ wget http://www.thespermwhale.com/jaseweston/babi/tasks_1-20_v1-2.tar.gz\n'
'$ mv tasks_1-20_v1-2.tar.gz ~/.keras/datasets/babi-tasks-v1-2.tar.gz')
raise
tar = tarfile.open(path)


challenges = {
# QA1 with 10,000 samples
Expand All @@ -112,8 +112,9 @@ def vectorize_stories(data):
challenge = challenges[challenge_type]

print('Extracting stories for the challenge:', challenge_type)
train_stories = get_stories(tar.extractfile(challenge.format('train')))
test_stories = get_stories(tar.extractfile(challenge.format('test')))
with tarfile.open(path) as tar:
train_stories = get_stories(tar.extractfile(challenge.format('train')))
test_stories = get_stories(tar.extractfile(challenge.format('test')))

vocab = set()
for story, q, answer in train_stories + test_stories:
Expand Down
7 changes: 4 additions & 3 deletions examples/babi_rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def vectorize_stories(data, word_idx, story_maxlen, query_maxlen):
'$ wget http://www.thespermwhale.com/jaseweston/babi/tasks_1-20_v1-2.tar.gz\n'
'$ mv tasks_1-20_v1-2.tar.gz ~/.keras/datasets/babi-tasks-v1-2.tar.gz')
raise
tar = tarfile.open(path)

# Default QA1 with 1000 samples
# challenge = 'tasks_1-20_v1-2/en/qa1_single-supporting-fact_{}.txt'
# QA1 with 10,000 samples
Expand All @@ -169,8 +169,9 @@ def vectorize_stories(data, word_idx, story_maxlen, query_maxlen):
challenge = 'tasks_1-20_v1-2/en/qa2_two-supporting-facts_{}.txt'
# QA2 with 10,000 samples
# challenge = 'tasks_1-20_v1-2/en-10k/qa2_two-supporting-facts_{}.txt'
train = get_stories(tar.extractfile(challenge.format('train')))
test = get_stories(tar.extractfile(challenge.format('test')))
with tarfile.open(path) as tar:
train = get_stories(tar.extractfile(challenge.format('train')))
test = get_stories(tar.extractfile(challenge.format('test')))

vocab = set()
for story, q, answer in train + test:
Expand Down
Loading

0 comments on commit e736fb4

Please sign in to comment.