gammagl.data.Dataset

class Dataset(root: str | None = None, transform: Callable | None = None, pre_transform: Callable | None = None, pre_filter: Callable | None = None, force_reload: bool = False)[source]

Bases: Dataset

Dataset base class for creating graph datasets. See here for the accompanying tutorial.

Parameters:
  • root (str, optional) – Root directory where the dataset should be saved. (optional: None)

  • transform (callable, optional) – A function/transform that takes in an gammagl.data.Graph object and returns a transformed version. The data object will be transformed before every access. (default: None)

  • pre_transform (callable, optional) – A function/transform that takes in an gammagl.data.Graph object and returns a transformed version. The graph object will be transformed before being saved to disk. (default: None)

  • pre_filter (callable, optional) – A function that takes in an gammagl.data.Graph object and returns a boolean value, indicating whether the graph object should be included in the final dataset. (default: None)

  • force_reload (bool, optional) – Whether to re-process the dataset.(default: False)

property raw_file_names: str | List[str] | Tuple

The name of the files in the self.raw_dir folder that must be present in order to skip downloading.

property processed_file_names: str | List[str] | Tuple

The name of the files in the self.processed_dir folder that must be present in order to skip processing.

download()[source]

Downloads the dataset to the self.raw_dir folder.

process()[source]

Processes the dataset to the self.processed_dir folder.

len() int[source]

Returns the number of graphs stored in the dataset.

get(idx: int) Graph[source]

Gets the data object at index idx.

save_data(obj, file_name)[source]

Support save data according to different backend.

load_data(file_name)[source]

Support load data according to different backend.

property num_node_features: int

Returns the number of features per node in the dataset.

property num_features: int

Returns the number of features per node in the dataset. Alias for num_node_features.

property num_edge_features: int

Returns the number of features per edge in the dataset.

property raw_paths: List[str]

The absolute filepaths that must be present in order to skip downloading.

property processed_paths: List[str]

The absolute filepaths that must be present in order to skip processing.

index_select(idx: slice | ndarray | Sequence) Dataset[source]

Creates a subset of the dataset from specified indices idx. Indices idx can be a slicing object, e.g., [2:5], a list, a tuple, or a Tensor or np.ndarray of type long or bool.

shuffle(return_perm: bool = False)[source]

Randomly shuffles the examples in the dataset.

Parameters:

return_perm (bool, optional) – If set to True, will also return the random permutation used to shuffle the dataset. (default: False)