keras - keras中函数式API是什么意思?
问题描述
当我阅读 Keras 文档时,我发现了一个称为功能 API 的术语。
Keras 中的函数式 API 是什么意思?
谁能帮助您理解 Keras 中的基本和重要术语?
谢谢
解决方案
这是一种创建模型的方法。可以使用顺序模型(此处为教程):
例如:
from keras.models import Sequential
from keras.layers import Dense, Activation
model = Sequential([
Dense(32, input_shape=(784,)),
Activation('relu'),
Dense(10),
Activation('softmax'),
])
您可以使用输入功能调用它。第二种方法是功能性的(这里是教程)。您可以使用下一个层调用每一层,这使您在创建模型时具有更大的灵活性,例如:
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 中被大量使用。
推荐阅读
- java - 在 Java Servlet 中设置 Log4j 2
- shopify-api - 棱镜集成字段:无法接收 Shopify 产品元字段
- javascript - React:在子上下文中访问时,父状态设置为默认值
- kotlin - 我想在实时数据 setValue 中输入一个变量
- c# - TiDB 索引没有被用于查询
- excel - 在电子邮件中使用单元格内容时如何保留文本中的换行符?
- java - 在列表适配器中单击时尝试更改图像视图的可绘制对象
- python-3.x - 如何创建具有真实值的直方图
- html - 在Angular 2+中动态溢出的路由器出口内容的底部附加页脚
- python - PyQt5 滚动失败并带有水平滑块