分享

keras reademe

 木俊 2018-06-20

翻译自:https://github.com/keras-team/keras

Keras: Deep Learning for humans

Keras logo

Build Status license

You have just found Keras.你刚刚找到keras。

Keras is a high-level neural networks API, written in Python and capable of running on top of TensorFlowCNTK, 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.

Keras是一个高级神经网络API,用Python编写,能够在TensorFlow,CNTK或Theano之上运行。 它的开发着重于实现快速实验。 能够以最少的可能延迟从想法到结果是做好研究的关键。

Use Keras if you need a deep learning library that:

如果您需要深度学习库,请使用Keras:

  • 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.
  • 允许简单快速的原型设计(通过用户友好性,模块化和可扩展性)。
  • 支持卷积网络和经常性网络,以及两者的组合。
  • 在CPU和GPU上无缝运行。

Read the documentation at Keras.io.

阅读Keras.io的文档。

Keras is compatible with: Python 2.7-3.6.

Keras兼容: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.

  • 用户友好。 Keras是为人类设计的API,而不是机器。 它将用户体验放在前面和中心。 Keras遵循减少认知负荷的最佳实践:它提供了一致且简单的API,它将常见用例所需的用户操作数量降至最低,并且在用户错误时提供清晰且可操作的反馈。

  • 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.

  • 易于扩展。 新模块很容易添加(作为新的类和功能),现有的模块提供了充足的示例。 为了能够轻松创建新的模块,可以提高总体表现力,使Keras适用于高级研究。

  • 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.

  • 使用Python。 声明格式没有单独的模型配置文件。 模型在Python代码中描述,这些代码紧凑,易于调试,并且易于扩展。


Getting started: 30 seconds to Keras

开始:keras 30秒

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.

Keras的核心数据结构是一种模型,一种组织图层的方法。 最简单的模型是Sequential模型,这是一个线性堆叠层。 对于更复杂的体系结构,您应该使用Keras功能API,它允许构建任意图层的图层。

Here is the Sequential model:

这是Sequential模型:

from keras.models import Sequential

model = Sequential()

Stacking layers is as easy as .add():

堆叠图层如.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():

一旦你的模型看起来不错,用.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).

如果你需要,你可以进一步配置你的优化器。 Keras的核心原则是使事情变得相当简单,同时允许用户在需要时能够完全控制(最终控制是源代码的易扩展性)。

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:

有关Keras的更深入的教程,您可以查看:

In the examples folder of the repository, you will find more advanced models: question-answering with memory networks, text generation with stacked LSTMs, etc.

在存储库的examples文件夹中,您可以找到更多高级模型:使用内存网络回答问题,使用堆叠LSTM生成文本等。


Installation

Before installing Keras, please install one of its backend engines: TensorFlow, Theano, or CNTK. We recommend the TensorFlow backend.

在安装Keras之前,请安装其后端引擎之一:TensorFlow,Theano或CNTK。 我们推荐TensorFlow后端。

You may also consider installing the following optional dependencies:

您也可以考虑安装以下可选依赖项:

  • cuDNN (recommended if you plan on running Keras on GPU).  如果您打算在GPU上运行Keras,建议使用
  • HDF5 and h5py (required if you plan on saving Keras models to disk).  如果您计划将Keras型号保存到磁盘,则需要此选项
  • graphviz and pydot (used by visualization utilities to plot model graphs). 可视化工具使用它绘制模型图

Then, you can install Keras itself. There are two ways to install Keras:

然后,您可以安装Keras本身。 有两种方法可以安装Keras:

  • Install Keras from PyPI (recommended):
sudo pip install keras

If you are using a virtualenv, you may want to avoid using sudo:

如果你使用的是virtualenv,你可能想避免使用sudo:

pip install keras
  • Alternatively: install Keras from the GitHub source:
  • 或者:从GitHub源安装Keras:

First, clone Keras using git:

git clone https://github.com/keras-team/keras.git

Then, cd to the Keras folder and run the install command:

然后,cd到Keras文件夹并运行安装命令:

cd keras
sudo python setup.py install

Configuring your Keras backend

配置您的Keras后端

By default, Keras will use TensorFlow as its tensor manipulation library. Follow these instructions to configure the Keras backend.

默认情况下,Keras将使用TensorFlow作为张量操作库。 按照这些说明配置Keras后端。


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.

您也可以在GitHub问题中发布错误报告和功能请求(仅)。 请务必先阅读我们的指南。


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(κέρας)意为希腊语中的号角。 它是从古希腊和拉丁文学中提及的一种文学形象,首次在奥德赛发现,那里的梦幻灵魂(Oneiroi,单一的Oneiros)被分为那些用假象来欺骗人类,通过象牙门到达地球的人 ,还有那些宣布未来将要来临的人们,他们从喇叭口到达。 这是一个关于κέρας(horn)/κραίνω(履行)和ἐλέφας(象牙)/ἐλεφαίρομαι(欺骗)这两个词的游戏。

Keras was initially developed as part of the research effort of project ONEIROS (Open-ended Neuro-Electronic Intelligent Robot Operating System).

Keras最初是作为项目ONEIROS(开放式神经电子智能机器人操作系统)研究工作的一部分而开发的。

"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).

“Oneiroi超出了我们的解密范围 - 他们可以肯定他们讲述了什么故事?并非所有男人都期待的事情发生了,有两扇门通向转瞬即逝的Oneiroi;一个是角,一个象牙。 穿过锯齿象牙的人是诡诈的,带有一个不会实现的信息;那些通过抛光角发出的信息在他们背后有真理,对于看到他们的人来说是完成的。“ 荷马,奥德赛19. 562 ff(Shewring翻译)。


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多