If you want to format the summary, you can pass the function printto model.summary()and output it to a file as follows:
def myprint(s):
with open('modelsummary.txt','w') as f:
print(s, file=f)
model.summary(print_fn=myprint)
Alternatively, you can serialize it to a json or yaml string using model.to_json()or model.to_yaml(), which you can import later.
Edit
In Python 3.4+, a more pythonic way to do this is with contextlib.redirect_stdout
import redirect_stdout from contextlib
with open('modelsummary.txt', 'w') as f:
with redirect_stdout(f):
model.summary()
source
share