--- title: TensorFlow 1.x + Keras tags: AI/TF-Keras --- # TensorFlow 1.x + Keras By 蓉爸 Created: 2019-10-24 Revised: 2022-12-11  --- ## 環境: - Anaconda: 2019-10 版 - Python: 3.7.4 - TensorFlow: 1.14.0 - Keras: 2.3.1 --- ## 狀況: 在執行以下程式碼時, ```python= show_train_history(train_history,'acc','val_acc') ``` 發生錯誤: ```typescript= KeyError Traceback (most recent call last) <ipython-input-15-b94c5e09c9c0> in <module> ----> 1 show_train_history(train_history,'acc','val_acc') 2 #show_train_history(train_history,'accuracy','loss') <ipython-input-14-11fefc73ba88> in show_train_history(train_history, train, validation) 1 import matplotlib.pyplot as plt 2 def show_train_history(train_history,train,validation): ----> 3 plt.plot(train_history.history[train]) 4 plt.plot(train_history.history[val_acc]) 5 plt.title('Train History') KeyError: 'acc' ``` --- ## 解法: 變更數入參數: acc --> accuracy val_acc --> loss ```python= show_train_history(train_history,'accuracy','loss') ``` 就能跑出正確結果:  Ref: - Convolutional Neural Net-Keras-val_acc Keyerror 'acc' https://stackoverflow.com/questions/42689066/convolutional-neural-net-keras-val-acc-keyerror-acc
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up