Hands-On Deep Learning Architectures with Python
上QQ阅读APP看书,第一时间看更新

Functional API

This is just another layout for coding the model graph. You can choose the following layout if you are more comfortable with Python style code writing:

from keras.models import Model
from keras.layers import Dense, Input

#defining input placeholder with input shape
inp = Input(shape = 100)

# layers
x = Dense(units = 128, activation = 'relu')
x = Dense(units = 64, activation = 'relu')

# taking output
predict = Dense(units = 4, activation = 'softmax')(x)

# defining model
model = Model(inputs = inp, outputs = predict)