GlobalMeanPool#
- class deeplay.models.gnn.gtogmpm.GlobalMeanPool(*args, **kwargs)#
Bases:
DeeplayModuleGlobal mean pooling layer for Graph Neural Networks.
Constraints#
- Inputs:
x: torch.Tensor of shape (num_nodes, num_features)
batch: torch.Tensor of shape (num_nodes,)
Inputs can be passed to the forward method as a tuple or as separate arguments.
Output: torch.Tensor of shape (batch_size, num_features)
Examples#
>>> # Global mean pooling layer >>> layer = GlobalMeanPool().create() >>> # Define input as a tuple of node features and batch >>> x = torch.randn(10, 16) >>> batch = torch.Tensor([0, 0, 0, 1, 1, 1, 2, 2, 2, 2]).long() >>> out1 = layer((x, batch)) >>> # Define input as separate arguments >>> out2 = layer(x, batch) >>> torch.allclose(out1, out2) True >>> out1.shape torch.Size([3, 16])
Methods Summary
forward(x)Define the computation performed at every call.
Methods Documentation
- forward(x)#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.