Isotropic segmentation pipeline for MTL subregions from multi-modality 3T MRI
Project description
HyperResASHS
HyperResASHS is a deep learning pipeline for isotropic segmentation of medial temporal lobe (MTL) subregions from multi-modality 3T MRI (T1w and T2w). This repository implements the method described in our paper for achieving high-resolution, isotropic segmentation of brain structures.
Overview
This project addresses the challenge of segmenting MTL subregions from anisotropic MRI data by:
- Building an isotropic atlas using Implicit Neural Representations (INR)
- Training a multi-modality segmentation model with nnU-Net
- Performing inference on test data with automatic preprocessing
The pipeline handles the entire workflow from raw multi-modality MRI images to final segmentation results, including registration, ROI extraction, upsampling, and model inference.
Setup
Follow these steps to set up the repository in a fresh environment:
1. Create a Conda Environment
Create a new conda environment with Python 3.10 or higher:
conda create -n hyperresashs python=3.10
conda activate hyperresashs
2. Clone the Repository
Clone the repository with submodules:
git clone --recursive https://github.com/liyue3780/HyperResASHS.git
cd HyperResASHS
If you've already cloned without submodules, initialize them with:
git submodule update --init --recursive
3. Install Python Dependencies
Important: PyTorch version compatibility is critical. This pipeline requires PyTorch 2.5.x (tested with 2.5.1). Newer versions (e.g., 2.9) may cause compatibility issues.
# First, install PyTorch with CUDA support (adjust CUDA version as needed)
# For CUDA 11.8:
pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu118
# For CPU only:
# pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1
# Then install the package and remaining dependencies
pip install -e .
Note: Additional dependencies may be required by the submodules. See the submodule setup instructions below.
4. Set Up Submodules
This repository uses git submodules for dependencies:
submodules/multi_contrast_inr: INR repository (trackingmainbranch)submodules/nnUNet: Modified nnUNet repository (trackingmmsegbranch) - https://github.com/liyue3780/nnUNet/tree/mmseg
Install nnUNet submodule:
This step is only needed if you will be training new HyperResASHS models. For inference, it is not necessary.
cd submodules/nnUNet
pip install -e .
cd ../..
Set nnU-Net Environment Variables:
After installing nnUNet, you must set the following environment variables:
export nnUNet_raw="/path/to/nnUNet_raw"
export nnUNet_preprocessed="/path/to/nnUNet_preprocessed"
export nnUNet_results="/path/to/nnUNet_results"
For detailed setup instructions (including Linux, MacOS, and Windows), see the nnU-Net environment variables documentation.
Install INR submodule dependencies:
This step is only needed if you will be training new HyperResASHS models. For inference, it is not necessary.
pip install tensorboard==2.20.0 lpips==0.1.4
Refer to the INR repository's documentation for specific installation requirements. The INR submodule may require additional dependencies such as PyTorch, nibabel, and other packages.
Note: The modified nnUNet includes Modality Augmentation methods for multi-modality brain MRI segmentation. Make sure to use the mmseg branch when running nnU-Net training.
6. Verify Installation
Verify that the main pipeline can be imported:
python -c "from hyperresashs.preprocessing import PreprocessorInVivo; from hyperresashs.testing import ModelTester; from hyperresashs.prepare_inr import INRPreprocess; print('Installation successful!')"
Configuration
For detailed configuration information, including config file format and cross-validation file format, see Configuration Guide.
Pipeline Details
The pipeline consists of six main steps that can be run in linear order. Each step assumes the previous steps have been completed:
- Prepare → 2. Prepare INR → 3. Run INR Upsampling → 4. Preprocess → 5. Train → 6. Test
Note: Steps 2-3 are only needed if using INR upsampling. For other upsampling methods (e.g., GreedyUpsampling or None), you can skip Steps 2-3 and go directly from Step 1 to Step 4.
Step 1: Prepare Patch Data (stage = prepare)
Run this step first to create the experiment folder by copying images and segmentations from the two atlas folders (T1w and T2w ASHS atlases). This step:
- Copies primary and secondary modality images from ASHS packages
- Copies segmentation files
- Performs coordinate system transformations (swapdim RPI)
- Creates the folder structure in
{PREPARE_RAW_PATH}/{EXP_NUM}{MODEL_NAME}/images/
Usage:
python main.py -s prepare -c {CONFIG_ID}
Step 2: Prepare INR Data (stage = prepare_inr)
This step prepares the data for INR upsampling. It requires the prepared patch data from Step 1. The prepare_inr stage will:
- Prepare the data in the format expected by the INR submodule
- Generate INR configuration files for each case
- Create a shell script
shell/run_inr_upsampling_{EXP_NUM}{MODEL_NAME}.shwith paths automatically filled from your config
Usage:
python main.py -s prepare_inr -c {CONFIG_ID}
Folder structure created:
The prepare_inr stage creates the following folder structure under {INR_PATH}/{EXP_NUM}{MODEL_NAME}/:
preprocess/: Contains case folders with input data and config files for INRtraining_preparation/: Contains case folders with prepared data ready for INR trainingtraining_output/: Will contain INR training outputs (created after INR training completes)
Step 3: Run INR Upsampling (stage = run_inr)
After preparing INR data, you have two options to run INR upsampling:
Option 1: Run via Python (Recommended for single GPU)
Run INR upsampling directly using Python:
python main.py -s run_inr -c {CONFIG_ID}
This will process all cases sequentially. The script automatically:
- Finds all cases in the
training_preparationfolder (created in Step 2) - Runs INR training for each case using the generated config files from the
preprocessfolder
Option 2: Run via Shell Script (Recommended for multi-GPU)
For multi-GPU setups, you can use the generated shell script and modify it to run different batches on different GPUs. See INR Upsampling Shell Script Guide for detailed instructions.
Step 4: Complete Preprocessing (stage = preprocess)
After INR upsampling is finished, run the preprocessing stage to complete all remaining steps. This step assumes the patch data preparation (Step 1) was already completed. It will:
- Copy INR upsampled results (if using INR upsampling method)
- Perform resampling/upsampling based on the configured method
- Register secondary modality (T1w) to primary (T2w)
- Prepare nnU-Net dataset
- Remove outer segmentation artifacts
- Convert labels to continuous format
- Create cross-validation splits
- Run nnU-Net experiment planning
- Generate nnU-Net training script:
shell/train_nnunet_{EXP_NUM}{MODEL_NAME}.sh
Usage:
python main.py -s preprocess -c {CONFIG_ID}
Outputs from Step 4:
- nnU-Net dataset in
{NNUNET_RAW_PATH}/Dataset{EXP_NUM}_{MODEL_NAME}/ - Preprocessed data in
{NNUNET_RAW_PATH}/../nnUNet_preprocessed/Dataset{EXP_NUM}_{MODEL_NAME}/ - Cross-validation splits file:
splits_final.json - Training script:
shell/train_nnunet_{EXP_NUM}{MODEL_NAME}.sh
Note: If you're using a non-INR upsampling method (e.g., GreedyUpsampling or None), you can skip Steps 2-3 and go directly from Step 1 to Step 4.
Step 5: nnU-Net Training (stage = train)
Step 4 creates the nnU-Net dataset, runs experiment planning, and creates five-fold cross-validation splits. A training script is automatically generated for convenience.
You have two options to run nnU-Net training:
Option 1: Run via Python (Recommended)
Run nnU-Net training directly using Python:
python main.py -s train -c {CONFIG_ID}
This will train all 5 folds (fold 0-4) sequentially using the TRAINER specified in your configuration file (e.g., ModAugUNetTrainer).
Note: Ensure you're using the modified nnUNet from submodules/nnUNet (mmseg branch) which includes Modality Augmentation methods. The nnUNetv2_train command should be available after installing the modified nnUNet.
Option 2: Run via Shell Script
Alternatively, you can run the generated training script manually. See nnU-Net Training Shell Script Guide for detailed instructions.
Step 6: Testing (stage = test)
Testing is independent from Steps 1-5 and uses its own configuration files in the config_test/ directory. Each test configuration has its own ID that links to a trained model.
Test Configuration ID Convention:
- The test config ID links to the training model ID. For example:
2921links to model292(the1represents the first test set)2922,2923,2924, etc. can be used for different test sets of the same model
- The first digits match the
EXP_NUMof the trained model you want to use
Usage:
python main.py -s test -c {TEST_CONFIG_ID}
# For example: python main.py -s test -c 2921
Configuration Requirements:
EXP_NUM: Must match the training model'sEXP_NUM(e.g.,292)MODEL_NAME: Must match the training model'sMODEL_NAME(e.g.,TestPipeline)TRAINER: Must match the training model'sTRAINERCONDITION: Must match the training model'sCONDITION(e.g.,in_vivo)UPSAMPLING_METHOD: Must match the training model'sUPSAMPLING_METHODTEST_PATH: Path to test data (see Configuration Guide for structure)TEMPLATE_PATH: Path to ASHS template for MTL ROI cropping (downloadable from DOI: 10.5061/dryad.k6djh9wmn)
This stage performs:
- Whole-brain registration (T1w to T2w)
- ROI extraction using ASHS template
- Patch cropping and upsampling
- Local registration for fine alignment
- nnU-Net inference for segmentation
- Output of segmentation results
For detailed test configuration information, see Configuration Guide.
Citation
If you use this code in your research, please cite our paper:
@article{hyperresashs2024,
title={HyperResASHS: Isotropic Segmentation of MTL Subregions from Multi-modality 3T MRI},
author={[Authors]},
journal={arXiv preprint arXiv:2508.17171},
year={2024},
url={https://doi.org/10.48550/arXiv.2508.17171}
}
Changelog
01/14/2026
- Replaced
trim_neck.shshell script with Python implementation usingpicsl_c3dpackage - Removed ITK-SNAP installation requirement (no longer needed)
- Updated
multi_contrast_inrsubmodule to latest version - Modified
--config_idargument to accept both integer ID and full file path - Added config validation checks: ID consistency, conflict detection, and nnUNet dataset existence
- Made
FILE_NAME_CONFIGoptional with automatic defaults based on stage (test vs. other stages) - Renamed
scripts/folder toshell/for better clarity - Added optional
--subject_idargument for test stage to test specific subjects - Updated
.gitignoreto exclude generated config and script files while keeping template files tracked - Fixed config validation to skip checks when stage is
test
01/07/2026
- Added
requirements.txtandsetup.pywith pinned package versions for reproducible installation - Added nnU-Net environment variables setup instructions
- Added Python stages for INR upsampling (
stage = run_inr) and nnU-Net training (stage = train) - Created comprehensive documentation in
docs/folder:- Configuration guide with training and test config details
- INR upsampling shell script guide
- nnU-Net training shell script guide
- Updated README to reference documentation files for better organization
- Added
trim_neck.shscript for neck trimming - Updated testing documentation with config_test details and test data structure
- Changed default pipeline stage from
prepare_inrtoprepare
01/04/2026
- Refactored pipeline to support linear execution order
- Added separate
preparestage for patch data preparation - Simplified
execute()method in preprocessing to remove conditional checks - Updated pipeline documentation to reflect linear execution flow
- Added
.gitignoreto exclude Python cache files and build artifacts
12/24/2025
- Added INR and modified nnUNet as git submodules
- Added INR preparation module with config generation
- Added INR upsampling script template and generation
- Added nnUNet training script template and generation
- Updated README with submodule setup and pipeline documentation
12/22/2025
- Updated README.md with comprehensive documentation
- Added data structure documentation slots for atlas and test data
11/20/2025
- Added main pipeline of preprocessing
10/27/2025
- Initial release of isotropic segmentation pipeline for MTL subregions
- Support for 3T-T2w and 3T-T1w multi-modality MRI
Contact
For questions or support, please open an issue or contact liyue3780@gmail.com.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hyperresashs-1.0.2.tar.gz.
File metadata
- Download URL: hyperresashs-1.0.2.tar.gz
- Upload date:
- Size: 65.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd83433551165c451b0513876eae75828aac229bae68d4dd90c413c04465cfaf
|
|
| MD5 |
b34bc05318986c1a9f7262eddbac42e7
|
|
| BLAKE2b-256 |
babc142afb79d95bd74fcc06324fa602c15c48a336d55e4fb74412eae01e2b49
|
Provenance
The following attestation bundles were made for hyperresashs-1.0.2.tar.gz:
Publisher:
python-publish.yml on pyushkevich/HyperResASHS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyperresashs-1.0.2.tar.gz -
Subject digest:
cd83433551165c451b0513876eae75828aac229bae68d4dd90c413c04465cfaf - Sigstore transparency entry: 1090842928
- Sigstore integration time:
-
Permalink:
pyushkevich/HyperResASHS@8b989c8856747a806b4892828dc9daf3889bfa6e -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/pyushkevich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8b989c8856747a806b4892828dc9daf3889bfa6e -
Trigger Event:
release
-
Statement type:
File details
Details for the file hyperresashs-1.0.2-py3-none-any.whl.
File metadata
- Download URL: hyperresashs-1.0.2-py3-none-any.whl
- Upload date:
- Size: 69.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6584616ca940956b76316a1fbcd21050f26afd8195575a2331251709ad705bc5
|
|
| MD5 |
3277fd21be4c7b21bfcf8a987b011e10
|
|
| BLAKE2b-256 |
ac2b66add4899000f144ba9c187491f1f1c2de1e258a06b4289609af8116c088
|
Provenance
The following attestation bundles were made for hyperresashs-1.0.2-py3-none-any.whl:
Publisher:
python-publish.yml on pyushkevich/HyperResASHS
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyperresashs-1.0.2-py3-none-any.whl -
Subject digest:
6584616ca940956b76316a1fbcd21050f26afd8195575a2331251709ad705bc5 - Sigstore transparency entry: 1090842959
- Sigstore integration time:
-
Permalink:
pyushkevich/HyperResASHS@8b989c8856747a806b4892828dc9daf3889bfa6e -
Branch / Tag:
refs/tags/v1.0.2 - Owner: https://github.com/pyushkevich
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8b989c8856747a806b4892828dc9daf3889bfa6e -
Trigger Event:
release
-
Statement type: