mindspore_gl.nn.STConv

查看源文件
class mindspore_gl.nn.STConv(num_nodes: int, in_channels: int, hidden_channels: int, out_channels: int, kernel_size: int = 3, k: int = 3, bias: bool = True)[源代码]

时空图卷积层。 来自论文 A deep learning framework for traffic forecasting arXiv preprint arXiv:1709.04875, 2017. 。 STGCN层包含2个时间卷积层和1个图卷积层(ChebyNet)。

参数:
  • num_nodes (int) - 节点数。

  • in_channels (int) - 输入节点特征大小。

  • hidden_channels (int) - 隐藏特征大小。

  • out_channels (int) - 输出节点特征大小。

  • kernel_size (int, 可选) - 卷积内核大小。默认值:3

  • k (int, 可选) - Chebyshev过滤器大小。默认值:3

  • bias (bool, 可选) - 是否使用偏置。默认值:True

输入:
  • x (Tensor) - 输入节点特征。Shape为 \((B, T, N, (D_{in}))\) 其中 \(B\) 是批处理的大小, \(T\) 是输入时间步数, \(N\) 是节点数。 \((D_{in})\) 应等于参数中的 in_channels

  • edge_weight (Tensor) - 边权重。Shape为 \((N\_e,)\) 其中 \(N\_e\) 是边的数量。

  • g (Graph) - 输入图。

输出:
  • Tensor,输出节点特征,shape为 \((B, D_{out}, N, T)\), 其中 \(B\) 是批处理的大小, \((D_{out})\) 应与参数中的 out_channels 相等, \(N\) 是节点数, \(T\) 是输入时间步数。

异常:
  • TypeError - 如果 num_nodesin_channelsout_channelshidden_channelskernel_sizek 不是int。

  • TypeError - 如果 bias 不是bool。

支持平台:

Ascend GPU

样例:

>>> import numpy as np
>>> import mindspore as ms
>>> from mindspore_gl.nn.temporal import STConv
>>> from mindspore_gl import GraphField
>>> from mindspore_gl.graph import norm
>>> n_nodes = 4
>>> n_edges = 6
>>> feat_size = 2
>>> edge_attr = ms.Tensor([1, 1, 1, 1, 1, 1], ms.float32)
>>> edge_index = ms.Tensor([[1, 1, 2, 2, 3, 3],
>>>                         [0, 2, 1, 3, 0, 1]], ms.int32)
>>> edge_index, edge_weight = norm(edge_index, n_nodes, edge_attr, 'sym')
>>> edge_weight = ms.ops.Reshape()(edge_weight, ms.ops.Shape()(edge_weight) + (1,))
>>> batch_size = 2
>>> input_time_steps = 5
>>> feat = ms.Tensor(np.ones((batch_size, input_time_steps, n_nodes, feat_size)), ms.float32)
>>> graph_field = GraphField(edge_index[0], edge_index[1], n_nodes, n_edges)
>>> stconv = STConv(num_nodes=n_nodes, in_channels=feat_size,
>>>                 hidden_channels=3, out_channels=2,
>>>                 kernel_size=2, k=2)
>>> out = stconv(feat, edge_weight, *graph_field.get_graph())
>>> print(out.shape)
(2, 3, 4, 2)