简体   繁体   English

Keras中的顺序模型是什么意思

[英]What is meant by sequential model in Keras

I have recently started working Tensorflow for deep learning.我最近开始使用 Tensorflow 进行深度学习。 I found this statement model = tf.keras.models.Sequential() bit different.我发现这个语句model = tf.keras.models.Sequential()有点不同。 I couldn't understand what is actually meant and is there any other models as well for deep learning?我不明白这到底是什么意思,还有其他深度学习模型吗? I worked a lot on MatconvNet (Matlab library for convolutional neural network).我在 MatconvNet(卷积神经网络的 Matlab 库)上做了很多工作。 never saw any sequential definition in that.从未在其中看到任何顺序定义。

There are two ways to build Keras models: sequential and functional.构建 Keras 模型有两种方法:顺序和功能。

The sequential API allows you to create models layer-by-layer for most problems.顺序 API 允许您为大多数问题逐层创建模型。 It is limited in that it does not allow you to create models that share layers or have multiple inputs or outputs.它的局限性在于它不允许您创建共享层或具有多个输入或输出的模型。

Alternatively, the functional API allows you to create models that have a lot more flexibility as you can easily define models where layers connect to more than just the previous and next layers.或者,函数式 API 允许您创建具有更大灵活性的模型,因为您可以轻松定义模型,其中层连接到的不仅仅是上一层和下一层。 In fact, you can connect layers to (literally) any other layer.事实上,您可以将层连接到(字面上)任何其他层。 As a result, creating complex networks such as siamese networks and residual networks become possible.因此,创建复杂的网络,如 siamese 网络和残差网络成为可能。

for more details visit : https://machinelearningmastery.com/keras-functional-api-deep-learning/有关更多详细信息,请访问: https : //machinelearningmastery.com/keras-functional-api-deep-learning/

From the definition of Keras documentation the Sequential model is a linear stack of layers .You can create a Sequential model by passing a list of layer instances to the constructor:根据Keras文档的定义,Sequential 模型是线性堆栈。您可以通过将层实例列表传递给构造函数来创建 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'),
])

You can also simply add layers via the .add() method:您还可以通过 .add() 方法简单地添加图层:

model = Sequential()
model.add(Dense(32, input_dim=784))
model.add(Activation('relu'))

For More details click here更多详情请点击这里

The Sequential model is a linear stack of layers. Sequential模型是层的线性堆栈。

The common architecture of ConvNets is a sequential architecture. ConvNets 的常见架构是顺序架构。 However, some architectures are not linear stacks.然而,一些架构不是线性堆栈。 For example, siamese networks are two parallel neural networks with some shared layers.例如,孪生网络是具有一些共享层的两个并行神经网络。 More examples here .更多例子在这里

As others have already mentioned that " The Sequential model is a linear stack of layers. "正如其他人已经提到的那样,“顺序模型是层的线性堆栈。

The Sequential model API is a way of creating deep learning models where an instance of the Sequential class is created and model layers are created and added to it. Sequential 模型 API 是一种创建深度学习模型的方法,其中创建 Sequential 类的实例,并创建模型层并将其添加到其中。

The most common method to add layers is Piecewise添加图层最常用的方法是Piecewise

import keras
from keras.models import Sequential
from keras.layers import Dense

#initialising the classifier
#defining sequential i.e sequense of layers


classifier = Sequential()

# Adding the input layer and the first hidden layer
classifier.add(Dense(units = 6,activation = 'relu'))
#units = 6 as no. of column in X_train = 11 and y_train =1 --> 11+1/2

#Adding the second hidden lyer
classifier.add(Dense(units = 6, activation='relu'))

#adding the output layer
classifier.add(Dense(units = 1, activation = 'sigmoid))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM