danielegrattarola / spektral

Graph Neural Networks with Keras and Tensorflow 2.
https://graphneural.network
MIT License
2.37k stars 334 forks source link

ValueError: Exception encountered when calling layer "gcn_4" (type GCN) #394

Open Lav-Mehta opened 2 years ago

Lav-Mehta commented 2 years ago

Hello, i am using the following code with a disjoint loader as follows:

batch_size = 32 loader_tr = DisjointLoader(data_tr, batch_size=batch_size, epochs=epochs, node_level=True, shuffle=True) loader_va = DisjointLoader(data_va, batch_size=batch_size, node_level=True, shuffle = True) loader_te = DisjointLoader(data_te, batch_size=batch_size, node_level=True, shuffle= False)

mask_tr, mask_va, mask_te = loader_tr, loader_va, loader_te model = GCN(n_labels=d.n_labels) optimizer = Adam(lr=1e-2) loss_fn = CategoricalCrossentropy()

Training step

@tf.function
def train():
    with tf.GradientTape() as tape:
        predictions = model([x, a], training=True)
        loss = loss_fn(y[mask_tr], predictions[mask_tr])
        loss += sum(model.losses)
    gradients = tape.gradient(loss, model.trainable_variables)
    optimizer.apply_gradients(zip(gradients, model.trainable_variables))
    return loss

Time the execution of 200 epochs of training

train()  # Warm up to ignore tracing times when timing
tic()
for epoch in range(1, 201):
    loss = train()
toc("Spektral - GCN (200 epochs)")
print(f"Final loss = {loss}")`

I am getting the following error: ---> 21 train() ValueError: in user code: ValueError: Exception encountered when calling layer "gcn_4" (type GCN) ValueError: Exception encountered when calling layer "dropout_8" (type Dropout). Dimension 0 in both shapes must be equal, but are 185 and 189. Shapes are [185,38] and [189,38].

Too many ValueError for one day, I am not able to understand the error at first place, any help would be appreciated.

danielegrattarola commented 2 years ago

Hey,

are you using one of the standard datasets when you get this error?

Lav-Mehta commented 2 years ago

Hi Daniele, No not a standard dataset i have generated my own X, Y, and A

danielegrattarola commented 2 years ago

Can you provide a brief piece of code with mock data to reproduce the error on my machine?

Thanks

Lav-Mehta commented 2 years ago

Sure @danielegrattarola please give me sometime, will replicate and update the code here. Thanks