tfg.geometry.convolution.graph_convolution.edge_convolution_template
Stay organized with collections
Save and categorize content based on your preferences.
A template for edge convolutions.
tfg.geometry.convolution.graph_convolution.edge_convolution_template(
data: type_alias.TensorLike,
neighbors: tf.sparse.SparseTensor,
sizes: type_alias.TensorLike,
edge_function: Callable[[type_alias.TensorLike, type_alias.TensorLike], type_alias.TensorLike],
reduction: str,
edge_function_kwargs: Dict[str, Any],
name: str = 'graph_convolution_edge_convolution_template'
) -> tf.Tensor
This function implements a general edge convolution for graphs of the form
\(y_i = \sum_{j \in \mathcal{N}(i)} w_{ij} f(x_i, x_j)\), where
\(\mathcal{N}(i)\) is the set of vertices in the neighborhood of vertex
\(i\), \(x_i \in \mathbb{R}^C\) are the features at vertex \(i\),
\(w_{ij} \in \mathbb{R}\) is the weight for the edge between vertex \(i\)
and vertex \(j\), and finally
\(f(x_i, x_j): \mathbb{R}^{C} \times \mathbb{R}^{C} \to \mathbb{R}^{D}\) is
a user-supplied function.
This template also implements the same general edge convolution described
above with a max-reduction instead of a weighted sum.
An example of how this template can be used is for Laplacian smoothing,
which is defined as
\(y_i = \frac{1}{|\mathcal{N(i)}|} \sum_{j \in \mathcal{N(i)} } x_j\).
edge_convolution_template
can be used to perform Laplacian smoothing by
setting
\(w_{ij} = \frac{1}{|\mathcal{N(i)}|}\), edge_function=lambda x, y: y
,
and reduction='weighted'
.
The shorthands used below are
V
: The number of vertices.
C
: The number of channels in the input data.
Note |
In the following, A1 to An are optional batch dimensions.
|
Args |
data
|
A float tensor with shape [A1, ..., An, V, C] .
|
neighbors
|
A SparseTensor with the same type as data and with shape
[A1, ..., An, V, V] representing vertex neighborhoods. The neighborhood
of a vertex defines the support region for convolution. The value at
neighbors[A1, ..., An, i, j] corresponds to the weight \(w_{ij}\)
above. Each vertex must have at least one neighbor.
|
sizes
|
An int tensor of shape [A1, ..., An] indicating the true input
sizes in case of padding (sizes=None indicates no padding). Note that
sizes[A1, ..., An] <= V . If data and neighbors are 2-D, sizes will
be ignored. As an example, consider an input consisting of three graphs
G0, G1, and G2 with V0, V1, and V2 vertices respectively. The padded input
would have the shapes [3, V, C] , and [3, V, V] for data and
neighbors respectively, where V = max([V0, V1, V2]) . The true sizes of
each graph will be specified by sizes=[V0, V1, V2] and data[i, :Vi, :]
and neighbors[i, :Vi, :Vi] will be the vertex and neighborhood data of
graph Gi. The SparseTensor neighbors should have no nonzero entries in
the padded regions.
|
edge_function
|
A callable that takes at least two arguments of vertex
features and returns a tensor of vertex features. Y = f(X1, X2,
**kwargs) , where X1 and X2 have shape [V3, C] and Y must have
shape [V3, D], D >= 1 .
|
reduction
|
Either 'weighted' or 'max'. Specifies the reduction over the
neighborhood. For 'weighted', the reduction is a weighted sum as shown
in the equation above. For 'max' the reduction is a max over features in
which case the weights \(w_{ij}\) are ignored.
|
edge_function_kwargs
|
A dict containing any additional keyword arguments to
be passed to edge_function .
|
name
|
A name for this op. Defaults to
graph_convolution_edge_convolution_template .
|
Returns |
Tensor with shape [A1, ..., An, V, D] .
|
Raises |
TypeError
|
if the input types are invalid.
|
ValueError
|
if the input dimensions are invalid.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-10-28 UTC.
[null,null,["Last updated 2022-10-28 UTC."],[],[],null,["# tfg.geometry.convolution.graph_convolution.edge_convolution_template\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/graphics/blob/master/tensorflow_graphics/geometry/convolution/graph_convolution.py#L164-L290) |\n\nA template for edge convolutions. \n\n tfg.geometry.convolution.graph_convolution.edge_convolution_template(\n data: type_alias.TensorLike,\n neighbors: tf.sparse.SparseTensor,\n sizes: type_alias.TensorLike,\n edge_function: Callable[[type_alias.TensorLike, type_alias.TensorLike], type_alias.TensorLike],\n reduction: str,\n edge_function_kwargs: Dict[str, Any],\n name: str = 'graph_convolution_edge_convolution_template'\n ) -\u003e tf.Tensor\n\nThis function implements a general edge convolution for graphs of the form\n\\\\(y_i = \\\\sum_{j \\\\in \\\\mathcal{N}(i)} w_{ij} f(x_i, x_j)\\\\), where\n\\\\(\\\\mathcal{N}(i)\\\\) is the set of vertices in the neighborhood of vertex\n\\\\(i\\\\), \\\\(x_i \\\\in \\\\mathbb{R}\\^C\\\\) are the features at vertex \\\\(i\\\\),\n\\\\(w_{ij} \\\\in \\\\mathbb{R}\\\\) is the weight for the edge between vertex \\\\(i\\\\)\nand vertex \\\\(j\\\\), and finally\n\\\\(f(x_i, x_j): \\\\mathbb{R}\\^{C} \\\\times \\\\mathbb{R}\\^{C} \\\\to \\\\mathbb{R}\\^{D}\\\\) is\na user-supplied function.\n\nThis template also implements the same general edge convolution described\nabove with a max-reduction instead of a weighted sum.\n\nAn example of how this template can be used is for Laplacian smoothing,\nwhich is defined as\n\\\\(y_i = \\\\frac{1}{\\|\\\\mathcal{N(i)}\\|} \\\\sum_{j \\\\in \\\\mathcal{N(i)} } x_j\\\\).\n`edge_convolution_template` can be used to perform Laplacian smoothing by\nsetting\n\\\\(w_{ij} = \\\\frac{1}{\\|\\\\mathcal{N(i)}\\|}\\\\), `edge_function=lambda x, y: y`,\nand `reduction='weighted'`.\n\nThe shorthands used below are\n`V`: The number of vertices.\n`C`: The number of channels in the input data.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Note ---- ||\n|---|---|\n| In the following, A1 to An are optional batch dimensions. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data` | A `float` tensor with shape `[A1, ..., An, V, C]`. |\n| `neighbors` | A `SparseTensor` with the same type as `data` and with shape `[A1, ..., An, V, V]` representing vertex neighborhoods. The neighborhood of a vertex defines the support region for convolution. The value at `neighbors[A1, ..., An, i, j]` corresponds to the weight \\\\(w_{ij}\\\\) above. Each vertex must have at least one neighbor. |\n| `sizes` | An `int` tensor of shape `[A1, ..., An]` indicating the true input sizes in case of padding (`sizes=None` indicates no padding). Note that `sizes[A1, ..., An] \u003c= V`. If `data` and `neighbors` are 2-D, `sizes` will be ignored. As an example, consider an input consisting of three graphs G0, G1, and G2 with V0, V1, and V2 vertices respectively. The padded input would have the shapes `[3, V, C]`, and `[3, V, V]` for `data` and `neighbors` respectively, where `V = max([V0, V1, V2])`. The true sizes of each graph will be specified by `sizes=[V0, V1, V2]` and `data[i, :Vi, :]` and `neighbors[i, :Vi, :Vi]` will be the vertex and neighborhood data of graph Gi. The `SparseTensor` `neighbors` should have no nonzero entries in the padded regions. |\n| `edge_function` | A callable that takes at least two arguments of vertex features and returns a tensor of vertex features. `Y = f(X1, X2, **kwargs)`, where `X1` and `X2` have shape `[V3, C]` and `Y` must have shape `[V3, D], D \u003e= 1`. |\n| `reduction` | Either 'weighted' or 'max'. Specifies the reduction over the neighborhood. For 'weighted', the reduction is a weighted sum as shown in the equation above. For 'max' the reduction is a max over features in which case the weights \\\\(w_{ij}\\\\) are ignored. |\n| `edge_function_kwargs` | A dict containing any additional keyword arguments to be passed to `edge_function`. |\n| `name` | A name for this op. Defaults to `graph_convolution_edge_convolution_template`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| Tensor with shape `[A1, ..., An, V, D]`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|--------------------------------------|\n| `TypeError` | if the input types are invalid. |\n| `ValueError` | if the input dimensions are invalid. |\n\n\u003cbr /\u003e"]]