Skip to content

Releases: EdisonLeeeee/GraphGallery

GraphGallery 1.0.0

21 Sep 13:57
Compare
Choose a tag to compare

GraphGallery 1.0.0

banner

GraphGallery is a gallery for benchmarking Graph Neural Networks (GNNs) and Graph Adversarial Learning with TensorFlow 2.x and PyTorch backend. Besides, Pytorch Geometric (PyG) backend and Deep Graph Library (DGL) backend now are available in GraphGallery.

Usages

  • read a graph dataset
import graphgallery as gg
data = gg.datasets.Planetoid('cora', root="~/GraphData/datasets", verbose=None)
graph = data.graph
splits = data.split_nodes()
  • run a simple GCN model for node classification task
from graphgallery.gallery.nodeclas import GCN
trainer = GCN()
trainer.setup_graph(graph)
trainer.build()
history = trainer.fit(train_nodes, val_nodes, epochs=100, verbose=1)
results = trainer.evaluate(test_nodes)
print(f'Test loss {results.loss:.5}, Test accuracy {results.accuracy:.2%}')

If you have any troubles, you can simply run trainer.help() for more messages, and it would print


**************************************Help Message for GCN******************************************
|First, initialize a trainer object, run `trainer=GCN(device='cpu', seed=42)                  |
------------------------------------------------------------------------------------------------------------
|Second, setup a graph, run `trainer.setup_graph()`, the reqiured argument are:                      |
(1) `graph`, UNSPECIDIED position argument
(2) `graph_transform`, Default is `None` 
(3) `device`, Default is `None` 
(4) `adj_transform`, Default is `normalize_adj` 
(5) `attr_transform`, Default is `None` 

------------------------------------------------------------------------------------------------------------
|Third, build your model, run `trainer.build()`, the reqiured argument are:                          |
(1) `hids`, Default is `[16]` 
(2) `acts`, Default is `['relu']` 
(3) `dropout`, Default is `0.5` 
(4) `weight_decay`, Default is `0.0005` 
(5) `lr`, Default is `0.01` 
(6) `bias`, Default is `False` 
 
------------------------------------------------------------------------------------------------------------
|Fourth, train your model, run `trainer.fit()`, the reqiured argument are:                           |
(1) `train_data`, UNSPECIDIED position argument
(2) `val_data`, Default is `None` 
 
------------------------------------------------------------------------------------------------------------
|Finally and optionally, evaluate your model, run `trainer.evaluate()`, the reqiured argument are:   |
(1) `test_data`, UNSPECIDIED position argument
 
------------------------------------------------------------------------------------------------------------
  • The default backend module is PyTorch, you can switch to others:
>>> import graphgallery
# Default: PyTorch backend
>>> graphgallery.backend()
PyTorch 1.7.0cu101 Backend
# Switch to TensorFlow backend
>>> graphgallery.set_backend("tf")
# Switch to PyTorch backend
>>> graphgallery.set_backend("th")
# Switch to PyTorch Geometric backend
>>> graphgallery.set_backend("pyg")
# Switch to DGL PyTorch backend
>>> graphgallery.set_backend("dgl")

But your codes don't even need to change, for example:

from graphgallery.gallery.nodeclas import GCN
# this line of code imports GCN written by PyTorch by default
# but if you switch to other backend such as tensorflow, it imports GCN written by TensorFlow as well
# and the following codes for training or testing don't even need to change.

Note, not all models are implemented by four backends (PyTorch, TensorFlow, PyG and DGL),
just run

>>> from graphgallery.gallery.nodeclas import models
>>> models()
# you will get a dict of implanted models here

For more examples, please refer to examples

GraphGallery 0.7.2

20 Jan 16:42
Compare
Choose a tag to compare

GraphGallery 0.6.0

15 Dec 01:35
Compare
Choose a tag to compare
update README

GraphGallery 0.5.0

06 Nov 10:44
Compare
Choose a tag to compare

GraphGallery 0.4.2

22 Oct 08:12
Compare
Choose a tag to compare

New features

  • Strided (dense) Tensor
>>> backend()
TensorFlow 2.1.2 Backend

>>> from graphgallery import transforms as T
>>> arr = [1, 2, 3]
>>> T.astensor(arr)
<tf.Tensor: shape=(3,), dtype=int32, numpy=array([1, 2, 3], dtype=int32)>
  • Sparse Tensor
>>> import scipy.sparse as sp
>>> sp_matrix = sp.eye(3)
>>> T.astensor(sp_matrix)
<tensorflow.python.framework.sparse_tensor.SparseTensor at 0x7f1bbc205dd8>
  • also works for PyTorch, just like
>>> from graphgallery import set_backend
>>> set_backend('torch') # torch, pytorch or th
PyTorch 1.6.0+cu101 Backend

>>> T.astensor(arr)
tensor([1, 2, 3])

>>> T.astensor(sp_matrix)
tensor(indices=tensor([[0, 1, 2],
                       [0, 1, 2]]),
       values=tensor([1., 1., 1.]),
       size=(3, 3), nnz=3, layout=torch.sparse_coo)
  • To Numpy or Scipy sparse matrix
>>> tensor = T.astensor(arr)
>>> T.tensoras(tensor)
array([1, 2, 3])

>>> sp_tensor = T.astensor(sp_matrix)
>>> T.tensoras(sp_tensor)
<3x3 sparse matrix of type '<class 'numpy.float32'>'
    with 3 stored elements in Compressed Sparse Row format>
  • Or even convert one Tensor to another one
>>> tensor = T.astensor(arr, kind="T")
>>> tensor
<tf.Tensor: shape=(3,), dtype=int64, numpy=array([1, 2, 3])>
>>> T.tensor2tensor(tensor)
tensor([1, 2, 3])

>>> sp_tensor = T.astensor(sp_matrix, kind="T") # set kind="T" to convert to tensorflow tensor
>>> sp_tensor
<tensorflow.python.framework.sparse_tensor.SparseTensor at 0x7efb6836a898>
>>> T.tensor2tensor(sp_tensor)
tensor(indices=tensor([[0, 1, 2],
                       [0, 1, 2]]),
       values=tensor([1., 1., 1.]),
       size=(3, 3), nnz=3, layout=torch.sparse_coo)

GraphGallery 0.4.1

07 Oct 07:36
Compare
Choose a tag to compare

New features

  • Strided (dense) Tensor
>>> backend()
TensorFlow 2.1.2 Backend

>>> from graphgallery import transforms as T
>>> arr = [1, 2, 3]
>>> T.astensor(arr)
<tf.Tensor: shape=(3,), dtype=int32, numpy=array([1, 2, 3], dtype=int32)>
  • Sparse Tensor
>>> import scipy.sparse as sp
>>> sp_matrix = sp.eye(3)
>>> T.astensor(sp_matrix)
<tensorflow.python.framework.sparse_tensor.SparseTensor at 0x7f1bbc205dd8>
  • also works for PyTorch, just like
>>> from graphgallery import set_backend
>>> set_backend('torch') # torch, pytorch or th
PyTorch 1.6.0+cu101 Backend

>>> T.astensor(arr)
tensor([1, 2, 3])

>>> T.astensor(sp_matrix)
tensor(indices=tensor([[0, 1, 2],
                       [0, 1, 2]]),
       values=tensor([1., 1., 1.]),
       size=(3, 3), nnz=3, layout=torch.sparse_coo)
  • To Numpy or Scipy sparse matrix
>>> tensor = T.astensor(arr)
>>> T.tensoras(tensor)
array([1, 2, 3])

>>> sp_tensor = T.astensor(sp_matrix)
>>> T.tensoras(sp_tensor)
<3x3 sparse matrix of type '<class 'numpy.float32'>'
    with 3 stored elements in Compressed Sparse Row format>
  • Or even convert one Tensor to another one
>>> tensor = T.astensor(arr, kind="T")
>>> tensor
<tf.Tensor: shape=(3,), dtype=int64, numpy=array([1, 2, 3])>
>>> T.tensor2tensor(tensor)
tensor([1, 2, 3])

>>> sp_tensor = T.astensor(sp_matrix, kind="T") # set kind="T" to convert to tensorflow tensor
>>> sp_tensor
<tensorflow.python.framework.sparse_tensor.SparseTensor at 0x7efb6836a898>
>>> T.tensor2tensor(sp_tensor)
tensor(indices=tensor([[0, 1, 2],
                       [0, 1, 2]]),
       values=tensor([1., 1., 1.]),
       size=(3, 3), nnz=3, layout=torch.sparse_coo)

GraphGallery 0.4.0

03 Oct 06:34
Compare
Choose a tag to compare
update README

GraphGallery 0.3.0

24 Sep 07:23
Compare
Choose a tag to compare

GraphGallery 0.3.0

read the dataset

from graphgallery.data import Planetoid, NPZDataset;
data = Planetoid('cora', root="~/GraphData/datasets/", verbose=False);
graph = data.graph
idx_train, idx_val, idx_test = data.split()

>>> graph
Graph(adj_matrix(2708, 2708), attr_matrix(2708, 2708), labels(2708,))

Add TensorFlow and PyTorch support

Using TensorFlow

graphgallery.set_backend("tensorflow")

from graphgallery.nn.models import GCN
model = GCN(graph, attr_transformer="normalize_attr", device="GPU", seed=123);
model.build()
his = model.train(idx_train, idx_val, verbose=1, epochs=100)
loss, accuracy = model.test(idx_test)
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')

Using PyTorch

graphgallery.set_backend("pytorch")

# the following codes are the same!
from graphgallery.nn.models import GCN
model = GCN(graph, attr_transformer="normalize_attr", device="GPU", seed=123);
model.build()
his = model.train(idx_train, idx_val, verbose=1, epochs=100)
loss, accuracy = model.test(idx_test)
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')

GraphGallery 0.2.0

26 Aug 12:54
Compare
Choose a tag to compare

Changelogs

  • update docstrings
  • rewrite dataset API
    you can load the dataset like
from graphgallery.data import Planetoid, NPZDataset
data = Planetoid('cora',, verbose=True)
# data = NPZDataset('cora', verbose=True)
adj, x, labels = data.graph.unpack()
idx_train, idx_val, idx_test = data.split()

GraphGallery 0.1.12

26 Aug 11:09
Compare
Choose a tag to compare

Changelogs

  • update docstrings
  • rewrite dataset API
    you can load the dataset like
from graphgallery.data import Planetoid, NPZDataset
data = Planetoid('cora',, verbose=True)
# data = NPZDataset('cora', verbose=True)
adj, x, labels = data.graph.unpack()
idx_train, idx_val, idx_test = data.split()