1.https://cbovar.github.io/ConvNetDraw/
2.参考链接这个作者把print信息写到log中也不错
from __future__ import absolute_import
import os
import sys
import os.path as osp
def mkdir_if_missing(dir_path):
if not os.path.exists(dir_path):
try:
os.mkdir(dir_path)
except OSError as e:
print(f'Cannot create {dir_path}!!!')
print(f'check permission!!!')
raise
class Logger(object):
def __init__(self, fpath=None):
self.console = sys.stdout
self.file = None
if fpath is not None:
mkdir_if_missing(os.path.dirname(fpath))
self.file = open(fpath, 'w')
def __del__(self):
self.close()
def __enter__(self):
pass
def __exit__(self, *args):
self.close()
def write(self, msg):
self.console.write(msg)
if self.file is not None:
self.file.write(msg)
self.flush()
def flush(self):
self.console.flush()
if self.file is not None:
self.file.flush()
os.fsync(self.file.fileno())
def close(self):
self.console.close()
if self.file is not None:
self.file.close()
参考: