longitudinal/scripts_nnu/01_nnu_prepare_dataset.py
Furen Xiao 695bbb6e11 refactor(nnu): transition to native volume processing for Pipeline B
Update the nnU-Net pipeline to operate on native (unprocessed) volumes
instead of preprocessed ones. This allows nnU-Net to utilize its own
`plan_and_preprocess` logic for resampling, cropping, and normalization,
ensuring Pipeline B remains distinct from Pipelines A and C.

- Update `scripts/05_build_splits.py` to include native `img` and `label`
  paths in the manifest rows.
- Modify `scripts_nnu/01_nnu_prepare_dataset.py` to symlink native
  volumes and implement a label fix-up mechanism for non-conforming grids.
- Update `scripts_nnu/04_nnu_pseudo_label.py` and `05_nnu_eval_test.py`
  to use native image paths and perform selection/evaluation in physical
  mm on the native grid.
- Refactor `scripts_nnu/nnu_common.py` to handle native-grid label
  alignment and volume-based selection gates.
- Update `README.md` to document the preprocessing differences between
  Pipelines A/C and Pipeline B.
2026-09-26 12:44:40 +08:00

31 lines
No EOL
1.2 KiB
Python

"""Build/rebuild the nnU-Net raw dataset (Dataset210_NTUH_T1C_PL) from rows jsonl.
rows: {key, img, label} where img is the NATIVE (unprocessed) T1c nifti and
label a nifti mask on (or warpable to) that grid. No resampling/cropping/
normalization is applied here — nnUNetv2_plan_and_preprocess (02) does the
preprocessing; imagesTr entries are symlinks to the native volumes, labelsTr
entries are symlinks when already 0/1 on the image grid, else nearest-warped
+ binarized copies (label fix-up only).
Usage: python scripts_nnu/01_nnu_prepare_dataset.py --rows <rows.jsonl>
"""
import argparse
import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from src.common import load_jsonl
from nnu_common import make_raw_dataset, raw_ds
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--rows", required=True, help="jsonl with {key, img, label} (native paths)")
args = ap.parse_args()
rows = load_jsonl(args.rows)
n = make_raw_dataset(rows)
print(f"[nnu:prepare] {raw_ds()}: {n} cases", flush=True)
if __name__ == "__main__":
main()