Skip to content
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

Expose keepdim for torchgeo.transforms.indices #2329

Open
MathiasBaumgartinger opened this issue Oct 1, 2024 · 3 comments
Open

Expose keepdim for torchgeo.transforms.indices #2329

MathiasBaumgartinger opened this issue Oct 1, 2024 · 3 comments
Labels
transforms Data augmentation transforms

Comments

@MathiasBaumgartinger
Copy link
Contributor

Summary

Currently, none of the indices expose their inherited property keepdim. For some cases this might be useful.

Rationale

Without the usage of keepdim=True on the augmentations, my CrossEntropyLoss fails with RuntimeError: only batches of spatial targets supported (3D tensors) but got targets of dimension: [batch_size, 1, H, W], because an additional dimension is added.

Implementation

Expose keepdim: bool=False in __init()__

Alternatives

No response

Additional information

No response

@adamjstewart adamjstewart added the transforms Data augmentation transforms label Oct 1, 2024
@adamjstewart
Copy link
Collaborator

I've always wondered why keepdim isn't True by default, I can't think of any reason I would ever want it to be False.

Instead of explicitly adding a keepdim parameter, I would instead add **kwargs to all transforms and pass it directly to super().__init__().

@MathiasBaumgartinger
Copy link
Contributor Author

I agree, was quite flattered that some deep base augmentation class would for some reason add a completely unnecessary dimension. Anyway, some form of (by default keepdim=True) option and/or hint would be beneficial. Took me some time to debug that.

@adamjstewart
Copy link
Collaborator

Want to open a PR to add the kwargs forwarding? You could then show how to use keepdim in our Transforms tutorial.

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

No branches or pull requests

2 participants