官术网_书友最值得收藏!

Building a deep neural network in Keras

Changing our model is as easy as redefining our previous build_network() function. Our input layer will stay the same because our input hasn't changed. Likewise, the output layer should remain the same. 

I'm going to add parameters to our network by adding additional hidden layers. I hope that by adding these hidden layers, our network can learn more complicated relationships between the input and output. I am going to start by adding four additional hidden layers; the first three will have 32 neurons and the fourth will have 16. Here's what it will look like:

And here's the associated code for building the model in Keras:

def build_network(input_features=None):
inputs = Input(shape=(input_features,), name="input")
x = Dense(32, activation='relu', name="hidden1")(inputs)
x = Dense(32, activation='relu', name="hidden2")(x)
x = Dense(32, activation='relu', name="hidden3")(x)
x = Dense(32, activation='relu', name="hidden4")(x)
x = Dense(16, activation='relu', name="hidden5")(x)
prediction = Dense(1, activation='linear', name="final")(x)
model = Model(inputs=inputs, outputs=prediction)
model.compile(optimizer='adam', loss='mean_absolute_error')
return model

As promised, very little of our code has changed. I've bolded the additional lines. The rest of our code can stay the same; however, you often have to train longer (for more epochs) as network complexity increases.

主站蜘蛛池模板: 翁源县| 河间市| 东安县| 延长县| 呼图壁县| 大同县| 桦川县| 津南区| 景谷| 丽江市| 文安县| 攀枝花市| 石门县| 奇台县| 玉林市| 萝北县| 射洪县| 福清市| 大同市| 浠水县| 阳曲县| 潜江市| 共和县| 枞阳县| 大竹县| 大名县| 嘉祥县| 嘉义县| 丰都县| 临城县| 浦东新区| 云南省| 香港 | 秦安县| 繁峙县| 肇州县| 义乌市| 和平县| 乐至县| 吉首市| 郑州市|