keras在搭建神經網路模型以及訓練神經網路方面,簡單又好用,總結幾個keras的API使用,持續更新。當然也可以通過keras官網進行學習。https://keras.io/ 模型可視化
將模型結構圖儲存為圖片。
from keras.utils import plot_modelplot_model(model, to_file='model.png')
plot_model接收兩個選擇性參數:
show_shapes:指定是否顯示輸出資料的形狀,預設為Falseshow_layer_names:指定是否顯示層名稱,預設為True
訓練過程可視化
history = model.fit(Xtr_more, Ytr_more, batch_size=batch_size, epochs=50, verbose=1, callbacks=[earlyStopping, mcp_save, reduce_lr_loss], validation_split=0.25)print(history.history.keys())fig = plt.figure()plt.plot(history.history['acc'])plt.plot(history.history['val_acc'])plt.title('model accuracy')plt.ylabel('accuracy')plt.xlabel('epoch')plt.legend(['train', 'test'], loc='upper left')plt.plot(history.history['loss'])plt.plot(history.history['val_loss'])plt.title('model loss')plt.ylabel('loss')plt.xlabel('epoch')plt.legend(['train', 'test'], loc='lower left')#fig.savefig('performance.png')