Skip to content

Question about RuntimeError: Predictions and targets are expected to have the same shape #695

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

Open
megamattc opened this issue Mar 30, 2025 · 2 comments

Comments

@megamattc
Copy link

megamattc commented Mar 30, 2025

Hi,

Recently I was trying to train a segmenter model from the command-line and I encountered the following error:

RuntimeError: Predictions and targets are expected to have the same shape, but 
got torch.Size([1, 8, 450, 348]) and torch.Size([1, 7, 450, 348]).

The model I was using as the base model was not model_best.mlmodel because the training process did not produce it (it simply stopped at the 50th epoch). The training data is of the same type as the one used to train the base model.

Can someone please explain what the error means? I do not see how the model parameters could have changed given that I took an output from the previous training cycle and used it as the base model for the next one, using very similar training data.

@mittagessen
Copy link
Owner

mittagessen commented Mar 31, 2025 via email

@megamattc
Copy link
Author

Hi,

I believe I installed from the main branch of the repository (pip install git+https://github.com/mittagessen/kraken.git) on a VM and ran the same command as above, but I got the same error:

RuntimeError: Predictions and targets are expected to have the same shape, but got torch.Size([1, 9, 450, 557]) and torch.Size([1, 8, 450, 557]).

So I don't know what to do now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants