When you run a Keras neural network model you might see something like this in the console:
Epoch 1/3 6/1000 [..............................] - ETA: 7994
You can redirect the sys.stdout object to a file before the model.fit method and reassign it to the standard console after model.fit method as follows:
import sys oldStdout = sys.stdout file = open('logFile', 'w') sys.stdout = file model.fit(Xtrain, Ytrain) sys.stdout = oldStdout