def _deserialize_graph_ops_edges(pb_ops, pb_edges): """ Given a set of serialized ops and edges, this will deserialize them and return the list of all ops in that graph. """ 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 _deserialize_graph(graph_def)
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