2

I am new to python. How to dynamically save the output from the fit() provided by keras to a text file ?

suppose the output is

Epoch 1/30
904/904 [==============================] - 488s - loss: 0.5103 - acc: 0.7505 - val_loss: 0.3322 - val_acc: 0.8669

For the first epoch, I want to write this into a text file immediately. Then I want to append the next output:

Epoch 2/30
904/904 [==============================] - 471s - loss: 0.3982 - acc: 0.8190 - val_loss: 0.2841 - val_acc: 0.8869

To the same text file and so on. That is, I want to dynamically update the file every time. How do I do it? is it possible to use the capture magic for this?

AChampion
  • 29,683
  • 4
  • 59
  • 75
Abhijit Balaji
  • 1,870
  • 4
  • 17
  • 40
  • 1
    You can use keras callbacks, see: https://stackoverflow.com/questions/38445982/how-to-log-keras-loss-output-to-a-file – AChampion Jul 06 '17 at 05:14
  • 1
    Or `%%capture` magic see: https://stackoverflow.com/questions/27994137/how-to-save-the-output-of-a-cell-in-ipython-notebook – AChampion Jul 06 '17 at 05:17
  • See also this thread about saving the losses to `history`: https://stackoverflow.com/questions/36952763/how-to-return-history-of-validation-loss-in-keras – petezurich Jul 06 '17 at 06:41
  • @AChampion. Thanks for your reply. I am already using the history call back and I am storing it to a csv file after the whole program has run (say after completing 30epochs) .I want to store it in a text file or a log file dynamically i.e after completion of a single epoch it should be saved.(similar to the example in the question). Is there a way to do it? And I am unfamiliar with using %%capture. Can you please enlighten me on that? Thanks – Abhijit Balaji Jul 06 '17 at 09:47

0 Answers0