• Stars
    star
    458
  • Rank 95,591 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GraphGallery is a gallery for benchmarking Graph Neural Networks, From InplusLab.

banner

PyTorch is all you need!

Python pytorch pypi license

GraphGallery

GraphGallery is a gallery for benchmarking Graph Neural Networks (GNNs) based on pure PyTorch backend. Alteratively, Pytorch Geometric (PyG) and Deep Graph Library (DGL) backend are also available in GraphGallery to facilitate your implementations.

💨 NEWS

  • November 20, 2021: We now no longer support TensorFlow backend.
  • November 20, 2021: The module graphgallery.attack is deprecated, users may refer to GraphWar for more information.

🚀 Installation

Please make sure you have installed PyTorch. Also, Pytorch Geometric (PyG) and Deep Graph Library (DGL) are alternative choices.

Install from source:

# Recommended
git clone https://github.com/EdisonLeeeee/GraphGallery.git && cd GraphGallery
pip install -e . --verbose

where -e means "editable" mode so you don't have to reinstall every time you make changes.

NOTE: GraphGallery is a frequently updated package and DO NOT install GraphGallery with pip, we're currently working on releasing a binary distribution on PyPI, stay tuned!

🤖 Implementations

In detail, the following methods are currently implemented:

Node Classification

Method Author Paper PyTorch PyG DGL
ChebyNet Michaël Defferrard et al. Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering (NeurIPS'16) ✔️
GCN Thomas N. Kipf et al. Semi-Supervised Classification with Graph Convolutional Networks (ICLR'17) ✔️ ✔️ ✔️
GraphSAGE William L. Hamilton et al. Inductive Representation Learning on Large Graphs (NeurIPS'17) ✔️ ✔️
FastGCN Jie Chen et al. FastGCN: Fast Learning with Graph Convolutional Networks via Importance Sampling (ICLR'18) ✔️
GAT Petar Veličković et al. Graph Attention Networks (ICLR'18) ✔️ ✔️ ✔️
SGC Felix Wu et al. Simplifying Graph Convolutional Networks (ICLR'19) ✔️ ✔️ ✔️
GWNN Bingbing Xu et al. Graph Wavelet Neural Network (ICLR'19) ✔️
ClusterGCN Wei-Lin Chiang et al. Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks (KDD'19) ✔️
DAGNN Meng Liu et al. Towards Deeper Graph Neural Networks (KDD'20) ✔️ ✔️
GDC Johannes Klicpera et al. Diffusion Improves Graph Learning (NeurIPS'19) ✔️
TAGCN Jian Du et al. Topology Adaptive Graph Convolutional Networks (arxiv'17) ✔️
APPNP, PPNP Johannes Klicpera et al. Predict then Propagate: Graph Neural Networks meet Personalized PageRank (ICLR'19) ✔️ ✔️
PDN Benedek Rozemberczki et al. Pathfinder Discovery Networks for Neural Message Passing (ICLR'21) ✔️
SSGC Zhu et al. Simple Spectral Graph Convolution (ICLR'21) ✔️
AGNN Kiran K. Thekumparampil al. Attention-based Graph Neural Network for semi-supervised learning (ICLR'18 openreview) ✔️
ARMA Bianchi et al. Graph Neural Networks with convolutional ARMA filters (Arxiv'19)
GraphMLP Yang Hu et al. Graph-MLP: Node Classification without Message Passing in Graph (Arxiv'21) ✔️
LGC, EGC, hLGC Luca Pasa et al. Simple Graph Convolutional Networks (Arxiv'21) ✔️
GRAND Wenzheng Feng et al. Graph Random Neural Network for Semi-Supervised Learning on Graphs (NeurIPS'20) ✔️
AlaGCN, AlaGAT Yiqing Xie et al. When Do GNNs Work: Understanding and Improving Neighborhood Aggregation (IJCAI'20) ✔️
JKNet Keyulu Xu et al. Representation Learning on Graphs with Jumping Knowledge Networks (ICML'18) ✔️
MixHop Sami Abu-El-Haija et al. MixHop: Higher-Order Graph Convolutional Architecturesvia Sparsified Neighborhood Mixing (ICML'19) ✔️
DropEdge Yu Rong et al. DropEdge: Towards Deep Graph Convolutional Networks on Node Classification (ICML'20) ✔️
Node2Grids Dalong Yang et al. Node2Grids: A Cost-Efficient Uncoupled Training Framework for Large-Scale Graph Learning (CIKM'21) ✔️
RobustGCN Dingyuan Zhu et al. Robust Graph Convolutional Networks Against Adversarial Attacks (KDD'19) ✔️ ✔️
SBVAT, OBVAT Zhijie Deng et al. Batch Virtual Adversarial Training for Graph Convolutional Networks (ICML'19) ✔️
SimPGCN Wei Jin et al. Node Similarity Preserving Graph Convolutional Networks (WSDM'21) ✔️
GraphVAT Fuli Feng et al. Graph Adversarial Training: Dynamically Regularizing Based on Graph Structure (TKDE'19) ✔️
LATGCN Hongwei Jin et al. Latent Adversarial Training of Graph Convolution Networks (ICML@LRGSD'19) ✔️
DGAT Weibo Hu et al. Robust graph convolutional networks with directional graph adversarial training (Applied Intelligence'19) ✔️
MedianGCN, TrimmedGCN Liang Chen et al. Understanding Structural Vulnerability in Graph Convolutional Networks ✔️ ✔️ ✔️

Graph Purification

The graph purification methods are universal for all models, just specify:

graph_transform="purification_method"

so, here we only give the examples of GCN with purification methods, other models should work.

Method Author Paper
GCN-Jaccard Huijun Wu et al. Adversarial Examples on Graph Data: Deep Insights into Attack and Defense (IJCAI'19)
GCN-SVD Negin Entezari et al. All You Need Is Low (Rank): Defending Against Adversarial Attacks on Graphs (WSDM'20)

LinkPrediction

Method Author Paper PyTorch PyG DGL
GAE, VGAE Thomas N. Kipf et al. Variational Graph Auto-Encoders (NeuIPS'16) ✔️ ✔️

Node Embedding

The following methods are framework-agnostic.

Method Author Paper
Deepwalk Bryan Perozzi et al. DeepWalk: Online Learning of Social Representations (KDD'14)
Node2vec Aditya Grover and Jure Leskovec node2vec: Scalable Feature Learning for Networks (KDD'16)
Node2vec+ Renming Liu et al. Accurately Modeling Biased Random Walks on Weighted Graphs Using Node2vec+
BANE Hong Yang et al. Binarized attributed network embedding (ICDM'18)

Quick Start

Datasets

  • Planetoid: a collection of widely used benchmark datasets in graph learning tasks, including 'cora', 'citeseerr', 'pubmed' and 'nell' datasets.
  • NPZDataset: a collection of graph datasets stored with numpy .npz format.

you can simply run dataset.available_datasets() to see the available datasets, e.g.,:

from graphgallery.datasets import Planetoid
print(Planetoid.available_datasets())

more details please refer to GraphData.

Example of GCN (Node Classification Task)

It takes just a few lines of code.

import torch
import graphgallery
from graphgallery.datasets import Planetoid
from graphgallery.gallery import callbacks

data = Planetoid('cora', root="~/GraphData/datasets/", verbose=True)
graph = data.graph
splits = data.split_nodes()
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')

graphgallery.set_backend("torch")
from graphgallery.gallery.nodeclas import GCN

trainer = GCN(device=device, seed=123).setup_graph(graph, feat_transform="normalize_feat").build()
cb = callbacks.ModelCheckpoint('model.pth', monitor='val_accuracy')
trainer.fit(splits.train_nodes, splits.val_nodes, verbose=1, callbacks=[cb])
results = trainer.evaluate(splits.test_nodes)
print(f'Test loss {results.loss:.5}, Test accuracy {results.accuracy:.2%}')

Example of GAE (Link Prediction Task)

import torch
import graphgallery
from graphgallery.gallery import callbacks
from graphgallery.datasets import Planetoid

data = Planetoid('cora', root="~/GraphData/datasets/", verbose=True)
graph = data.graph
splits = data.split_edges(random_state=15)
device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')

graphgallery.set_backend("torch")

from graphgallery.gallery.linkpred import GAE
trainer = GAE(device=device, seed=123).setup_graph(graph).build()
cb = callbacks.ModelCheckpoint('model.pth', monitor='val_ap')
trainer.fit(splits.train_pos_edge_index,
            val_data=(splits.val_pos_edge_index, splits.val_neg_edge_index), 
            verbose=1, callbacks=[cb])
results = trainer.evaluate((splits.test_pos_edge_index, splits.test_neg_edge_index))
print(results)

If you have any troubles, you can simply run trainer.help() for more information.

Other Backends

>>> import graphgallery
# Default: PyTorch backend
>>> graphgallery.backend()
PyTorch 1.9.0+cu111 Backend
# Switch to PyTorch Geometric backend
>>> graphgallery.set_backend("pyg")
# Switch to DGL PyTorch backend
>>> graphgallery.set_backend("dgl")
# Switch to PyTorch backend
>>> graphgallery.set_backend("th") # "torch", "pytorch"

But your codes don't even need to change.

How to add your datasets

This is motivated by gnn-benchmark

from graphgallery.data import Graph

# Load the adjacency matrix A, attribute (feature) matrix X and labels vector y
# A - scipy.sparse.csr_matrix of shape [num_nodes, num_nodes]
# X - scipy.sparse.csr_matrix or numpy.ndarray of shape [num_nodes, num_feats]
# y - numpy.ndarray of shape [num_nodes]

mydataset = Graph(adj_matrix=A, attr_matrix=X, label=y)
# save dataset
mydataset.to_npz('path/to/mydataset.npz')
# load dataset
mydataset = Graph.from_npz('path/to/mydataset.npz')

⭐ Road Map

  • Add PyTorch trainers support
  • Add other frameworks (PyG and DGL) support
  • set tensorflow as optional dependency when using graphgallery
  • Add more GNN trainers
  • Support for more tasks, e.g., graph Classification and link prediction
  • Support for more types of graphs, e.g., Heterogeneous graph
  • Add Docstrings and Documentation (Building)
  • Comprehensive tutorials

❓ FAQ

Please fell free to contact me if you have any troubles.

😘 Acknowledgement

This project is motivated by Pytorch Geometric, Stellargraph and DGL, etc., and the original implementations of the authors, thanks for their excellent works!

Cite

Please cite our paper (and the respective papers of the methods used) if you use this code in your own work:

@inproceedings{li2021graphgallery,
author = {Jintang Li and Kun Xu and Liang Chen and Zibin Zheng and Xiao Liu},
booktitle = {2021 IEEE/ACM 43rd International Conference on Software Engineering: Companion Proceedings (ICSE-Companion)},
title = {GraphGallery: A Platform for Fast Benchmarking and Easy Development of Graph Neural Networks Based Intelligent Software},
year = {2021},
pages = {13-16},
publisher = {IEEE Computer Society},
address = {Los Alamitos, CA, USA},
}

More Repositories

1

Awesome-Masked-Autoencoders

A collection of literature after or concurrent with Masked Autoencoder (MAE) (Kaiming He el al.).
761
star
2

Graph-Adversarial-Learning

A curated collection of adversarial attack and defense on graph data.
Python
546
star
3

Awesome-Learning-Resource

A curated list of all kinds of learning resources, blogs, books, videos and so on.
291
star
4

RS-Adversarial-Learning

A curated collection of adversarial attack and defense on recommender systems.
129
star
5

Awesome-Fair-Graph-Learning

Paper List for Fair Graph Learning (FairGL).
123
star
6

ICLR2023-OpenReviewData

ICLR 2023 Paper submission analysis from https://openreview.net/group?id=ICLR.cc/2023/Conference
Jupyter Notebook
100
star
7

ICLR2022-OpenReviewData

ICLR 2022 Paper submission trend analysis from https://openreview.net/group?id=ICLR.cc/2022/Conference
Jupyter Notebook
84
star
8

GreatX

A graph reliability toolbox based on PyTorch and PyTorch Geometric (PyG).
Python
83
star
9

MaskGAE

[KDD 2023] What’s Behind the Mask: Understanding Masked Graph Modeling for Graph Autoencoders
Python
73
star
10

SpikeNet

[AAAI 2023] Scaling Up Dynamic Graph Representation Learning via Spiking Neural Networks
Python
55
star
11

ICDM2022_competition_3rd_place_solution

3rd place solution of ICDM 2022 Risk Commodities Detection on Large-Scale E-Commence Graphs
Python
36
star
12

GraphData

A collection of graph data used for semi-supervised node classification.
34
star
13

DCIC-2023-Solution

DCIC2023 Fraud Risk Identification Competition Solution.
Jupyter Notebook
23
star
14

SpikeGCL

[ICLR 2024] Official implementation of Spiking Graph Contrastive Learning (0️⃣1️⃣ SpikeGCL)
Python
22
star
15

arxiv-daily

arxiv-daily
Python
12
star
16

Awesome-SAR-Detection

A curated list of SAR detection datasets.
9
star
17

GUARD

[CIKM 2023] GUARD: Graph Universal Adversarial Defense
Python
9
star
18

SGAttack

Official Repository for "Adversarial Attack on Large Scale Graph." [TKDE 2021]
Jupyter Notebook
9
star
19

Mooon

Graph Data Augmentation Library for PyTorch Geometric
Python
6
star
20

STEP

Python
6
star
21

MAGI

[KDD 2024] Revisiting Modularity Maximization for Graph Clustering: A Contrastive Learning Perspective
Python
6
star
22

SAT

Python
5
star
23

SpikingNeuralNetworks

Spiking Neural Networks (脉冲神经网络调研)
5
star
24

MedianGCN

Official PyTorch implementation of MedianGCN and TrimmedGCN in Understanding Structural Vulnerability in Graph Convolutional Networks (IJCAI 2021).
Jupyter Notebook
5
star
25

CIKM22_FL_Competition

4th place (4/1746) solution of CIKM 2022 AnalytiCup Competition.
Python
4
star
26

GraphAdv

TensorFlow 2 implementation of state-of-the-arts graph adversarial attack and defense models (methods).
Python
4
star
27

GraphSSM

[arXiv 2024] State Space Models on Temporal Graphs: A First-Principles Study
4
star
28

SVD_HMM

Python implement of SVD+HMM for face recognition.
Jupyter Notebook
3
star
29

EdisonLeeeee.github.io

Github pages
Python
3
star
30

BlockGCL

PyTorch implementation of Blockwise Graph Contrastive Learning (BlockGCL)
Python
3
star
31

SAR-Ship-Detection-Detectron2

SAR Ship detection with Detection2
Jupyter Notebook
3
star
32

CenterSAR

CenterNet for SAR ship detection based on Detectron2
Jupyter Notebook
2
star
33

SGC_tf2.0

Python implement of SGC with Tensorflow 2.0.
Jupyter Notebook
2
star
34

Hetero2Net

Python
2
star
35

EdisonLeeeee

1
star
36

tensorflow-jupyterlab-docker

Tensorflow 2.1 GPU with Python 3.6 and jupyterlab
Dockerfile
1
star
37

Introduction_to_graph_adversarial_learning

An introduction to graph adversarial learning
1
star
38

TemporalDatasets

1
star
39

DropPath

Implementation of DropPath: A Structured Dropout for Graph Neural Networks in PyTorch.
Python
1
star
40

glcore

graph learing toolbox
Cuda
1
star
41

lrGAE

Python
1
star