[英]What are the differences between building a model with and without using Sequential() in Keras?
I have 2 build_model
functions as below: 我有2个
build_model
函数,如下所示:
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
? build_model01
和build_model02
什么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
). 实际上,有创建的模型之间使用功能API没有差别(即
build_model01
和为顺序模型创建的相同模型(即) build_model02
)。 You can further confirm this by checking the Sequential
class source code ; 您可以通过检查
Sequential
类源代码进一步确认这一点; as you can see, it is a subclass of Model
class. 如您所见,它是
Model
类的子类。 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). 当然,Keras功能API 为您提供了更大的灵活性 ,它使您可以创建具有复杂架构的模型(例如,具有多个输入/输出或多个分支的模型)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.