![](/img/trans.png)
[英]Training a Network designed using tensorflow.keras.Model and the keras functional API causes Python crash
[英]How to print accuracy of different activation layers while training a Keras functional API model? (Tensorflow Python)
我使用 Functional API 創建了一個 model 和三個不同的 output 層來測試不同的激活函數。 問題是每個時期的 output 行太長了。 我只想看准確率而不是損失。
Epoch 1/5
1875/1875 - 4s - loss: 3.7070 - Sigmoid_loss: 1.1836 - Softmax_loss: 1.2291 - Softplus_loss: 1.2943 - Sigmoid_accuracy: 0.9021 - Softmax_accuracy: 0.9020 - Softplus_accuracy: 0.5787
我不希望.fit()
function 打印每一層的損失,只打印精度。 我搜索了所有 Google 和 Tensorflow 文檔,但找不到如何操作。
如果你想要完整的代碼,請評論這篇文章。 我會立即發送。
這是模型的摘要:
Model: "model"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
InputLayer (InputLayer) [(32, 784)] 0
__________________________________________________________________________________________________
FirstHidden (Dense) (32, 512) 401920 InputLayer[0][0]
__________________________________________________________________________________________________
SecondHidden (Dense) (32, 256) 131328 FirstHidden[0][0]
__________________________________________________________________________________________________
Sigmoid (Dense) (32, 10) 2570 SecondHidden[0][0]
__________________________________________________________________________________________________
Softmax (Dense) (32, 10) 2570 SecondHidden[0][0]
__________________________________________________________________________________________________
Softplus (Dense) (32, 10) 2570 SecondHidden[0][0]
==================================================================================================
Total params: 540,958
Trainable params: 540,958
Non-trainable params: 0
__________________________________________________________________________________________________
None
謝謝你,祝你有美好的一天。
這是我對自定義回調的拍攝。 注意我假設 Sigmoid_accuracy、Softmax_accuracy 和 Softplus_accuracy 之前在 model.compile 中定義為指標。 這是自定義回調的代碼
class Print_Acc(keras.callbacks.Callback):
def __init__(self):
super(Print_Acc, self).__init__()
def on_epoch_end(self, epoch, logs=None): # method runs on the end of each epoch
sig_acc=logs.get('Sigmoid_accuracy')
softmax_acc =logs.get('Softmax_accuracy')
softplus_acc =logs.get('Softplus_accuracy')
print('For epoch ',epoch, ' sig acc= ', sig_acc, ' softmac acc= ', softmax_acc, ' softplus acc= ', softplus_acc)
在 model.fit 中包含回調=[Print_Acc]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.