Skip to content

EdgeCNN

EdgeCNN(
    node_features_dim: Union[int, Tuple[int, int]],
    hidden_features_dim: int,
    num_layers: int,
    out_features_dim: Optional[int] = None,
    dropout: float = 0.0,
    act: Activation = "relu",
    norm: Normalization = None,
    jk: Optional[Literal["cat", "max", "lstm"]] = None,
    **kwargs: Any,
)

Bases: BasicGNN

The Dynamic Graph CNN model from the "Dynamic Graph CNN for Learning on Point Clouds" paper, a stack of EdgeConv layers, each with a two-layer MLP mapping 2 * in_dim features to out_dim.

The graph is fixed (given by edge_index), not recomputed from the embeddings at every layer.

Parameters:

Name Type Description Default
node_features_dim Union[int, Tuple[int, int]]

Size of the input node features.

required
hidden_features_dim int

Size of the hidden node embeddings.

required
num_layers int

Number of message passing layers.

required
out_features_dim Optional[int]

Size of the output. Default: None

None
dropout float

Dropout probability. Default: 0.0

0.0
act Activation

Activation between layers and inside the MLPs of the convolutions (as PyG). Default: "relu"

'relu'
norm Normalization

Normalization between layers and inside the MLPs of the convolutions (as PyG). Default: None

None
jk Optional[Literal['cat', 'max', 'lstm']]

Jumping Knowledge mode. Default: None

None
**kwargs Any

Additional arguments of EdgeConv (e.g. aggr="mean"; "max" by default).

{}

Example:

from mlx_graphs.nn import EdgeCNN

model = EdgeCNN(3, 64, num_layers=3, out_features_dim=10)
out = model(edge_index, node_features)
Source code in mlx_graphs/nn/models/basic_gnn.py
def __init__(
    self,
    node_features_dim: Union[int, Tuple[int, int]],
    hidden_features_dim: int,
    num_layers: int,
    out_features_dim: Optional[int] = None,
    dropout: float = 0.0,
    act: Activation = "relu",
    norm: Normalization = None,
    jk: Optional[Literal["cat", "max", "lstm"]] = None,
    **kwargs: Any,
):
    super().__init__()
    if num_layers < 1:
        raise ValueError("`num_layers` must be at least 1")

    self.node_features_dim = node_features_dim
    self.hidden_features_dim = hidden_features_dim
    self.num_layers = num_layers
    self.out_features_dim = (
        out_features_dim if out_features_dim is not None else hidden_features_dim
    )
    self.act = _resolve_activation(act)
    # Normalization name, for convolutions with inner MLPs (`init_conv`).
    self._norm_name = norm
    self.dropout = nn.Dropout(dropout) if dropout > 0.0 else None
    self._dropout_p = dropout

    # Without Jumping Knowledge the last convolution maps directly to the
    # output size; with it, every convolution outputs hidden embeddings and
    # a final linear layer produces the output.
    conv_out_last = hidden_features_dim
    if out_features_dim is not None and jk is None:
        conv_out_last = out_features_dim
    self._plain_last = out_features_dim is not None and jk is None

    # As in PyG, a (src, dst) input size gives every layer separate
    # source and destination sizes.
    hidden_in: Union[int, Tuple[int, int]] = hidden_features_dim
    if isinstance(node_features_dim, (tuple, list)):
        node_features_dim = tuple(node_features_dim)
        hidden_in = (hidden_features_dim, hidden_features_dim)
    in_dims = [node_features_dim] + [hidden_in] * (num_layers - 1)
    out_dims = [hidden_features_dim] * (num_layers - 1) + [conv_out_last]
    self.convs = [
        self.init_conv(in_dim, out_dim, is_last=(i == num_layers - 1), **kwargs)
        for i, (in_dim, out_dim) in enumerate(zip(in_dims, out_dims))
    ]

    num_post = num_layers - 1 if self._plain_last else num_layers
    if norm is not None:
        self.norms = [
            _make_norm(norm, hidden_features_dim) for _ in range(num_post)
        ]

    if jk is not None:
        self.jk = JumpingKnowledge(jk, hidden_features_dim, num_layers)
        jk_dim = hidden_features_dim * (num_layers if jk == "cat" else 1)
        if out_features_dim is not None or jk == "cat":
            self.lin = Linear(jk_dim, self.out_features_dim)

from mlx_graphs.nn import EdgeCNN · mlx_graphs/nn/models/edge_cnn.py