Skip to main content

GraphGallery

logo


Python 3.6 TensorFlow >=2.1 PyPI Version GitHub license

GraphGallery is a gallery of state-of-the-arts graph neural networks for 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

Installation

pip install -U graphgallery

Implementations

In detail, the following methods are currently implemented:

Semi-supervised models

General

Defense models

Unsupervised models

Quick Start

Datasets

from graphgallery.data import Planetoid
# set `verbose=False` to avoid these printed tables
data = Planetoid('cora', verbose=False)
adj, x, labels = data.graph.unpack()
idx_train, idx_val, idx_test = data.split()
# adj:  adjacency matrix: 2D Scipy sparse matrix
# x:  feature matrix: 2D Numpy array
# labels:  class labels: 1D Numpy array
# idx_train:  training indices: 1D Numpy array
# idx_val:  validation indices: 1D Numpy array
# idx_test:  testing indices: 1D Numpy array

currently the supported datasets are:

>>> data.supported_datasets
('citeseer', 'cora', 'pubmed')

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 default 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.0161 Acc = 0.9500 Val_Loss = 1.4101 Val_Acc = 0.7740 >: 100%|██████████| 100/100 [00:01<00:00, 118.02it/s]
Test loss 1.4123, Test accuracy 81.20%

Customization

  • 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 your model
# train with validation
>>> his = model.train(idx_train, idx_val, verbose=1, epochs=100)
# train without validation
# his = model.train(idx_train, verbose=1, epochs=100)

here his is tensorflow Histoory like instance (or itself).

  • Test you model
loss, accuracy = model.test(idx_test)
print(f'Test loss {loss:.5}, Test accuracy {accuracy:.2%}')
  • Display 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()    

visualization

  • 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()    

visualization

More Examples

Please refer to the examples directory.

TODO Lists

  • Add Docstrings and Documentation
  • Add PyTorch models support
  • Support for graph Classification and link prediction tasks
  • Support for Heterogeneous graphs

Acknowledgement

This project is motivated by Pytorch Geometric, Tensorflow Geometric and Stellargraph, and the original implementations of 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

graphgallery-0.2.0.tar.gz (67.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphgallery-0.2.0-py3-none-any.whl (132.3 kB view details)

Uploaded Python 3

File details

Details for the file graphgallery-0.2.0.tar.gz.

File metadata

  • Download URL: graphgallery-0.2.0.tar.gz
  • Upload date:
  • Size: 67.7 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

Hashes for graphgallery-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e806aaae52ac667e0426b91e5853f9dac463882c7ce8ff85e5cf38ccc75ebe44
MD5 2e16bf4b4181943aa5dc12e7139a5f79
BLAKE2b-256 80243e11a9382a485931e819fe18c1e9293f4abf45f0b5fd34cf3941d5e25419

See more details on using hashes here.

File details

Details for the file graphgallery-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: graphgallery-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 132.3 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

Hashes for graphgallery-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c2dfcd36c417aeceda00af02de90cdc29341c275fb43922c66d6028720266c7
MD5 96c369e8bce88bcd0a6bea9a79a813d6
BLAKE2b-256 21e02f635c0404c74ab62de35f8acd47df843e61a5d9406de8ea7ab5ef9578a4

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.0

2 files

0.7.2

2 files

0.6.0

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page