1

I have used the Functional API to create a model with three different output layers to test different activation functions. The problem is that the output line for each epoch is too long. I only want to look at the accuracy and not the loss.

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

I don't want the .fit() function to print the loss for each layer, only the accuracy. I searched all of Google and Tensorflow Documentation but couldn't find how to do it.

If you want the complete code, comment on this post. I will send it immediately.

Here is the model's summary:

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

Thank You and have a nice day ahead.

yudhiesh
  • 6,383
  • 3
  • 16
  • 49
  • 1
    The only way I can think of is to set verbose=0 in model.fit. That I believe stops all printing during training. Then you have to create a custom callback that will print the metric data you wish. Documentation on how to create a custom callback is at https://keras.io/guides/writing_your_own_callbacks/. Define the function on_epoch_end to print you metric data. – Gerry P Jan 14 '21 at 04:06
  • @GerryP you are right, verbose=0 will stop printing everything during training but what I want is that the model.fit function should print just the accuracy of each layer and not the loss. – Neil Lunavat Jan 14 '21 at 04:40

1 Answers1

0

Here is my shot at the custom callback. Note I assume that Sigmoid_accuracy, Softmax_accuracy and Softplus_accuracy are defined previously as metrics in model.compile. Here is the code for the custom callback

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)

in model.fit include callbacks=[Print_Acc]

Gerry P
  • 7,662
  • 3
  • 10
  • 20