def _serialize_graph(ops):
"""
Serializes a graph and returns the actual protobuf python object (rather than serialized
byte string as done by `serialize_graph`).
"""
assert isinstance(ops, Iterable), "Ops passed into `serialize_graph` must be an iterable"
ops = Op.all_op_references(ops)
pb_ops = []
pb_edges = []
for op in ops:
pb_ops.append(op_to_protobuf(op))
add_edges(pb_edges, pb_ops, op)
graph_def = ops_pb.GraphDef()
for edge in pb_edges:
temp = graph_def.edges.add()
temp.CopyFrom(edge)
for op in pb_ops:
temp = graph_def.ops.add()
temp.CopyFrom(op)
return graph_def
评论列表
文章目录