Skip to content

Fix #422: Added --fold argument and 5-fold cross-validation logic#428

Open
aman0311x wants to merge 2 commits into
Project-MONAI:mainfrom
aman0311x:fix-issue-422
Open

Fix #422: Added --fold argument and 5-fold cross-validation logic#428
aman0311x wants to merge 2 commits into
Project-MONAI:mainfrom
aman0311x:fix-issue-422

Conversation

@aman0311x

@aman0311x aman0311x commented Jul 12, 2026

Copy link
Copy Markdown

Description

This PR resolves issue #422. The repository mentioned using 5-fold cross-validation for the UNET/UNETR model on the BTCV dataset, but the --fold argument was missing in main.py and the cross-validation data splitting logic was unimplemented.

Changes Made

  • Added the --fold argument to the argument parser in main.py.
  • Implemented 5-fold cross-validation splitting using MONAI's partition_dataset in utils/data_utils.py based on the requested fold index.

Fixes #422

Summary by CodeRabbit

  • New Features

    • Added support for selecting one of five cross-validation folds through a command-line option.
    • Training and validation data are now automatically partitioned by the selected fold.
  • Bug Fixes

    • Improved dataset preparation to ensure the selected fold is used for validation while the remaining folds are used for training.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown

Walkthrough

The BTCV training command now accepts a fold index. The data loader partitions the full training datalist into five folds, uses the selected fold for validation, and builds the training dataset from the remaining folds.

Changes

BTCV cross-validation

Layer / File(s) Summary
Fold selection and dataset construction
UNETR/BTCV/main.py, UNETR/BTCV/utils/data_utils.py
Adds the --fold argument and uses the selected five-fold partition for validation while constructing training data from the other folds.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding --fold support and 5-fold cross-validation logic.
Linked Issues check ✅ Passed The PR addresses #422 by adding the missing --fold CLI option and implementing 5-fold dataset splitting for BTCV training.
Out of Scope Changes check ✅ Passed The changes stay focused on fold selection and cross-validation data loading, with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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

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 `@UNETR/BTCV/main.py`:
- Line 94: Update the --fold argument definition in the argument parser to
validate that values are within the documented inclusive range 0–4, causing
argparse to reject invalid input before execution reaches folds[args.fold] in
data_utils.py.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a1d77ad9-7e37-4ac6-8eb5-f98f9d273c63

📥 Commits

Reviewing files that changed from the base of the PR and between 21ed8e5 and 248c80a.

📒 Files selected for processing (2)
  • UNETR/BTCV/main.py
  • UNETR/BTCV/utils/data_utils.py

Comment thread UNETR/BTCV/main.py
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.

Five-fold cross-validation for the UNET model

1 participant