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

Building the network

For this example, you'll define the following:

  • The input layer, which you should expect for each piece of MNIST data, as it tells the network the number of inputs
  • Hidden layers, as they recognize patterns in data and also connect the input layer to the output layer
  • The output layer, as it defines how the network learns and gives a label as the output for a given image, as follows:
# Defining the neural network
def build_model():
    model = Sequential()
    model.add(Dense(512, input_shape=(784,)))
    model.add(Activation('relu')) # An "activation" is just a non-linear function that is applied to the output
 # of the above layer. In this case, with a "rectified linear unit",
 # we perform clamping on all values below 0 to 0.
                           
    model.add(Dropout(0.2))   #With the help of Dropout helps we can protect the model from memorizing or "overfitting" the training data
    model.add(Dense(512))
    model.add(Activation('relu'))
    model.add(Dropout(0.2))
    model.add(Dense(10))
    model.add(Activation('softmax')) # This special "softmax" activation,
    #It also ensures that the output is a valid probability distribution,
    #Meaning that values obtained are all non-negative and sum up to 1.
    return model
#Building the model
model = build_model()
model.compile(optimizer='rmsprop',
          loss='categorical_crossentropy',
          metrics=['accuracy'])
主站蜘蛛池模板: 酒泉市| 宁晋县| 九江县| 将乐县| 轮台县| 信宜市| 清水县| 临武县| 东乌珠穆沁旗| 昭苏县| 兴和县| 潜江市| 清苑县| 南雄市| 台江县| 大同县| 镇平县| 凤冈县| 石景山区| 泰和县| 湄潭县| 渝北区| 定南县| 贵港市| 神木县| 岗巴县| 永德县| 定结县| 富平县| 会泽县| 增城市| 齐河县| 镇赉县| 壶关县| 阿图什市| 南郑县| 黄冈市| 通渭县| 诸城市| 射阳县| 金沙县|