diff --git a/examples/mxnet/gcn/README.md b/examples/mxnet/gcn/README.md index f6d2878199c7..c389975d5376 100644 --- a/examples/mxnet/gcn/README.md +++ b/examples/mxnet/gcn/README.md @@ -21,6 +21,7 @@ The folder contains three implementations of GCN: - `gcn_mp.py` uses user-defined message and reduce functions. - `gcn_spmv.py` improves from `gcn_mp.py` by using DGL's builtin functions so SPMV optimization could be applied. +Modify `train.py` to switch between different implementations. The provided implementation in `gcn_concat.py` is a bit different from the original paper for better performance, credit to @yifeim and @ZiyueHuang. @@ -29,7 +30,7 @@ Results ------- Run with following (available dataset: "cora", "citeseer", "pubmed") ```bash -DGLBACKEND=mxnet python3 train.py --dataset cora --gpu 0 +DGLBACKEND=mxnet python3 train.py --dataset cora --gpu 0 --self-loop ``` * cora: ~0.810 (paper: 0.815) diff --git a/examples/mxnet/gcn/train.py b/examples/mxnet/gcn/train.py index 4eb120d82dce..dd574d9150a1 100644 --- a/examples/mxnet/gcn/train.py +++ b/examples/mxnet/gcn/train.py @@ -53,7 +53,8 @@ def main(args): # create GCN model g = DGLGraph(data.graph) - g.add_edges(g.nodes(), g.nodes()) + if args.self_loop: + g.add_edges(g.nodes(), g.nodes()) # normalization degs = g.in_degrees().astype('float32') norm = mx.nd.power(degs, -0.5) @@ -120,6 +121,9 @@ def main(args): help="number of hidden gcn layers") parser.add_argument("--weight-decay", type=float, default=5e-4, help="Weight for L2 loss") + parser.add_argument("--self-loop", action='store_true', + help="graph self-loop (default=False)") + parser.set_defaults(self_loop=False) args = parser.parse_args() print(args) diff --git a/examples/pytorch/gcn/README.md b/examples/pytorch/gcn/README.md index d2f7af8459bb..ea621c066301 100644 --- a/examples/pytorch/gcn/README.md +++ b/examples/pytorch/gcn/README.md @@ -28,7 +28,7 @@ Results Run with following (available dataset: "cora", "citeseer", "pubmed") ```bash -python train.py --dataset cora --gpu 0 +python train.py --dataset cora --gpu 0 --self-loop ``` * cora: ~0.810 (0.79-0.83) (paper: 0.815) diff --git a/examples/pytorch/gcn/train.py b/examples/pytorch/gcn/train.py index c4ba300d8fba..153679db968b 100644 --- a/examples/pytorch/gcn/train.py +++ b/examples/pytorch/gcn/train.py @@ -57,7 +57,8 @@ def main(args): g = DGLGraph(data.graph) n_edges = g.number_of_edges() # add self loop - g.add_edges(g.nodes(), g.nodes()) + if args.self_loop: + g.add_edges(g.nodes(), g.nodes()) # normalization degs = g.in_degrees().float() norm = torch.pow(degs, -0.5) @@ -128,6 +129,9 @@ def main(args): help="number of hidden gcn layers") parser.add_argument("--weight-decay", type=float, default=5e-4, help="Weight for L2 loss") + parser.add_argument("--self-loop", action='store_true', + help="graph self-loop (default=False)") + parser.set_defaults(self_loop=False) args = parser.parse_args() print(args)