class GCNLayer(nn.Module):
def __init__(self, in_feats, out_feats):
super(GCNLayer, self).__init__()
self.linear = nn.Linear(in_feats, out_feats)
def forward(self, g, feature):
# Creating a local scope so that all the stored ndata and edata
# (such as the `'h'` ndata below) are automatically popped out
# when the scope exits.
with g.local_scope():
g.ndata['h'] = feature
g.update_all(gcn_msg, gcn_reduce)
h = g.ndata['h']
return self.linear(h)
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.layer1 = GCNLayer(6, 16)
self.layer2 = GCNLayer(16, 1)
def forward(self, g, features):
x = F.relu(self.layer1(g, features))
x = self.layer2(g, x)
return x
net = Net()
x = torch.randn(32, 307, 6)# batch_size, node_count, feature_dim
G = dgl.graph((df_data[:,0],df_data[:,1]))#num_nodes=307, num_edges=340
output = net(G,x)#<-----it can not work
the above is the GCN.
output = net(G,x) can not work. I get this:
DGLError: Expect number of features to match number of nodes (len(u)). Got 32 and 307 instead.
So how to input batch of data (like x) into the GCN? Thank you guys!