New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
predicting on a batch of sparse tensors #365
Comments
Hi, batch mode does not support sparse tensors (due to TensorFlow shenanigans) so you need to cast your adjacency matrices to np.arrays. Cheers |
Hi @danielegrattarola , thank you for this! i did not know sparse tensors would cause a problem when feeding in batches! its slightly problematic as i would need to store a buffer of non sparse adjacency matrices ha! I haver to reduce the buffer size.. with regards to the y tensor - if i feed it in as input shapes cause me headache in tensorflow - even when they are seemingly correct.. |
Have you considered using disjoint mode instead of batch mode? Disjoint mode uses sparse adjacency matrices. I don't know what's going on with your model/data, but node features in batch mode are expected to be 3-dimensional, so even if it doesn't crash with a 4-dimensional tensor you can be sure that the resulting computation will not be as expected. |
Hi @danielegrattarola , I made a silly mistake in the input for the node features! before, my input was:
but the correct shape to put as you pointed out is batch,
now with an input of shape It would be preferable to feed in sparse tensors for the graphs as i need to feed in many at a time, however, i also need to predict on one sample as well which is why i was trying to avoid the loaders. Can the disjoint loader be fed in as a normal input with adjacency matrices only? for example would this work?
thanks! |
No, the disjoint loader creates batches of inputs with a generator, you cannot pass it to the model like that. |
perfect, thank you so much for clarfiying - by own training loop do you mean the GradientTape method? if so, yes this is a possibility. and with the disjoint loader, am i only able to provide the adjacency matrix with node features without y labels, as i wont be predicting on a specific set of y labels.. thank you! |
Yes, that's what I meant. If you can take care of creating the batches, there's no need to use a loader at all. Cheers |
thank you so much! again, for your time in answering al of my questions :) the only problematic part still is that i need to feed in the sparse adj matrices due to the size of the batch itself! I will see if i can think of a workaround. thank you again! |
Hi @danielegrattarola ,
I posted the other day about the adjacency matrix input - sorry for a second post, but i am now trying to predict on a batch of sparse tensors with no success - I won't post all of the code, however, i have tried feeding in the adj matrix by creating a dataset and then using the batchloader with no success.. as well as the following:
dummy network:
if i create a dummy batch of data:
if i predict on one sample (as discussed the other day) this works without issue
dummy_gnn([y[0], practice_batch[0])
however, if I now predict on a batch of sparse tensors.. this fails..
this now produces an error
AssertionError: Expected a of rank 2 or 3, got 4
If i create a dummy network with only an input for the node features (y), the batch is accepted without issue, so the problem seems to be with the batch of sparse tensors (adjacency matrix input) - I have tried so many different ways of feeding these tensors in, any help is appreciated!! thank you again :)
The text was updated successfully, but these errors were encountered: