文档章节

Keras: 基于Theano和TensorFlow的深度学习库

openthings
 openthings
发布于 2016/09/12 15:00
字数 972
阅读 223
收藏 2

Keras.ioGithub源码

Keras: 基于Theano和TensorFlow的深度学习库

简介

Keras is a minimalist, highly modular neural networks library, written in Python and capable of running on top of either TensorFlow 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 total modularity, minimalism, and extensibility).
  • supports both convolutional networks and recurrent networks, as well as combinations of the two.
  • supports arbitrary connectivity schemes (including multi-input and multi-output training).
  • runs seamlessly on CPU and GPU.

Read the documentation at Keras.io.

Keras is compatible with: Python 2.7-3.5.


指南

  • Modularity. A model is understood as a sequence or a graph of standalone, fully-configurable modules that can be plugged together with as little 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.

  • Minimalism. Each module should be kept short and simple. Every piece of code should be transparent upon first reading. No black magic: it hurts iteration speed and ability to innovate.

  • Easy extensibility. New modules are dead 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.


快速入门: 30 秒进入 Keras

The core data structure of Keras is a model, a way to organize layers. The main type of model is the Sequential model, a linear stack of layers. For more complex architectures, you should use the Keras functional API.

Here's the Sequential model:

from keras.models import Sequential

model = Sequential()

Stacking layers is as easy as .add():

from keras.layers import Dense, Activation

model.add(Dense(output_dim=64, input_dim=100))
model.add(Activation("relu"))
model.add(Dense(output_dim=10))
model.add(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).

from keras.optimizers import SGD
model.compile(loss='categorical_crossentropy', optimizer=SGD(lr=0.01, momentum=0.9, nesterov=True))

You can now iterate on your training data in batches:

model.fit(X_train, Y_train, nb_epoch=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=32)

Or generate predictions on new data:

classes = model.predict_classes(X_test, batch_size=32)
proba = model.predict_proba(X_test, batch_size=32)

Building a question answering system, an image classification model, a Neural Turing Machine, a word2vec embedder 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.


安装

Keras uses the following dependencies:

  • numpy, scipy
  • pyyaml
  • HDF5 and h5py (optional, required if you use model saving/loading functions)
  • Optional but recommended if you use CNNs: cuDNN.

When using the Theano backend:

When using the TensorFlow backend:

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

sudo python setup.py install

You can also install Keras from PyPI:

sudo pip install keras

从 Theano 切换到 TensorFlow

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


支持

You can ask questions and join the development discussion on the Keras Google group.

You can also post bug reports and feature requests in Github issues. Make sure to read our guidelines first.


为什么取名 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).


© 著作权归作者所有

共有 人打赏支持
openthings
粉丝 301
博文 1110
码字总数 636345
作品 1
东城
架构师
私信 提问
开源的机器学习框架应当如何选择?

为何要选择机器学习框架呢?使用开源工具的好处不仅仅在于其可用性。通常来说,如此级别的项目均有大量的数据工程师和数据科学家愿意去分享数据集和前期训练模型。比如,你可以使用分类模型训...

小欣妹妹
2018/04/20
0
0
Keras还是TensorFlow?深度学习框架选型实操分享

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dQCFKyQDXYm3F8rB0/article/details/83005530 译者| 王天宇、林椿眄 责编| Jane、琥珀 出品| AI科技大本营 深...

AI科技大本营
2018/10/09
0
0
送书&优惠丨对深度学习感兴趣的你,不了解这些就太OUT了!

点击上方“程序人生”,选择“置顶公众号” 第一时间关注程序猿(媛)身边的故事 TensorFlow是什么? TensorFlow的前身是谷歌大脑(google brain)团队研发的DistBelief。自创建以来,它便被...

csdnsevenn
2018/05/03
0
0
ArXiv 中最受欢迎的开源框架,TensorFlow 排名第一

近日 Keras 作者 François Chollet 近日在 Twitter 上公布了一项他所做的调查,统计了在过去三个月中 ArXiv 上(截至 3 月 7 日)被提及(mention)最多的几大开源框架。结果显示,谷歌开源...

周其
2018/03/11
4.1K
0
机器学习者必知的5种深度学习框架

雷锋网按:本文为雷锋字幕组编译的技术博客,原标题The 5 Deep Learning Frameworks Every Serious Machine Learner Should Be Familiar With,作者为James Le。 翻译 | 杨恕权 张晓雪 陈明霏...

雷锋字幕组
2018/05/03
0
0

没有更多内容

加载失败,请刷新页面

加载更多

租房软件隐私保护如同虚设

近日,苏州市民赵先生向江苏新闻广播新闻热线025-84658888反映,他在“安居客”手机应用软件上浏览二手房信息,并且使用该软件自动生成的虚拟号码向当地一家中介公司进行咨询。可电话刚挂不久...

linux-tao
21分钟前
1
0
分布式项目(五)iot-pgsql

书接上回,在Mapping server中,我们已经把数据都整理好了,现在利用postgresql存储历史数据。 iot-pgsql 构建iot-pgsql模块,这里我们写数据库为了性能考虑不在使用mybatis,换成spring jd...

lelinked
今天
2
0
一文分析java基础面试题中易出错考点

前言 这篇文章主要针对的是笔试题中出现的通过查看代码执行结果选择正确答案题材。 正式进入题目内容: 1、(单选题)下面代码的输出结果是什么? public class Base { private Strin...

一看就喷亏的小猿
今天
1
0
cocoapods 用法

cocoapods install pod install 更新本地已经install的仓库 更新所有的仓库 pod update --verbose --no-repo-update 更新制定的仓库 pod update ** --verbose --no-repo-update...

HOrange
今天
3
0
linux下socket编程实现一个服务器连接多个客户端

使用socekt通信一般步骤 1)服务器端:socker()建立套接字,绑定(bind)并监听(listen),用accept()等待客户端连接。 2)客户端:socker()建立套接字,连接(connect)服务器,连接上后...

shzwork
昨天
3
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部