使用DGL库得到图数据的一个数据的形状是Data(x=[38, 10], edge_index=[2, 43], edge_attr=[43], y=0, mol_attr=[1400]),其中x, edge_index输入到卷积层,想让mol_attr和卷积完成后的特征共同输入到全连接层,该怎么做,在共同输入到全连接层的时候,两个特征因为维度问题总是出错,该怎么办?
#模型代码:
class GCN(torch.nn.Module):
def __init__(self, hidden_channels):
super(GCN, self).__init__()
torch.manual_seed(12345)
self.conv1 = GCNConv(dataset.num_node_features, hidden_channels)
self.conv2 = GCNConv(hidden_channels, hidden_channels)
self.conv3 = GCNConv(hidden_channels, hidden_channels)
self.lin = Linear(hidden_channels, dataset.num_classes)
def forward(self, x, edge_index, batch):
# 1. Obtain node embeddings
x = self.conv1(x, edge_index)
x = x.relu()
x = self.conv2(x, edge_index)
x = x.relu()
x = self.conv3(x, edge_index)
# 2. Readout layer
x = global_mean_pool(x, batch) # [batch_size, hidden_channels]
# 3. Apply a final classifier
x = F.dropout(x, p=0.5, training=self.training)
x = self.lin(x)
return x