簡體   English   中英

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

[英]What is meant by sequential model in Keras

我最近開始使用 Tensorflow 進行深度學習。 我發現這個語句model = tf.keras.models.Sequential()有點不同。 我不明白這到底是什么意思,還有其他深度學習模型嗎? 我在 MatconvNet(卷積神經網絡的 Matlab 庫)上做了很多工作。 從未在其中看到任何順序定義。

構建 Keras 模型有兩種方法:順序和功能。

順序 API 允許您為大多數問題逐層創建模型。 它的局限性在於它不允許您創建共享層或具有多個輸入或輸出的模型。

或者,函數式 API 允許您創建具有更大靈活性的模型,因為您可以輕松定義模型,其中層連接到的不僅僅是上一層和下一層。 事實上,您可以將層連接到(字面上)任何其他層。 因此,創建復雜的網絡,如 siamese 網絡和殘差網絡成為可能。

有關更多詳細信息,請訪問: https : //machinelearningmastery.com/keras-functional-api-deep-learning/

根據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'),
])

您還可以通過 .add() 方法簡單地添加圖層:

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

更多詳情請點擊這里

Sequential模型是層的線性堆棧。

ConvNets 的常見架構是順序架構。 然而,一些架構不是線性堆棧。 例如,孿生網絡是具有一些共享層的兩個並行神經網絡。 更多例子在這里

正如其他人已經提到的那樣,“順序模型是層的線性堆棧。

Sequential 模型 API 是一種創建深度學習模型的方法,其中創建 Sequential 類的實例,並創建模型層並將其添加到其中。

添加圖層最常用的方法是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