RuntimeError: shape '[64, 19, 415]' is invalid for input of size 61189120

BabuRao69420: <p>I was trying to recreate someone else’s work, I have added a few print statements to find out where exactly the issue is occurring.</p>
<p>The problem occurs in the torch.reshape function, in the forward method of the DiffusionGraphConv class, it is located in “eeg-gnn-ssl-main/model/cell.py”</p>
<p>Link to the original github repository can be found in the first cell of the colab notebook<br>
Link to colab notebook for more details = <a href="https://colab.research.google.com/drive/1yaPclNIO01-Pte7umfAYfON5m5_ipyOI?usp=sharing" class="inline-onebox" rel="noopener nofollow ugc">Google Colab</a><br>
Link to my repository with the changes I made = <a href="https://drive.google.com/drive/folders/1XktSNJWNj9aiw0rKmy0BBhQEOYed3jYr?usp=sharing" class="inline-onebox" rel="noopener nofollow ugc">eeg-gnn-ssl-main - Google Drive</a></p>
<hr>
<p>RuntimeError                              Traceback (most recent call last)<br>
Cell In[16], line 33<br>
30 model = model.to(device)<br>
32 # Train<br>
—&gt; 33 train(model, dataloaders, device)<br>
35 # Load best model after training finished<br>
36 best_path = os.path.join(args.save_dir, ‘best.pth.tar’)</p>
<p>Cell In[15], line 58, in train(model, dataloaders, device)<br>
55 # Forward<br>
56 # (batch_size, num_classes)<br>
57 if args.model_name == “dcrnn”:<br>
—&gt; 58     logits = model(x, seq_lengths, supports)<br>
59 else:<br>
60     raise NotImplementedError</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)<br>
1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]<br>
1517 else:<br>
 → 1518     return self._call_impl(*args, **kwargs)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)<br>
1522 # If we don’t have any hooks, we want to skip the rest of the logic in<br>
1523 # this function, and just call forward.<br>
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks<br>
1525         or _global_backward_pre_hooks or _global_backward_hooks<br>
1526         or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1527     return forward_call(*args, **kwargs)<br>
1529 try:<br>
1530     result = None</p>
<p>Cell In[14], line 49, in DCRNNModel_classification.forward(self, input_seq, seq_lengths, supports)<br>
44 init_hidden_state = self.encoder.init_hidden(<br>
45     batch_size).to(self._device)<br>
47 # last hidden state of the encoder is the context<br>
48 # (max_seq_len, batch, rnn_units<em>num_nodes)<br>
—&gt; 49 _, final_hidden = self.encoder(input_seq, init_hidden_state, supports)<br>
50 # (batch_size, max_seq_len, rnn_units</em>num_nodes)<br>
51 output = torch.transpose(final_hidden, dim0=0, dim1=1)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)<br>
1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]<br>
1517 else:<br>
 → 1518     return self._call_impl(*args, **kwargs)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)<br>
1522 # If we don’t have any hooks, we want to skip the rest of the logic in<br>
1523 # this function, and just call forward.<br>
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks<br>
1525         or _global_backward_pre_hooks or _global_backward_hooks<br>
1526         or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1527     return forward_call(*args, **kwargs)<br>
1529 try:<br>
1530     result = None</p>
<p>Cell In[13], line 47, in DCRNNEncoder.forward(self, inputs, initial_hidden_state, supports)<br>
45 output_inner = <span class="chcklst-box fa fa-square-o fa-fw"></span><br>
46 for t in range(seq_length):<br>
—&gt; 47     _, hidden_state = self.encoding_cells[i_layer](<br>
48         supports, current_inputs[t, …], hidden_state)<br>
49     output_inner.append(hidden_state)<br>
50 output_hidden.append(hidden_state)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)<br>
1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]<br>
1517 else:<br>
 → 1518     return self._call_impl(*args, **kwargs)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)<br>
1522 # If we don’t have any hooks, we want to skip the rest of the logic in<br>
1523 # this function, and just call forward.<br>
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks<br>
1525         or _global_backward_pre_hooks or _global_backward_hooks<br>
1526         or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1527     return forward_call(*args, **kwargs)<br>
1529 try:<br>
1530     result = None</p>
<p>File /kaggle/input/syi-tang-my-beloved/eeg-gnn-ssl-main/model/cell.py:247, in DCGRUCell.forward(self, supports, inputs, state)<br>
244 else:<br>
245     fn = self._fc<br>
246 value = torch.sigmoid(<br>
 → 247     fn(supports, inputs, state, output_size, bias_start=1.0))<br>
248 value = torch.reshape(value, (-1, self._num_nodes, output_size))<br>
249 r, u = torch.split(<br>
250     value, split_size_or_sections=int(<br>
251         output_size / 2), dim=-1)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)<br>
1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]<br>
1517 else:<br>
 → 1518     return self._call_impl(*args, **kwargs)</p>
<p>File /opt/conda/lib/python3.10/site-packages/torch/nn/modules/module.py:1527, in Module._call_impl(self, *args, **kwargs)<br>
1522 # If we don’t have any hooks, we want to skip the rest of the logic in<br>
1523 # this function, and just call forward.<br>
1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks<br>
1525         or _global_backward_pre_hooks or _global_backward_hooks<br>
1526         or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1527     return forward_call(*args, **kwargs)<br>
1529 try:<br>
1530     result = None</p>
<p>File /kaggle/input/syi-tang-my-beloved/eeg-gnn-ssl-main/model/cell.py:151, in DiffusionGraphConv.forward(self, supports, inputs, state, output_size, bias_start)<br>
147 print(“Number of matrices:”, num_matrices)<br>
149 print(“Shape of x before reshaping:”, x.shape)<br>
 → 151 x = torch.reshape(<br>
152     x,<br>
153     shape=[<br>
154         batch_size,<br>
155         self._num_nodes,<br>
156         input_size *<br>
157         num_matrices])<br>
158 x = torch.reshape(<br>
159     x,<br>
160     shape=[<br>
(…)<br>
163         input_size *<br>
164         num_matrices])<br>
165 # (batch_size * self._num_nodes, output_size)</p>
<p>RuntimeError: shape ‘[64, 19, 415]’ is invalid for input of size 61189120</p>

BabuRao69420: <p>anyone willing to help please??</p>

ptrblck: <p>Your code is neither properly formatted nor executable, which helps in debugging.<br>
Based on the stacktrace this <code>reshape</code> fails:</p>
<pre data-code-wrap="python"><code class="lang-python">
[quote="BabuRao69420, post:1, topic:199299"]
File /kaggle/input/syi-tang-my-beloved/eeg-gnn-ssl-main/model/cell.py:151, in DiffusionGraphConv.forward(self, supports, inputs, state, output_size, bias_start)
147 print(“Number of matrices:”, num_matrices)
149 print(“Shape of x before reshaping:”, x.shape)
→ 151 x = torch.reshape(
152 x,
153 shape=[
154 batch_size,
155 self._num_nodes,
156 input_size *
157 num_matrices])
[/quote]
but it's unclear what this line is supposed to do without further information.</code></pre>