GatedGCNConv๏
- class dgl.nn.pytorch.conv.GatedGCNConv(input_feats, edge_feats, output_feats, dropout=0, batch_norm=True, residual=True, activation=<function relu>)[source]๏
Bases:
Module
Gated graph convolutional layer from Benchmarking Graph Neural Networks
where
is node feature of layer , is edge feature of layer , is sigmoid function, is a small fixed constant for numerical stability, are linear layers.- Parameters:
input_feats (int) โ Input feature size; i.e, the number of dimensions of
.edge_feats (int) โ Edge feature size; i.e., the number of dimensions of
.output_feats (int) โ Output feature size; i.e., the number of dimensions of
.dropout (float, optional) โ Dropout rate on node and edge feature. Default:
0
.batch_norm (bool, optional) โ Whether to include batch normalization on node and edge feature. Default:
True
.residual (bool, optional) โ Whether to include residual connections. Default:
True
.activation (callable activation function/layer or None, optional) โ If not None, apply an activation function to the updated node features. Default:
F.relu
.
Example
>>> import dgl >>> import torch as th >>> import torch.nn.functional as F >>> from dgl.nn import GatedGCNConv
>>> num_nodes, num_edges = 8, 30 >>> graph = dgl.rand_graph(num_nodes,num_edges) >>> node_feats = th.rand(num_nodes, 20) >>> edge_feats = th.rand(num_edges, 12) >>> gatedGCN = GatedGCNConv(20, 12, 20) >>> new_node_feats, new_edge_feats = gatedGCN(graph, node_feats, edge_feats) >>> new_node_feats.shape, new_edge_feats.shape (torch.Size([8, 20]), torch.Size([30, 20]))
- forward(graph, feat, edge_feat)[source]๏
Description๏
Compute gated graph convolution layer.
- param graph:
The graph.
- type graph:
DGLGraph
- param feat:
The input feature of shape
where is the number of nodes of the graph and is the input feature size.- type feat:
torch.Tensor
- param edge_feat:
The input edge feature of shape
, where is the number of edges and is the size of the edge features.- type edge_feat:
torch.Tensor
- returns:
torch.Tensor โ The output node feature of shape
where is the output feature size.torch.Tensor โ The output edge feature of shape
where is the output feature size.