Keras学习
本来做完模式识别的作业后,感觉现在读研完全避不开深度学习的坑,想系统的学一下keras,结果查询中文文档后发现翻译的不全,学也学不系统,干脆我自己来看英文文档,一边学一边翻译,以后自己要查询时也方便。(怨念~~~~)
前言:一个简单地keras模型步骤为:
sequential -> compile ->trian
getting started with the keras sequential model
Keras 的核心数据结构是 model,一种组织网络层的方式。最简单的模型是 Sequential 顺序模型,它由多个网络层线性堆叠。对于更复杂的结构,你应该使用 Keras 函数式 API,它允许构建任意的神经网络图。
sequential模型可以直接在一个模块里写好:
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential([
Dense(32, input_shape=(784,)),
Activation('relu'),
Dense(10),
Activation('softmax'),
])
也可以通过.add()一层一层的往上加:
model = Sequential()
model.add(Dense(32, input_dim=784))
model.add(Activation('relu'))
指定输入数据的shape
模型需要知道它要接受何种shape的input(输入的数据),因此,第一层layer(也只有第一层需要指定,因为接下来的layers可以自动推断这一层的shape)需要接收input的shape。有以下几种方式: