GraphGallery
A gallery of state-of-the-arts graph neural networks. Implemented with TensorFlow 2.x.
This repo aims to achieve 4 goals:
- Similar or higher performance
- Faster training and testing
- Simple and convenient to use, high scalability
- Easy to read source codes
Requirements
- python>=3.6
- tensorflow>=2.1 (2.1 is recommended)
- networkx==2.3
- scipy
- scikit_learn
- numpy
- numba
- gensim
Other packages (not necessary):
- metis==0.2a4 (required for
ClusterGCN) - texttable
Installation
pip install -U graphgallery
Implementation
General models
- ChebyNet from Michaël Defferrard et al, 📝Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering, NIPS'16, :octocat:Codes
- GCN from Thomas N. Kipf et al, 📝Semi-Supervised Classification with Graph Convolutional Networks, ICLR'17, :octocat:Codes
- GraphSAGE from William L. Hamilton et al, 📝Inductive Representation Learning on Large Graphs, NIPS'17, :octocat:Codes
- FastGCN from Jie Chen et al, FastGCN: Fast Learning with Graph Convolutional Networks via Importance Sampling , ICLR'18,:octocat:Codes
- LGCN from Hongyang Gao et al, 📝Large-Scale Learnable Graph Convolutional Networks, KDD'18, :octocat:Codes
- GAT from Petar Veličković et al, 📝Graph Attention Networks, ICLR'18, :octocat:Codes
- SGC from Felix Wu et al, 📝Simplifying Graph Convolutional Networks, ICML'19, :octocat:Codes
- GWNN from Bingbing Xu et al, 📝Graph Wavelet Neural Network, ICLR'19,:octocat:Codes
- GMNN from Meng Qu et al, 📝Graph Markov Neural Networks, ICML'19,:octocat:Codes
- ClusterGCN from Wei-Lin Chiang et al, 📝Cluster-GCN: An Efficient Algorithm for Training Deep and Large Graph Convolutional Networks, KDD'19, :octocat:Codes
- DAGNN from Meng Liu et al, 📝Towards Deeper Graph Neural Networks, KDD'20, :octocat:Codes
Defense models
- RobustGCN from Dingyuan Zhu et al, 📝Robust Graph Convolutional Networks Against Adversarial Attacks, KDD'19, :octocat:Codes
- SBVAT/OBVAT from Zhijie Deng et al, 📝Batch Virtual Adversarial Training for Graph Convolutional Networks, ICML'19, :octocat:Codes
Quick Start
Example of GCN model
from graphgallery.nn.models import GCN
# adj is scipy sparse matrix, x is numpy array matrix
model = GCN(adj, x, labels, device='GPU', norm_x='l1', seed=123)
# build your GCN model with custom hyper-parameters
model.build()
# train your model. here idx_train and idx_val are numpy arrays
his = model.train(idx_train, idx_val, verbose=1, epochs=100)
# test your model
loss, accuracy = model.test(idx_test)
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
On Cora dataset:
loss 1.02, acc 95.00%, val_loss 1.41, val_acc 77.40%: 100%|██████████| 100/100 [00:02<00:00, 37.07it/s]
Test loss 1.4123, Test accuracy 81.20%
Build your model
you can use the following statement to build your model
# one hidden layer with hidden units 32 and activation function RELU
>>> model.build(hiddens=32, activations='relu')
# two hidden layer with hidden units 32, 64 and all activation functions are RELU
>>> model.build(hiddens=[32, 64], activations='relu')
# two hidden layer with hidden units 32, 64 and activation functions RELU and ELU
>>> model.build(hiddens=[32, 64], activations=['relu', 'elu'])
# other parameters like `dropouts` and `l2_norms` (if have) are the SAME.
Train or test your model
More details can be seen in the methods model.train and model.test
Hyper-parameters
you can simply use model.show() to show all your Hyper-parameters.
Otherwise you can also use model.show('model') or model.show('train') to show your model parameters and training parameters.
NOTE: you should install texttable first.
Visualization
NOTE: you must install SciencePlots package for a better preview.
- Accuracy
import matplotlib.pyplot as plt
with plt.style.context(['science', 'no-latex']):
plt.plot(his.history['acc'])
plt.plot(his.history['val_acc'])
plt.legend(['Train Accuracy', 'Val Accuracy'])
plt.ylabel('Accuracy')
plt.xlabel('Epochs')
plt.autoscale(tight=True)
plt.show()
- Loss
import matplotlib.pyplot as plt
with plt.style.context(['science', 'no-latex']):
plt.plot(his.history['loss'])
plt.plot(his.history['val_loss'])
plt.legend(['Train Loss', 'Val Loss'])
plt.ylabel('Loss')
plt.xlabel('Epochs')
plt.autoscale(tight=True)
plt.show()
Acknowledgement
This project is motivated by Pytorch Geometric, Tensorflow Geometric and Stellargraph, and the original implementations from the authors, thanks for their excellent works!
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file graphgallery-0.1.10.tar.gz.
File metadata
- Download URL: graphgallery-0.1.10.tar.gz
- Upload date:
- Size: 58.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f867b1830b1e9628e7c7929ab718a07c4f7981f916139f9f31a9ce553ade246
|
|
| MD5 |
a83ca2a7f55396f28f458587c7e5341b
|
|
| BLAKE2b-256 |
7b3ffa3feaea1f91f4eaa9a6e625e029f933404749e3c7d23476e827e4cfbeff
|
File details
Details for the file graphgallery-0.1.10-py3-none-any.whl.
File metadata
- Download URL: graphgallery-0.1.10-py3-none-any.whl
- Upload date:
- Size: 114.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1756526367fd47f9012341ad6d4bc4585762b4edc78fe3763a58fcf2adeec10e
|
|
| MD5 |
8cd25f6d477a9eb16b75265cfed9d618
|
|
| BLAKE2b-256 |
3140a36561ac75eb337ea9edeaf2cd3e65cc6771b4dcef7c6f1739e58bd86f44
|