-
I am trying to implement CGConv, for which there is no example unfortunately :( Here is my network: f1 = np.random.randint(10, size=(21))
f2 = np.random.randint(10,20, size=(21))
f3 = np.random.randint(20,30, size=(21))
f_final = np.stack((f1,f2,f3), axis=1)
capital = 2*f1 + f2 - f3
f1_t = torch.from_numpy(f1)
f2_t = torch.from_numpy(f2)
f3_t = torch.from_numpy(f3)
capital_t = torch.from_numpy(capital)
capital_t = capital_t.type(torch.FloatTensor)
x = torch.from_numpy(f_final)
x = x.type(torch.FloatTensor)
edge_index = edge_index = torch.tensor([[0,1],[1,0],[0,5],[5,0],[0,4],[4,0],[1, 2],
[2, 1],[1,3],[3,1],[1,4],[4,1],[2,7],[7,2],[2,6],[6,2],[2,3],[3,2],[3,6],[6,3],[3,5],[5,3],[4,5],[5,4],
[5,9],[9,5],[6,10],[10,6],[6,8],[8,6],[6,7],[7,6],[6,11],[11,6],[7,12],[12,7],[3,8],[8,3],[8,9],[9,8],
[8,10],[10,8],[8,14],[14,8],[9,13],[13,9],[9,10],[10,9],[10,11],[11,10],[12,4],[4,12],[12,14],[14,12],
[12,13],[13,12],[9,13],[13,9],[13,5],[5,13],[14,4],[4,14],[1,15],[15,1],[4,15],[15,4],
[3,15],[15,3],[2,16],[16,2],[5,16],[16,5],[13,16],[16,13],[17,9],[9,17],[17,12],[12,17],
[14,17],[17,14],[2,18],[18,2],[7,18],[18,7],[11,18],[18,11],[19,11],[11,19],[19,12],[12,19],
[19,10],[10,19],[20,4],[4,20],[20,5],[5,20],[13,20],[20,13]], dtype=torch.long)
#edge_attr = torch.tensor([[5],[-5],[2],[-2],[3],[-3],[6],[-6],[3],[-3],[1],[-1],[4],[-4],[2],[-2],[7],
## [-7],[11],[-11],[12],[-12],[4],[-4],[3],[-3],[2],[-2],[5],[-5],[1],[-1],[2],[-2],[3],[-3],], dtype=torch.float)
edge_attr = torch.tensor([[1],[4],[3],[5],[2],[3],[7],[1],[3],[6],[1],[3],[2],[4],[2],[7],[6],[5],
[11],[7],[3],[7],[3],[4],[12],[2],[4],[5],[3],[1],[2],[3],[4],[7],[6],[15],[3],[5],[4],
[4],[6],[3],[5],[7],[7],[6],[9],[1],[7]],dtype=torch.float)
data = Data(x = x, edge_index = edge_index.t().contiguous(), y = capital_t, edge_attr=edge_attr )
print(data) And the function I wrote for CGConv is as follows: from torch_geometric.nn import CGConv
class CGCN(torch.nn.Module):
def __init__(self, hidden_channels):
super(CGCN, self).__init__()
torch.manual_seed(12345)
self.conv1 = CGConv(data.num_features, hidden_channels)
self.conv2 = CGConv(hidden_channels, 1)
def forward(self, x, edge_index, edge_attr):
x = self.conv1(x, edge_index, edge_attr)
x = x.relu()
x = F.dropout(x, p=0.5, training=self.training)
x = self.conv2(x, edge_index,edge_attr )
return x
modelCGCN = CGCN(hidden_channels=2)
print(modelCGCN) Where I try to train the model: modelCGCN = CGCN(hidden_channels=2)
optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4)
criterion = torch.nn.MSELoss()
def trainCGCN():
modelCGCN.train()
optimizer.zero_grad() # Clear gradients.
out = modelCGCN(data.x, data.edge_index, data.edge_attr) # Perform a single forward pass.
loss = criterion(out[data.train_mask].squeeze(), data.y[data.train_mask].squeeze()) # Compute the loss solely based on the training nodes.
loss.backward() # Derive gradients.
optimizer.step() # Update parameters based on gradients.
return loss I keep getting this error:
Could someone please help me find the error? |
Beta Was this translation helpful? Give feedback.
Answered by
riskiem
Jul 15, 2021
Replies: 1 comment 3 replies
-
Never mind, I figured out the problem. |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
riskiem
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Never mind, I figured out the problem.