Skip to main content

GraphGallery

logo


Python tensorflow PyPI Version License: MIT

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

Defense models

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

  • Accuracy
import matplotlib.pyplot as plt
plt.plot(his.history['acc'])
plt.plot(his.history['val_acc'])
plt.legend(['Accuracy', 'Val Accuracy'])
plt.xlabel('Epochs')
plt.show()

visualization

  • Loss
import matplotlib.pyplot as plt
plt.plot(his.history['loss'])
plt.plot(his.history['val_loss'])
plt.legend(['Loss', 'Val Loss'])
plt.xlabel('Epochs')
plt.show()

visualization

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

graphgallery-0.1.9.tar.gz (58.1 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.1.9-py3-none-any.whl (114.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: graphgallery-0.1.9.tar.gz
  • Upload date:
  • Size: 58.1 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.1.9.tar.gz
Algorithm Hash digest
SHA256 6995100849c70bde646ba445158c38df9afd221b7252ee58b9a0aca764f10e6e
MD5 5ea5a0fbb4266e109bb85377a60508ac
BLAKE2b-256 6c42d4963d5d4ed6111f4231112500593ba420c9b2b0079db51124ff134c8092

See more details on using hashes here.

File details

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

File metadata

  • Download URL: graphgallery-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 114.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.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 fe3dcf2abca13007e2f87ab2849c901c0f6d26768228a2e2f2f6458f46b398c6
MD5 74443dc7765a95f521a5117cb3b3c057
BLAKE2b-256 317aee174e963fc4ffa2ed7235f617731ccb29d341670b0b800585c0843636ff

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

0.2.0

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

This release

0.1.9 This release

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