Skip to content

Commit

Permalink
fix gcn. (dmlc#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
zheng-da authored Apr 5, 2019
1 parent 8058f1c commit 4ea42e3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/mxnet/gcn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion examples/mxnet/gcn/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/pytorch/gcn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion examples/pytorch/gcn/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 4ea42e3

Please sign in to comment.