Closed joshneudorf closed 3 years ago
Thank you for your message.
The EncodeProcessDecode
uses MLPs as the node, edge and global update, so the input features are expected to be a vector for each node, edge and global. From the input GraphsTuple
s you are printing it seems that your nodes and edges have a single scalar feature per node and edge, instead of a vector of size one, so you may have to add that additional dimension.
You may do so either directly when you build the graphs (By setting the feature for each node/edge to be something like [1.], rather than just 1.) or at the graphs_tuple directly, by using something like:
graph_tuple= graph_tuple.replace(nodes=graph_tuples.nodes[:, None],
edges=graph_tuples.edges[:, None])
both those solutions should make it so your input shape is something like:
graph_tuple.nodes.shape = [total_num_nodes, 1]
graph_tuple.edges.shape = [total_num_edges, 1]
And your output shape will also be like that, so you may want to squeeze that dimension before building your loss by doing the opposite:
graph_tuple= graph_tuple.replace(nodes=tf.squeeze(graph_tuples.nodes, axis=1), ...)
Note the total number of edges in your graph seems very high (5953500 to be precise, so you should probably drastically reduce your batch size, or you will run out of memory).
Also, I noticed that in your graph_tuple
your globals are set to []. Not sure what the reason for this is, but you may want to use .replace(globals=None)
somewhere else too, so you get proper error messages inside the model.
If you are not interested on using globals at all, you may want to replace the GraphNetwork
by an InteractionNetwork
in EncodeProcessDecode
, or set a a dummy features in the globals using utils_tf.set_zero_global_features, so you can more easily connect the
GraphNetwork` if you do want to have global updates.
Hope this helps!
Thank you very much for your detailed response. graph_tuple= graph_tuple.replace(nodes=graph_tuples.nodes[:, None], edges=graph_tuples.edges[:, None])
worked to fix the issue with Rank. I have also made sure to squeeze that dimension in my loss function, have switched globals to None, and as you said, I am running out of memory so I will try reducing the batch size to fix this.
Thank you again for your response!
Hello, I am excited to make use of this great library for graph neural networks. However, I am running into an issue where I get an error
ValueError: Shape (5953500,) must have rank >= 2
when passing an input to models.EncodeProcessDecode. The input is a graphs_tuple converted from a networkx graph using utils_np.networkxs_to_graphs_tuple (no global values, node features have all been set to 1.0, and the edges have values from a 90 x 90 adjacency matrix).For example:
where rmatrix_nx is a list of networkx graphs.
I am roughly following the tf2 sort example, doing something like this to set up the model and the update_step function:
Then when I run training steps (x_train, y_train, x_val, and y_val are training and validation subsets' input and output):
I get this error:
When I print the input graph_tuples:
I hope this isn't too verbose, I just wanted to make sure I provide enough information to describe the problem. Thank you for any insight you may have into this problem.