Skip to content

AssertionError: 'input' and 'target' must have the same shape #36

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
sponge-dad opened this issue Mar 12, 2025 · 0 comments
Open

AssertionError: 'input' and 'target' must have the same shape #36

sponge-dad opened this issue Mar 12, 2025 · 0 comments

Comments

@sponge-dad
Copy link

In lib/losses3D/BaseClass.py, I encountered an error on line 56:

assert input.size() == target.size(), "'input' and 'target' must have the same shape"

Image

Upon inspection, I found that the shapes of input and target are different:

  • input.shape: torch.Size([4, 4, 128, 128, 48])
  • target.shape: torch.Size([4, 1, 128, 128, 48])

The mismatch occurs in dimension 1 (the channels dimension).

After debugging, I traced the source of input and target to the prepare_input function in lib/utils/general.py. At this stage:

Image

  • The function parameters are modalities == 3 and channels == 3
  • At this point, target.shape is already torch.Size([4, 1, 128, 128, 48])
  • However, after passing through the convolutional layers, input_tensor transforms from torch.Size([4, 3, 128, 128, 48]) to torch.Size([4, 4, 128, 128, 48]), leading to the shape mismatch.
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

1 participant