当我阅读Keras文档时,我发现了一个称为功能API的术语。
Keras中的功能性API是什么意思?
有人可以帮助您了解Keras中的基本和重要术语吗?
谢谢
这是创建模型的一种方法。可以使用顺序模型(教程here):
例如:
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential([
Dense(32, input_shape=(784,)),
Activation('relu'),
Dense(10),
Activation('softmax'),
])
您可以使用输入功能来调用它。第二种方法是实用的(教程here)。您可以在每一层中调用下一层,这将使您在创建模型时具有更大的灵活性,例如:
from keras.layers import Input, Dense
from keras.models import Model
# This returns a tensor
inputs = Input(shape=(784,))
# a layer instance is callable on a tensor, and returns a tensor
output_1 = Dense(64, activation='relu')(inputs)
# you call layer with another layer to create model
output_2 = Dense(64, activation='relu')(output_1)
predictions = Dense(10, activation='softmax')(output_2)
# This creates a model that includes
# the Input layer and three Dense layers
model = Model(inputs=inputs, outputs=predictions)
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
model.fit(data, labels) # starts training
您也可以将Model
子类化,类似于Chainer或PyTorch提供给用户的内容,但是在Keras中使用了很多。