Skip to content

docs: clarify RandWeightedCrop(d) does not crop the weight map (#7851)#8962

Merged
ericspod merged 4 commits into
Project-MONAI:devfrom
aymuos15:fix/7851-randweightedcrop-wkey-docs
Jul 2, 2026
Merged

docs: clarify RandWeightedCrop(d) does not crop the weight map (#7851)#8962
ericspod merged 4 commits into
Project-MONAI:devfrom
aymuos15:fix/7851-randweightedcrop-wkey-docs

Conversation

@aymuos15

Copy link
Copy Markdown
Contributor

Addresses #7851 .

Description

RandWeightedCrop(d) uses w_key/weight_map only to pick patch locations; the map itself is passed through uncropped at its original size. Per #7851, this breaks DataLoader collation when the weight map is a separate key and images differ in shape. This documents the behavior on both the array and dict transforms, and notes that w_key should be added to keys to get a cropped weight map.

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • In-line docstrings updated.

…7851)

The w_key/weight_map is used only to compute patch sample locations and is
left unchanged at its original spatial size. When the weight map is loaded as
a separate key and the source images have different shapes, the uncropped maps
have mismatched shapes and DataLoader collation fails. Document that the weight
map is not cropped, and that w_key should be added to keys to obtain a cropped
weight map aligned with the image patches.

Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 91f92a7f-72cb-4528-9c54-a062dfe40653

📥 Commits

Reviewing files that changed from the base of the PR and between f6eadce and c319dec.

📒 Files selected for processing (1)
  • monai/transforms/croppad/dictionary.py
✅ Files skipped from review due to trivial changes (1)
  • monai/transforms/croppad/dictionary.py

📝 Walkthrough

Walkthrough

Two docstring-only updates: RandWeightedCrop in array.py now states that weight_map is only used to compute patch sampling locations and is not cropped. RandWeightedCropd in dictionary.py expands w_key to describe the expected single-channel weight map shape and how including w_key in keys affects cropping.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: clarifying RandWeightedCrop(d) weight-map behavior.
Description check ✅ Passed The description covers the issue, the behavior change, and the requested change type sections well enough.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@monai/transforms/croppad/dictionary.py`:
- Line 946: The docstring text in the cropping/padding dictionary transform uses
the incorrect phrase “in size” for the single-channel array description. Update
the wording in the relevant docstring near the transform documentation to say
“with shape” instead, matching the terminology used in the corresponding
array-based docs and keeping the phrasing consistent across the API.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b9f33917-1905-418f-a08d-a22874667456

📥 Commits

Reviewing files that changed from the base of the PR and between d6713fd and f6eadce.

📒 Files selected for processing (2)
  • monai/transforms/croppad/array.py
  • monai/transforms/croppad/dictionary.py

Comment thread monai/transforms/croppad/dictionary.py Outdated
Signed-off-by: Soumya Snigdha Kundu <soumya_snigdha.kundu@kcl.ac.uk>
@ericspod ericspod enabled auto-merge (squash) July 2, 2026 05:44
@ericspod ericspod merged commit f1dcac4 into Project-MONAI:dev Jul 2, 2026
21 checks passed
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

Successfully merging this pull request may close these issues.

2 participants