项目作者: keras-team

项目描述 :
Keras community contributions
高级语言: Python
项目地址: git://github.com/keras-team/keras-contrib.git
创建时间: 2017-01-25T02:26:49Z
项目社区:https://github.com/keras-team/keras-contrib

开源协议:MIT License

下载


keras-contrib : Keras community contributions

Keras-contrib is deprecated. Use TensorFlow Addons.

The future of Keras-contrib:

We’re migrating to tensorflow/addons. See the announcement here.

Build Status

This library is the official extension repository for the python deep learning library Keras. It contains additional layers, activations, loss functions, optimizers, etc. which are not yet available within Keras itself. All of these additional modules can be used in conjunction with core Keras models and modules.

As the community contributions in Keras-Contrib are tested, used, validated, and their utility proven, they may be integrated into the Keras core repository. In the interest of keeping Keras succinct, clean, and powerfully simple, only the most useful contributions make it into Keras. This contribution repository is both the proving ground for new functionality, and the archive for functionality that (while useful) may not fit well into the Keras paradigm.


Installation

Install keras_contrib for keras-team/keras

For instructions on how to install Keras,
see the Keras installation page.

  1. git clone https://www.github.com/keras-team/keras-contrib.git
  2. cd keras-contrib
  3. python setup.py install

Alternatively, using pip:

  1. sudo pip install git+https://www.github.com/keras-team/keras-contrib.git

to uninstall:

  1. pip uninstall keras_contrib

Install keras_contrib for tensorflow.keras

  1. git clone https://www.github.com/keras-team/keras-contrib.git
  2. cd keras-contrib
  3. python convert_to_tf_keras.py
  4. USE_TF_KERAS=1 python setup.py install

to uninstall:

  1. pip uninstall tf_keras_contrib

For contributor guidelines see CONTRIBUTING.md


Example Usage

Modules from the Keras-Contrib library are used in the same way as modules within Keras itself.

  1. from keras.models import Sequential
  2. from keras.layers import Dense
  3. import numpy as np
  4. # I wish Keras had the Parametric Exponential Linear activation..
  5. # Oh, wait..!
  6. from keras_contrib.layers.advanced_activations import PELU
  7. # Create the Keras model, including the PELU advanced activation
  8. model = Sequential()
  9. model.add(Dense(100, input_shape=(10,)))
  10. model.add(PELU())
  11. # Compile and fit on random data
  12. model.compile(loss='mse', optimizer='adam')
  13. model.fit(x=np.random.random((100, 10)), y=np.random.random((100, 100)), epochs=5, verbose=0)
  14. # Save our model
  15. model.save('example.h5')

A Common “Gotcha”

As Keras-Contrib is external to the Keras core, loading a model requires a bit more work. While a pure Keras model is loadable with nothing more than an import of keras.models.load_model, a model which contains a contributed module requires an additional import of keras_contrib:

  1. # Required, as usual
  2. from keras.models import load_model
  3. # Recommended method; requires knowledge of the underlying architecture of the model
  4. from keras_contrib.layers import PELU
  5. from keras_contrib.layers import GroupNormalization
  6. # Load our model
  7. custom_objects = {'PELU': PELU, 'GroupNormalization': GroupNormalization}
  8. model = load_model('example.h5', custom_objects)