dgl.load_graphs(filename, idx_list=None)[source]

Load graphs and optionally their labels from file saved by save_graphs().

Besides loading from local files, DGL supports loading the graphs directly from S3 (by providing a "s3://..." path) or from HDFS (by providing "hdfs://..." a path).

  • filename (str) – The file name to load graphs from.

  • idx_list (list[int], optional) – The indices of the graphs to be loaded if the file contains multiple graphs. Default is loading all the graphs stored in the file.


  • graph_list (list[DGLGraph]) – The loaded graphs.

  • labels (dict[str, Tensor]) – The graph labels stored in file. If no label is stored, the dictionary is empty. Regardless of whether the idx_list argument is given or not, the returned dictionary always contains the labels of all the graphs.


Following the example in save_graphs().

>>> from dgl.data.utils import load_graphs
>>> glist, label_dict = load_graphs("./data.bin") # glist will be [g1, g2]
>>> glist, label_dict = load_graphs("./data.bin", [0]) # glist will be [g1]

See also