dgl.save_graphs¶
-
dgl.
save_graphs
(filename, g_list, labels=None)[source]¶ Save graphs and optionally their labels to file.
Besides saving to local files, DGL supports writing the graphs directly to S3 (by providing a
"s3://..."
path) or to HDFS (by providing"hdfs://..."
a path).The function saves both the graph structure and node/edge features to file in DGL’s own binary format. For graph-level features, pass them via the
labels
argument.- Parameters
Examples
>>> import dgl >>> import torch as th
Create
DGLGraph
objects and initialize node and edge features.>>> g1 = dgl.graph(([0, 1, 2], [1, 2, 3])) >>> g2 = dgl.graph(([0, 2], [2, 3])) >>> g2.edata["e"] = th.ones(2, 4)
Save Graphs into file
>>> from dgl.data.utils import save_graphs >>> graph_labels = {"glabel": th.tensor([0, 1])} >>> save_graphs("./data.bin", [g1, g2], graph_labels)
See also