RuntimeError: The size of tensor a (571) must match the size of tensor b (2) at non-singleton dimension 0
rashmibennur opened this issue · 4 comments
Getting run-time error while trying to run the cross-validation with explainer network code on Colab.
Package versions used:
torch: 1.9.0+cu102
torch-explain: 0.5.6
Following is the error message:
RuntimeError Traceback (most recent call last)
in ()
57
58 start = time.time()
---> 59 trainer.fit(model, train_loader, val_loader)
60 model.freeze()
61 model_results = trainer.test(model, test_dataloaders=test_loader)
20 frames
/usr/local/lib/python3.7/dist-packages/torch_explain/nn/logic.py in forward(self, input)
46 self.alpha_norm = self.alpha / self.alpha.max(dim=1)[0].unsqueeze(1)
47 self.concept_mask = self.alpha_norm > 0.5
---> 48 x = input.multiply(self.alpha_norm.unsqueeze(1))
49
50 # compute linear map
RuntimeError: The size of tensor a (571) must match the size of tensor b (2) at non-singleton dimension 0
Have you tried upgrading to the latest version: torch-explain v0.6.5?
Are you running a specific script from this repo?
Yes, was trying to run script experiments/vdem.ipynb
torch-explain v0.6.5 is being used.
I've just updated the script experiments/vdem.ipynb, now it should work. There was a squeeze
missing in the script (line 101, 102 and 103): c_train_pred = model_xc.model(x_train).squeeze()
instead of c_train_pred = model_xc.model(x_train)
.
Let me know if it works now :)
Yes, this works. thanks