This repository contains a cleaned, GitHub-ready version of the exploratory CardiacDissect notebooks for MnM2 cardiac MRI slices.
The code supports two concept vocabularies:
original_3: original segmentation conceptsLV,MYO, andRV.derived_9: long-axis derived conceptsLV/MYO/RV x basal/mid/apical.
cardiacdissect/
analysis.py # DataLoader and full association-matrix pipeline
concepts.py # Original and derived concept-mask extraction
config.py # Config dataclass and YAML loader
dataset.py # MnM2 long-axis dataset loader
metrics.py # Mask resizing, patches, IoU/Dice/precision/recall
model.py # DenseNet checkpoint loading and activation hooks
visualization.py # Demo plots
notebooks/
demo_cardiacdissect.ipynb
tests/
test_*.py
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtCopy the example config and update the paths:
cp config.example.yaml config.yamlEdit config.yaml:
mnm2_root: "/absolute/path/to/MnM2"
model_path: "/absolute/path/to/best_densenet161_MnMs.pth"
concept_set: "derived_9"
layer: "features.denseblock4"The old notebooks hard-coded personal absolute paths. This refactor keeps paths out of the code and reads them from config instead.
Open:
notebooks/demo_cardiacdissect.ipynb
The notebook demonstrates:
- Loading config.
- Selecting
original_3orderived_9. - Loading DenseNet-161 and registering an activation hook.
- Loading LA MnM2 slices.
- Visualizing one sample and its concept masks.
- Ranking neuron-concept overlaps for one image.
- Optionally running the full association-matrix pipeline.
Set this in the notebook to choose the concept vocabulary:
CONCEPT_SET = "derived_9" # or "original_3"Set RUN_FULL_PIPELINE = True only when you want to process the full LA subset.