model.add(Convolution2D(nb_filter=32, nb_row=3, nb_col=3, dim_ordering="th", border_mode="same", bias=False, init="uniform")) model.add(Convolution2D(nb_filter=32, nb_row=3, nb_col=3, dim_ordering="th", border_mode="same", bias=False, init="uniform")) model.add(AveragePooling2D(pool_size=(2, 2), dim_ordering="th")) model.add(Flatten()) model.add(Dense(output_dim=1000, activation="sigmoid")) model.add(Dense(output_dim=1000, activation="sigmoid")) model.add(Dense(output_dim=10, activation="sigmoid")) with open("digits_model.json", "w") as f: f.write(model.to_json()) plot(model, to_file="digits_model.png", show_shapes=True) model.compile(loss="mse", optimizer="rmsprop", metrics=["accuracy"]) model.fit(train_digits, train_labels_one_hot, batch_size=32, nb_epoch=10, callbacks=[history]) model.save_weights("digits_model_weights.hdf5") predict_labels = model.predict_classes(test_digits) print(classification_report(test_labels, predict_labels)) print(accuracy_score(test_labels, predict_labels)) print(confusion_matrix(test_labels, predict_labels)) 五、参考书目 [1]《最优化导论》(美)Edwin K. P. Chong(美)Stanislaw H. Zak [2]《神经网络设计》(美)Martin T.Hagan(美)Howard B.Demuth(美)Mark Beale ©本文为机器之心转载文章,转载请联系本公众号获得授权。 ?------------------------------------------------ 加入机器之心(全职记者/实习生):[email protected] 投稿或寻求报道:[email protected] 广告&商务合作:[email protected] (责任编辑:本港台直播) |