in scripts/grab_graphs.py [0:0]
def prase_graphs(gfile, dest_dir, graphs=None):
if dest_dir:
if os.path.isdir(dest_dir):
raise RuntimeError('Folder already exists: {}'.format(dest_dir))
os.mkdir(dest_dir)
if graphs is None:
graphs = []
graph, frame, last_frame, hashes = None, None, None, None
for line in gfile:
line = line.rstrip('\n')
if frame is not None:
if re.match(r'\s*$', line):
last_frame = frame
frame = None
else:
frame.append(line)
continue
if graph is not None:
m = re.match(r'## END_GRAPH$', line)
if m:
if dest_dir:
save_graph(graph,
os.path.join(dest_dir, 'graph_{:04d}'.format(len(graphs))))
graphs.append(
GraphInfo(
id=len(graphs),
graph=graph,
ngraph=normalize(graph),
frame=last_frame,
key='\n'.join(graph),
hashes=hashes))
graph, last_frame, hashes = None, None, None
else:
graph.append(line)
continue
m = re.match(r'TensorsGraphInfo:', line)
if m:
frame = []
continue
m = re.match(r'## BEGIN_GRAPH$', line)
if m:
graph = []
continue
m = re.match(r'Hashes: \(([^)]*)\)', line)
if m:
hashes = m.group(1)
continue
return graphs