keras函数式API定义层的模型
from tensorflow.keras import models, layers
之后,以下的用Sequential来建立的层:
nw = models.Sequential()
nw.add(layers.Dense(32,activation='relu', input_shape=(784,)))
nw.add(layers.Dense(10,activation='softmax')
可以更改为以下用自定义API函数建立层:
t_i = layers.input(shape=(786,))
x = layers.Dense(32, activation='relu')(t_i)
t_o = layers.Dense(10,activation='softmax')(x)
model = models.model(inputs=t_i, outputs=t_o)