2017-07-26 134 views
0

我使用張量流的Keras。而且我希望在訓練期間看到並將Kvariable保存爲numpy值。但「K.eval」效果不佳。有沒有解決方案?Keras保存中間變量

def acc(y_true, y_pred): 
    temp = K.eval(y_true) 
    ... 
    ... 
+0

你的意思是「不正常工作」 ?你究竟試過了什麼,結果或錯誤信息是什麼? – desertnaut

+0

是你尋找的答案嗎?如果是的話,請接受它 – desertnaut

回答

0

如果是培訓期間的準確性,那麼Keras會默認存儲此信息;如果你適合你的機型,如:

hist = model.fit(x_train, y_train, 
      batch_size=batch_size, 
      epochs=20, 
      verbose=1, 
      validation_data=(x_test, y_test)) 

然後訓練和驗證準確性&虧損爲每個時間段都存儲在字典hist.history

hist.history.keys() 
# ['acc', 'loss', 'val_acc', 'val_loss'] 
hist.history['val_acc'] # validation accuracy 
# [0.98140000000000005, 
# 0.98340000000000005, 
# 0.98740000000000006, 
# 0.98680000000000001, 
# 0.98750000000000004, 
# 0.98740000000000006, 
# 0.9869, 
# 0.98939999999999995, 
# 0.98819999999999997, 
# 0.98819999999999997, 
# 0.99039999999999995, 
# 0.9889, 
# 0.98919999999999997, 
# 0.98860000000000003, 
# 0.98780000000000001, 
# 0.98799999999999999, 
# 0.98819999999999997, 
# 0.9889, 
# 0.98909999999999998, 
# 0.98609999999999998]