logo
Loading...

day-78 - Cupoy

def build_mlp(input_shape, output_units=10, num_ne...

ml100-2-d78,ml100-2

day-78

2019/07/22 04:30 PM
機器學習新手論壇
蕭琮寶
觀看數:0
回答數:1
收藏數:0
ml100-2-d78
ml100-2

def build_mlp(input_shape, output_units=10, num_neurons=[512, 256, 128]):

    input_layer = keras.layers.Input(input_shape)

    

    for i, n_units in enumerate(num_neurons):

        if i == 0:

            x = keras.layers.Dense(units=n_units, activation="relu", name="hidden_layer"+str(i+1))(input_layer)

        else:

            x = keras.layers.Dense(units=n_units, activation="relu", name="hidden_layer"+str(i+1))(x)

    

    out = keras.layers.Dense(units=output_units, activation="softmax", name="output")(x)

    

    model = keras.models.Model(inputs=[input_layer], outputs=[out])

    return model


老師請問一下 if i == 0  後面接input_layer  是輸入層的意思嗎  

為甚麼輸入層不像輸出層一樣直接定義呢