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

Getting ready

To understand the impact of varying the optimizer on network accuracy, let's contrast the scenario laid out in previous sections (which was the Adam optimizer) with using a stochastic gradient descent optimizer in this section, while reusing the same MNIST training and test datasets that were scaled (the same data-preprocessing steps as those of step 1 and step 2 in the Scaling the dataset recipe):

model = Sequential()
model.add(Dense(1000, input_dim=784, activation='relu'))
model.add(Dense(10, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='sgd', metrics=['accuracy'])
history = model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=100, batch_size=32, verbose=1)

Note that when we used the stochastic gradient descent optimizer in the preceding code, the final accuracy after 100 epochs is ~98% (the code to generate the plots in the following diagram remains the same as the code we used in step 8 of the Training a vanilla neural network recipe):

However, we should also note that the model achieved the high accuracy levels much more slowly when compared to the model that used Adam optimization.

主站蜘蛛池模板: 瓦房店市| 衡阳市| 楚雄市| 永平县| 昭苏县| 玛沁县| 吴旗县| 綦江县| 马山县| 新巴尔虎右旗| 婺源县| 凤阳县| 山阳县| 永兴县| 如皋市| 岳池县| 怀远县| 景洪市| 凤庆县| 分宜县| 古浪县| 延吉市| 南丹县| 奉节县| 津市市| 阿拉善盟| 阿拉尔市| 阿拉善盟| 九江市| 湟源县| 四平市| 增城市| 滨州市| 镇巴县| 团风县| 阆中市| 江津市| 石阡县| 芒康县| 颍上县| 台东县|