Lin-Yijie / Graph-Matching-Networks

PyTorch implementation of Graph Matching Networks, e.g., Graph Matching with Bi-level Noisy Correspondence (COMMON, ICCV 2023), Graph Matching Networks for Learning the Similarity of Graph Structured Objects (GMN, ICML 2019).
Other
271 stars 55 forks source link

Node and edge features #3

Closed tathagatv closed 2 years ago

tathagatv commented 2 years ago

I'm trying to use this model with some node and edge features. Lines 229-230 in dataset.py of the _pack_batch function set node and edge feature dimensions as 1. If I increase this size to any number >1, I'm getting runtime errors. The following was obtained on changing the node and feature dimensions to 2, by changing the dimension in lines 229-230 of dataset.py : RuntimeError: Function AddmmBackward returned an invalid gradient at index 1 - got [1604, 65] but expected shape compatible with [1604, 66]. Experimenting with some other values for the dimension, I realized that the difference in dimension 1 of these error tensors is equal to feature_dimension-1. Can some model changes be suggested in order to allow higher feature dimensions?

Lin-Yijie commented 2 years ago

The problem may be caused by the gru module. I recommend for changing the gru module (lines 196 and 287) in graphembeddingnetwork.py first. Line 35 in graphembeddingnetwork.py ("def _build_model" in "class GraphEncoder") and configure.py may also need to be changed but I'm not very sure. There may exist other solutions by changing the "node_update_type='gru'" to "mlp" in configure.py.

tathagatv commented 2 years ago

@Lin-Yijie, changing gru to mlp didn't help. I found the following issues in the code which I believe are responsible for the problem:

  1. Line 74 of graphembeddingnetwork.py should be edge_outputs = self.MLP2(edge_features) instead of edge_outputs = self.MLP2(node_features).
  2. Line 178 and 188 of graphembeddingnetwork.py. The input dimension used is self._edge_hidden_sizes[0] + 1, it should instead be self._edge_output_dim + 2*self._node_state_dim. We need to additionally define self._edge_output_dim as the size of edge_outputs which is generated by GraphEncoder. The 2*self._node_state_dim comes due to line 110 of graphembeddingnetwork.py, where we are appending the node_features.

The model is working fine after these changes.

Lin-Yijie commented 2 years ago

Thanks~ Could you please pull your recent code graphembeddingnetwork.py to this Repository? Thanks a lot for your help!