Load graphs and optionally their labels from file saved by :func:`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). Parameters ----------
(filename, idx_list=None)
| 147 | |
| 148 | |
| 149 | def load_graphs(filename, idx_list=None): |
| 150 | """Load graphs and optionally their labels from file saved by :func:`save_graphs`. |
| 151 | |
| 152 | Besides loading from local files, DGL supports loading the graphs directly |
| 153 | from S3 (by providing a ``"s3://..."`` path) or from HDFS (by providing |
| 154 | ``"hdfs://..."`` a path). |
| 155 | |
| 156 | Parameters |
| 157 | ---------- |
| 158 | filename: str |
| 159 | The file name to load graphs from. |
| 160 | idx_list: list[int], optional |
| 161 | The indices of the graphs to be loaded if the file contains multiple graphs. |
| 162 | Default is loading all the graphs stored in the file. |
| 163 | |
| 164 | Returns |
| 165 | -------- |
| 166 | graph_list: list[DGLGraph] |
| 167 | The loaded graphs. |
| 168 | labels: dict[str, Tensor] |
| 169 | The graph labels stored in file. If no label is stored, the dictionary is empty. |
| 170 | Regardless of whether the ``idx_list`` argument is given or not, |
| 171 | the returned dictionary always contains the labels of all the graphs. |
| 172 | |
| 173 | Examples |
| 174 | ---------- |
| 175 | Following the example in :func:`save_graphs`. |
| 176 | |
| 177 | >>> from dgl.data.utils import load_graphs |
| 178 | >>> glist, label_dict = load_graphs("./data.bin") # glist will be [g1, g2] |
| 179 | >>> glist, label_dict = load_graphs("./data.bin", [0]) # glist will be [g1] |
| 180 | |
| 181 | See Also |
| 182 | -------- |
| 183 | save_graphs |
| 184 | """ |
| 185 | # if it is local file, do some sanity check |
| 186 | check_local_file_exists(filename) |
| 187 | version = _CAPI_GetFileVersion(filename) |
| 188 | if version == 1: |
| 189 | dgl_warning( |
| 190 | "You are loading a graph file saved by old version of dgl. \ |
| 191 | Please consider saving it again with the current format." |
| 192 | ) |
| 193 | return load_graph_v1(filename, idx_list) |
| 194 | elif version == 2: |
| 195 | return load_graph_v2(filename, idx_list) |
| 196 | else: |
| 197 | raise DGLError("Invalid DGL Version Number.") |
| 198 | |
| 199 | |
| 200 | def load_graph_v2(filename, idx_list=None): |
no test coverage detected