有model.summary() 方法 https://keras.io/models/about-keras-models/在喀拉斯。它将表打印到标准输出。是否可以将其保存到文件中?
如果您想要摘要的格式,您可以传递print
功能为model.summary()
并以这种方式输出到文件:
def myprint(s):
with open('modelsummary.txt','a') as f:
print(s, file=f)
model.summary(print_fn=myprint)
或者,您可以将其序列化为 json 或 yaml 字符串model.to_json()
or model.to_yaml()
稍后可以导入回来。
Edit
在 Python 3.4+ 中执行此操作的一种更 Pythonic 的方法是使用contextlib.redirect_stdout
from contextlib import redirect_stdout
with open('modelsummary.txt', 'w') as f:
with redirect_stdout(f):
model.summary()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)