简体   繁体   中英

What are the differences between building a model with and without using Sequential() in Keras?

I have 2 build_model functions as below:

def build_model01():
    X_input = Input(shape=(784,))
    Y = Dense(1, activation='sigmoid')(X_input)
    model = Model(inputs = X_input, outputs = Y, name='build_model')
    return model

def build_model02():
    model = Sequential()
    model.add(Dense(input_dim=784,units=1,activation='sigmoid'))
    return model

What are the differences between build_model01 and build_model02 ? Are they practically the same? Will the differences affect other layers?

Actually, there is no difference between the models created using the functional API (ie build_model01 ) and the same model created as a Sequential model (ie build_model02 ). You can further confirm this by checking the Sequential class source code ; as you can see, it is a subclass of Model class. Of course, Keras functional API gives you more flexibility and it lets you create models with complex architectures (eg models with multiple inputs/outputs or multiple branches).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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