/gcn-pytorch

Implementation of the Graph Convolutional Networks in Pytorch

Primary LanguageJupyter NotebookMIT LicenseMIT

Graph Convolutional Networks in PyTorch

Re-implementation of the work described in Semi-Supervised Classification with Graph Convolutional Networks.

The implementation contains two different propagation models, the one from original GCN as described in the above paper and the Chebyshev filter based one from Convolutional Neural Networks on Graphs with Fast Localized Spectral Filtering.

Installation & Usage

To quickly check: Open In Colab

git clone https://github.com/andrejmiscic/gcn-pytorch.git
cd gcn-pytorch

The requirements are dependent on whether you want to use a GPU or not:

pip install -r requirements_gpu.txt

or

pip install -r requirements_cpu.txt

A simple evaluation of the model on Cora dataset:

import torch

from gcn.model import TwoLayerGCN
from gcn.trainer import Trainer, RunConfig
from gcn.utils import Dataset, load_data

features, labels, train_labels, val_labels, test_labels, adjacency_matrix, \
    laplacian_matrix, num_classes = load_data(Dataset.Cora)
    
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# training parameters
run_config = RunConfig(learning_rate=0.1, num_epochs=200, weight_decay=5e-4, output_dir="gcn/")

# constructing a GCN model
model = TwoLayerGCN(
        input_size=features.size(1),
        hidden_size=16,
        output_size=num_classes,
        dropout=0.5
    )

# training
trainer = Trainer(model)
trainer.train(features, train_labels, val_labels, adjacency_matrix, device, run_config, log=False)

# evaluating
ce_loss, accuracy = trainer.evaluate(features, test_labels, adjacency_matrix, device)

You can check out notebooks/gcn_testing.ipynb that contains all the code for reproducing the results.

To run the notebook on Google Colab follow the link Open In Colab

Results

Test set accuracy for this implementation in comparison to the original paper. All results are based on public splits of analyzed datasets. In our results we report standard deviation of accuracy based on 100 repetitions.

Dataset: Cora CiteSeer PubMed
Original paper
GCN 81.5 70.3 79.0
Cheb (K=2) 81.2 69.6 73.8
Cheb (K=3) 79.5 69.8 74.4
This implementation
GCN 82.2 ± 0.5 71.0 ± 0.6 79.1 ± 0.5
Cheb (K=2) 81.3 ± 0.7 71.1 ± 0.9 77.9 ± 0.9
Cheb (K=3) 82.5 ± 0.7 71.2 ± 0.8 79.0 ± 0.7

Results of experiments with model depth and residual connections are shown below. Same as in the original paper the whole dataset is used and the mean accuracy of 5-fold cross validation is plotted.

References & Citations

@article{kipf2016semi,
  title={Semi-supervised classification with graph convolutional networks},
  author={Kipf, Thomas N and Welling, Max},
  journal={arXiv preprint arXiv:1609.02907},
  year={2016}
}
@inproceedings{defferrard2016convolutional,
  title={Convolutional neural networks on graphs with fast localized spectral filtering},
  author={Defferrard, Micha{\"e}l and Bresson, Xavier and Vandergheynst, Pierre},
  booktitle={Advances in neural information processing systems},
  pages={3844--3852},
  year={2016}
}