How aim-kannlab/itmt works
Project type and purpose
• This is an academic/research-oriented deep learning pipeline (“Automated Deep Learning TM-segmentation project”) for measuring temporalis muscle thickness (iTMT) from brain MRIs.
• It includes data curation, preprocessing (registration + normalization), two ML models (slice selection via DenseNet, segmentation via U-Net), post-processing (CSA/TMT computation), centile-curve generation (R scripts), and deployment via Docker or Conda.
High-level architectural overview
The system can be viewed as the following layers/components:
A. Data Ingestion & Curation
B. Preprocessing
C. Model Training & Evaluation
D. Inference Pipeline (Single-MRI)
E. Post-processing & Analytics
F. Centile Generation & Visualization
G. Deployment & Packaging
Component breakdown from the file tree
A. Data Ingestion & Curation
• Directory: data_curation_scripts/
• curate_*.py scripts for assembling MRI datasets by study/cohort
• dicoms_to_nii.py, extractor.py, extract_tgz.py for raw data conversion
• human_validator/ for manual QC pipelines
B. Preprocessing
• Directories: preprocessing/, docker/preprocessing/
• registration_mni.py (Elastix CLI integration for age-matched MNI registration)
• sitk_resample.py (SimpleITK resampling for DenseNet input)
• masks_to_npy.py (generates image+mask .npy for U-Net)
• scripts/preprocess_utils.py orchestrates bulk z-normalization and bias correction
C. Model Training & Evaluation
• Top-level scripts: train_slice_selection.py, test_slice_selection.py
• Top-level scripts: train_segmentation.py, test_segmentation.py
• model/densenet_models/ and model/unet_models/ hold saved weights & test harnesses
• scripts/ contains network definitions (densenet_regression.py, unet.py), generators, loss functions
D. Inference Pipeline (Single-MRI)
• docker/main.py + docker/predict.py orchestrate:
1. Input .nii through mounted volume
2. Preprocessing → slice selection → segmentation
3. TM metrics computation
4. Output .csv and registered images
• compute_population_pred.py for batch inference outside Docker
E. Post-processing & Analytics
• Python: scripts/measure_head_crm.py, generate_pseudolabels.py
• Centile computation in R: R_scripts/centile_curves_*.R
F. Centile Generation & Visualization
• R_scrips/ for generating growth charts (sex-specific percentiles)
• shared_data/percentiles_chart_*.csv used by web front-end
G. Deployment & Packaging
• Dockerfile + .dockerignore in docker/ for single-MRI inference container
• environment.yml and settings.py for Conda-based workflows
• example_notebooks/ and itmt_v2/ contain demo Jupyter pipelines and extended curation
Relationships & Data Flow
• Raw MRI sources → Data Curation → Clean NIfTI
↓
• Preprocessing (registration → normalization → format conversion)
↓
• Two parallel ML pipelines:
• DenseNet slice selection → selected slice index
• U-Net segmentation → binary mask
↓
• Post-processing: compute TMT/CSA from mask + slice index
↓
• Store intermediate results (.npy, .nii, .csv) in output/ or shared_data/
↓
• R scripts consume metrics CSV → generate centile curves & charts
↓
• Streamlit web app (external) reads charts + percentiles for visualization
Architectural patterns & principles
• Modular pipeline stages: clear separation of curation, preprocessing, modeling, post-processing
• Reproducible environments: Docker container or Conda + YAML
• “Script-oriented” orchestration rather than monolithic codebase
• Data artifacts checkpointed on disk between stages for speed and reusability
• Clear labels: e.g., “Registration Service (Elastix CLI)”