Skip to content

GraphGallery 1.0.0

Latest
Compare
Choose a tag to compare
@EdisonLeeeee EdisonLeeeee released this 21 Sep 13:57
· 91 commits to master since this release

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