Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
704bcaf6
Unverified
Commit
704bcaf6
authored
Feb 19, 2023
by
Hongzhi (Steve), Chen
Committed by
GitHub
Feb 19, 2023
Browse files
examples (#5323)
Co-authored-by:
Ubuntu
<
ubuntu@ip-172-31-28-63.ap-northeast-1.compute.internal
>
parent
6bc82161
Changes
332
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
56 additions
and
53 deletions
+56
-53
examples/mxnet/scenegraph/utils/metric.py
examples/mxnet/scenegraph/utils/metric.py
+4
-4
examples/mxnet/scenegraph/utils/sampling.py
examples/mxnet/scenegraph/utils/sampling.py
+1
-2
examples/mxnet/scenegraph/validate_reldn.py
examples/mxnet/scenegraph/validate_reldn.py
+1
-1
examples/mxnet/sgc/sgc.py
examples/mxnet/sgc/sgc.py
+9
-5
examples/mxnet/tagcn/tagcn.py
examples/mxnet/tagcn/tagcn.py
+2
-3
examples/mxnet/tagcn/train.py
examples/mxnet/tagcn/train.py
+8
-4
examples/mxnet/tree_lstm/train.py
examples/mxnet/tree_lstm/train.py
+2
-3
examples/mxnet/tree_lstm/tree_lstm.py
examples/mxnet/tree_lstm/tree_lstm.py
+2
-2
examples/pytorch/GATNE-T/src/utils.py
examples/pytorch/GATNE-T/src/utils.py
+1
-2
examples/pytorch/GNN-FiLM/data_loader.py
examples/pytorch/GNN-FiLM/data_loader.py
+2
-2
examples/pytorch/GNN-FiLM/main.py
examples/pytorch/GNN-FiLM/main.py
+3
-3
examples/pytorch/NGCF/NGCF/model.py
examples/pytorch/NGCF/NGCF/model.py
+1
-3
examples/pytorch/NGCF/NGCF/utility/load_data.py
examples/pytorch/NGCF/NGCF/utility/load_data.py
+2
-2
examples/pytorch/P-GNN/main.py
examples/pytorch/P-GNN/main.py
+2
-2
examples/pytorch/P-GNN/model.py
examples/pytorch/P-GNN/model.py
+1
-2
examples/pytorch/P-GNN/utils.py
examples/pytorch/P-GNN/utils.py
+1
-1
examples/pytorch/TAHIN/TAHIN.py
examples/pytorch/TAHIN/TAHIN.py
+2
-3
examples/pytorch/TAHIN/data_loader.py
examples/pytorch/TAHIN/data_loader.py
+2
-3
examples/pytorch/TAHIN/main.py
examples/pytorch/TAHIN/main.py
+2
-2
examples/pytorch/appnp/train.py
examples/pytorch/appnp/train.py
+8
-4
No files found.
examples/mxnet/scenegraph/utils/metric.py
View file @
704bcaf6
...
@@ -2,17 +2,17 @@ import logging
...
@@ -2,17 +2,17 @@ import logging
import
time
import
time
from
operator
import
attrgetter
,
itemgetter
from
operator
import
attrgetter
,
itemgetter
import
dgl
import
mxnet
as
mx
import
mxnet
as
mx
import
numpy
as
np
import
numpy
as
np
from
dgl.nn.mxnet
import
GraphConv
from
dgl.utils
import
toindex
from
gluoncv.data.batchify
import
Pad
from
gluoncv.data.batchify
import
Pad
from
gluoncv.model_zoo
import
get_model
from
gluoncv.model_zoo
import
get_model
from
mxnet
import
gluon
,
nd
from
mxnet
import
gluon
,
nd
from
mxnet.gluon
import
nn
from
mxnet.gluon
import
nn
import
dgl
from
dgl.nn.mxnet
import
GraphConv
from
dgl.utils
import
toindex
def
iou
(
boxA
,
boxB
):
def
iou
(
boxA
,
boxB
):
# determine the (x, y)-coordinates of the intersection rectangle
# determine the (x, y)-coordinates of the intersection rectangle
...
...
examples/mxnet/scenegraph/utils/sampling.py
View file @
704bcaf6
import
dgl
import
mxnet
as
mx
import
mxnet
as
mx
import
numpy
as
np
import
numpy
as
np
import
dgl
from
dgl.utils
import
toindex
from
dgl.utils
import
toindex
...
...
examples/mxnet/scenegraph/validate_reldn.py
View file @
704bcaf6
...
@@ -6,7 +6,7 @@ import mxnet as mx
...
@@ -6,7 +6,7 @@ import mxnet as mx
import
numpy
as
np
import
numpy
as
np
from
data
import
*
from
data
import
*
from
gluoncv.data.batchify
import
Pad
from
gluoncv.data.batchify
import
Pad
from
model
import
RelDN
,
faster_rcnn_resnet101_v1d_custom
from
model
import
faster_rcnn_resnet101_v1d_custom
,
RelDN
from
mxnet
import
gluon
,
nd
from
mxnet
import
gluon
,
nd
from
utils
import
*
from
utils
import
*
...
...
examples/mxnet/sgc/sgc.py
View file @
704bcaf6
...
@@ -9,16 +9,20 @@ import argparse
...
@@ -9,16 +9,20 @@ import argparse
import
math
import
math
import
time
import
time
import
dgl
import
mxnet
as
mx
import
mxnet
as
mx
import
numpy
as
np
import
numpy
as
np
from
dgl.data
import
(
CiteseerGraphDataset
,
CoraGraphDataset
,
PubmedGraphDataset
,
register_data_args
,
)
from
dgl.nn.mxnet.conv
import
SGConv
from
mxnet
import
gluon
,
nd
from
mxnet
import
gluon
,
nd
from
mxnet.gluon
import
nn
from
mxnet.gluon
import
nn
import
dgl
from
dgl.data
import
(
CiteseerGraphDataset
,
CoraGraphDataset
,
PubmedGraphDataset
,
register_data_args
)
from
dgl.nn.mxnet.conv
import
SGConv
def
evaluate
(
model
,
g
,
features
,
labels
,
mask
):
def
evaluate
(
model
,
g
,
features
,
labels
,
mask
):
pred
=
model
(
g
,
features
).
argmax
(
axis
=
1
)
pred
=
model
(
g
,
features
).
argmax
(
axis
=
1
)
...
...
examples/mxnet/tagcn/tagcn.py
View file @
704bcaf6
...
@@ -4,11 +4,10 @@ References:
...
@@ -4,11 +4,10 @@ References:
- Topology Adaptive Graph Convolutional Networks
- Topology Adaptive Graph Convolutional Networks
- Paper: https://arxiv.org/abs/1710.10370
- Paper: https://arxiv.org/abs/1710.10370
"""
"""
import
mxnet
as
mx
from
mxnet
import
gluon
import
dgl
import
dgl
import
mxnet
as
mx
from
dgl.nn.mxnet
import
TAGConv
from
dgl.nn.mxnet
import
TAGConv
from
mxnet
import
gluon
class
TAGCN
(
gluon
.
Block
):
class
TAGCN
(
gluon
.
Block
):
...
...
examples/mxnet/tagcn/train.py
View file @
704bcaf6
import
argparse
import
argparse
import
time
import
time
import
dgl
import
mxnet
as
mx
import
mxnet
as
mx
import
networkx
as
nx
import
networkx
as
nx
import
numpy
as
np
import
numpy
as
np
from
dgl.data
import
(
CiteseerGraphDataset
,
CoraGraphDataset
,
PubmedGraphDataset
,
register_data_args
,
)
from
mxnet
import
gluon
from
mxnet
import
gluon
from
tagcn
import
TAGCN
from
tagcn
import
TAGCN
import
dgl
from
dgl.data
import
(
CiteseerGraphDataset
,
CoraGraphDataset
,
PubmedGraphDataset
,
register_data_args
)
def
evaluate
(
model
,
features
,
labels
,
mask
):
def
evaluate
(
model
,
features
,
labels
,
mask
):
pred
=
model
(
features
).
argmax
(
axis
=
1
)
pred
=
model
(
features
).
argmax
(
axis
=
1
)
...
...
examples/mxnet/tree_lstm/train.py
View file @
704bcaf6
...
@@ -8,14 +8,13 @@ import zipfile
...
@@ -8,14 +8,13 @@ import zipfile
os
.
environ
[
"DGLBACKEND"
]
=
"mxnet"
os
.
environ
[
"DGLBACKEND"
]
=
"mxnet"
os
.
environ
[
"MXNET_GPU_MEM_POOL_TYPE"
]
=
"Round"
os
.
environ
[
"MXNET_GPU_MEM_POOL_TYPE"
]
=
"Round"
import
dgl
import
dgl.data
as
data
import
mxnet
as
mx
import
mxnet
as
mx
import
numpy
as
np
import
numpy
as
np
from
mxnet
import
gluon
from
mxnet
import
gluon
from
tree_lstm
import
TreeLSTM
from
tree_lstm
import
TreeLSTM
import
dgl
import
dgl.data
as
data
SSTBatch
=
collections
.
namedtuple
(
SSTBatch
=
collections
.
namedtuple
(
"SSTBatch"
,
[
"graph"
,
"mask"
,
"wordid"
,
"label"
]
"SSTBatch"
,
[
"graph"
,
"mask"
,
"wordid"
,
"label"
]
)
)
...
...
examples/mxnet/tree_lstm/tree_lstm.py
View file @
704bcaf6
...
@@ -5,13 +5,13 @@ https://arxiv.org/abs/1503.00075
...
@@ -5,13 +5,13 @@ https://arxiv.org/abs/1503.00075
import
itertools
import
itertools
import
time
import
time
import
dgl
import
mxnet
as
mx
import
mxnet
as
mx
import
networkx
as
nx
import
networkx
as
nx
import
numpy
as
np
import
numpy
as
np
from
mxnet
import
gluon
from
mxnet
import
gluon
import
dgl
class
_TreeLSTMCellNodeFunc
(
gluon
.
HybridBlock
):
class
_TreeLSTMCellNodeFunc
(
gluon
.
HybridBlock
):
def
hybrid_forward
(
self
,
F
,
iou
,
b_iou
,
c
):
def
hybrid_forward
(
self
,
F
,
iou
,
b_iou
,
c
):
...
...
examples/pytorch/GATNE-T/src/utils.py
View file @
704bcaf6
...
@@ -9,8 +9,7 @@ import numpy as np
...
@@ -9,8 +9,7 @@ import numpy as np
import
torch
import
torch
from
gensim.models.keyedvectors
import
Vocab
from
gensim.models.keyedvectors
import
Vocab
from
six
import
iteritems
from
six
import
iteritems
from
sklearn.metrics
import
(
auc
,
f1_score
,
precision_recall_curve
,
from
sklearn.metrics
import
auc
,
f1_score
,
precision_recall_curve
,
roc_auc_score
roc_auc_score
)
def
parse_args
():
def
parse_args
():
...
...
examples/pytorch/GNN-FiLM/data_loader.py
View file @
704bcaf6
import
collections
import
collections
from
torch.utils.data
import
DataLoader
,
Dataset
import
dgl
import
dgl
from
dgl.data
import
PPIDataset
from
dgl.data
import
PPIDataset
from
torch.utils.data
import
DataLoader
,
Dataset
# implement the collate_fn for dgl graph data class
# implement the collate_fn for dgl graph data class
PPIBatch
=
collections
.
namedtuple
(
"PPIBatch"
,
[
"graph"
,
"label"
])
PPIBatch
=
collections
.
namedtuple
(
"PPIBatch"
,
[
"graph"
,
"label"
])
...
...
examples/pytorch/GNN-FiLM/main.py
View file @
704bcaf6
import
argparse
import
argparse
import
os
import
os
import
dgl
import
dgl.function
as
fn
import
numpy
as
np
import
numpy
as
np
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn
as
nn
...
@@ -8,9 +11,6 @@ import torch.nn.functional as F
...
@@ -8,9 +11,6 @@ import torch.nn.functional as F
from
data_loader
import
load_PPI
from
data_loader
import
load_PPI
from
utils
import
evaluate_f1_score
from
utils
import
evaluate_f1_score
import
dgl
import
dgl.function
as
fn
class
GNNFiLMLayer
(
nn
.
Module
):
class
GNNFiLMLayer
(
nn
.
Module
):
def
__init__
(
self
,
in_size
,
out_size
,
etypes
,
dropout
=
0.1
):
def
__init__
(
self
,
in_size
,
out_size
,
etypes
,
dropout
=
0.1
):
...
...
examples/pytorch/NGCF/NGCF/model.py
View file @
704bcaf6
import
dgl.function
as
fn
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn
as
nn
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
import
dgl.function
as
fn
class
NGCFLayer
(
nn
.
Module
):
class
NGCFLayer
(
nn
.
Module
):
def
__init__
(
self
,
in_size
,
out_size
,
norm_dict
,
dropout
):
def
__init__
(
self
,
in_size
,
out_size
,
norm_dict
,
dropout
):
...
@@ -31,7 +30,6 @@ class NGCFLayer(nn.Module):
...
@@ -31,7 +30,6 @@ class NGCFLayer(nn.Module):
self
.
norm_dict
=
norm_dict
self
.
norm_dict
=
norm_dict
def
forward
(
self
,
g
,
feat_dict
):
def
forward
(
self
,
g
,
feat_dict
):
funcs
=
{}
# message and reduce functions dict
funcs
=
{}
# message and reduce functions dict
# for each type of edges, compute messages and reduce them all
# for each type of edges, compute messages and reduce them all
for
srctype
,
etype
,
dsttype
in
g
.
canonical_etypes
:
for
srctype
,
etype
,
dsttype
in
g
.
canonical_etypes
:
...
...
examples/pytorch/NGCF/NGCF/utility/load_data.py
View file @
704bcaf6
...
@@ -3,10 +3,10 @@
...
@@ -3,10 +3,10 @@
# It implements the data processing and graph construction.
# It implements the data processing and graph construction.
import
random
as
rd
import
random
as
rd
import
numpy
as
np
import
dgl
import
dgl
import
numpy
as
np
class
Data
(
object
):
class
Data
(
object
):
def
__init__
(
self
,
path
,
batch_size
):
def
__init__
(
self
,
path
,
batch_size
):
...
...
examples/pytorch/P-GNN/main.py
View file @
704bcaf6
import
os
import
os
import
warnings
import
warnings
import
dgl
import
numpy
as
np
import
numpy
as
np
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn
as
nn
...
@@ -8,8 +10,6 @@ from model import PGNN
...
@@ -8,8 +10,6 @@ from model import PGNN
from
sklearn.metrics
import
roc_auc_score
from
sklearn.metrics
import
roc_auc_score
from
utils
import
get_dataset
,
preselect_anchor
from
utils
import
get_dataset
,
preselect_anchor
import
dgl
warnings
.
filterwarnings
(
"ignore"
)
warnings
.
filterwarnings
(
"ignore"
)
...
...
examples/pytorch/P-GNN/model.py
View file @
704bcaf6
import
dgl.function
as
fn
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn
as
nn
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
import
dgl.function
as
fn
class
PGNN_layer
(
nn
.
Module
):
class
PGNN_layer
(
nn
.
Module
):
def
__init__
(
self
,
input_dim
,
output_dim
):
def
__init__
(
self
,
input_dim
,
output_dim
):
...
...
examples/pytorch/P-GNN/utils.py
View file @
704bcaf6
...
@@ -17,7 +17,7 @@ def get_communities(remove_feature):
...
@@ -17,7 +17,7 @@ def get_communities(remove_feature):
# Randomly rewire 1% edges
# Randomly rewire 1% edges
node_list
=
list
(
graph
.
nodes
)
node_list
=
list
(
graph
.
nodes
)
for
(
u
,
v
)
in
graph
.
edges
():
for
u
,
v
in
graph
.
edges
():
if
random
.
random
()
<
0.01
:
if
random
.
random
()
<
0.01
:
x
=
random
.
choice
(
node_list
)
x
=
random
.
choice
(
node_list
)
if
graph
.
has_edge
(
u
,
x
):
if
graph
.
has_edge
(
u
,
x
):
...
...
examples/pytorch/TAHIN/TAHIN.py
View file @
704bcaf6
import
dgl
import
dgl.function
as
fn
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn
as
nn
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
import
dgl
import
dgl.function
as
fn
from
dgl.nn.pytorch
import
GATConv
from
dgl.nn.pytorch
import
GATConv
...
...
examples/pytorch/TAHIN/data_loader.py
View file @
704bcaf6
...
@@ -2,12 +2,12 @@ import os
...
@@ -2,12 +2,12 @@ import os
import
pickle
as
pkl
import
pickle
as
pkl
import
random
import
random
import
dgl
import
numpy
as
np
import
numpy
as
np
import
torch
import
torch
from
torch.utils.data
import
DataLoader
,
Dataset
from
torch.utils.data
import
DataLoader
,
Dataset
import
dgl
# Split data into train/eval/test
# Split data into train/eval/test
def
split_data
(
hg
,
etype_name
):
def
split_data
(
hg
,
etype_name
):
...
@@ -301,7 +301,6 @@ def process_movielens(root_path):
...
@@ -301,7 +301,6 @@ def process_movielens(root_path):
class
MyDataset
(
Dataset
):
class
MyDataset
(
Dataset
):
def
__init__
(
self
,
triple
):
def
__init__
(
self
,
triple
):
self
.
triple
=
triple
self
.
triple
=
triple
self
.
len
=
self
.
triple
.
shape
[
0
]
self
.
len
=
self
.
triple
.
shape
[
0
]
...
...
examples/pytorch/TAHIN/main.py
View file @
704bcaf6
import
argparse
import
argparse
import
pickle
as
pkl
import
pickle
as
pkl
import
dgl
import
numpy
as
np
import
numpy
as
np
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn
as
nn
...
@@ -14,8 +16,6 @@ from utils import (
...
@@ -14,8 +16,6 @@ from utils import (
evaluate_logloss
,
evaluate_logloss
,
)
)
import
dgl
def
main
(
args
):
def
main
(
args
):
# step 1: Check device
# step 1: Check device
...
...
examples/pytorch/appnp/train.py
View file @
704bcaf6
import
argparse
import
argparse
import
time
import
time
import
dgl
import
numpy
as
np
import
numpy
as
np
import
torch
import
torch
import
torch.nn
as
nn
import
torch.nn
as
nn
import
torch.nn.functional
as
F
import
torch.nn.functional
as
F
from
appnp
import
APPNP
from
appnp
import
APPNP
from
dgl.data
import
(
import
dgl
CiteseerGraphDataset
,
from
dgl.data
import
(
CiteseerGraphDataset
,
CoraGraphDataset
,
CoraGraphDataset
,
PubmedGraphDataset
,
register_data_args
)
PubmedGraphDataset
,
register_data_args
,
)
def
evaluate
(
model
,
features
,
labels
,
mask
):
def
evaluate
(
model
,
features
,
labels
,
mask
):
...
...
Prev
1
2
3
4
5
6
…
17
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment