Spaces:
Runtime error
Runtime error
Anirudh Balaraman commited on
Revise README for improved clarity and structure
Browse filesUpdated README to enhance clarity and organization, including changes to usage instructions and section headings.
README.md
CHANGED
|
@@ -29,7 +29,7 @@ Deep learning methods used in medical AIβparticularly for csPCa prediction and
|
|
| 29 |
- β‘ **Automatic Attention Heatmaps** - Weak attention heatmaps generated automatically from DWI and ADC sequnces.
|
| 30 |
- π§ **Weakly-Supervised Attention** β Heatmap-guided patch sampling and cosine-similarity attention loss, replace the need for voxel-level labels.
|
| 31 |
- π§© **3D Multiple Instance Learning** β Extracts volumetric patches from bpMRI scans and aggregates them via transformer + attention pooling.
|
| 32 |
-
- ποΈ **
|
| 33 |
- π§Ή **Preprocessing** β Preprocessing to minimize inter-center MRI acquisiton variability.
|
| 34 |
- π₯ **End-to-end Pipeline** β Open source, clinically viable complete pipeline.
|
| 35 |
|
|
@@ -52,32 +52,31 @@ curl -L -o models/file3.pth https://huggingface.co/anirudh0410/WSAttention-Prost
|
|
| 52 |
```
|
| 53 |
|
| 54 |
## π Usage
|
| 55 |
-
### Inference
|
| 56 |
```bash
|
| 57 |
python run_inference.py --config config/config_preprocess.yaml
|
| 58 |
```
|
| 59 |
|
| 60 |
Run run_inference.py to execute the full pipeline, from preprocessing to model predictions.
|
| 61 |
-
-
|
| 62 |
-
-
|
| 63 |
-
-
|
| 64 |
|
| 65 |
|
| 66 |
β οΈ ***NOTE: For each scan, all sequences should share the same filename, and the input files must be in NRRD format.***
|
| 67 |
|
| 68 |
- π **Outputs:**
|
| 69 |
The following are stored for each scan:
|
| 70 |
-
-
|
| 71 |
-
-
|
| 72 |
-
-
|
| 73 |
-
The results are stored in results.json saved in output_dir along with the intermediary files from pre processing including the prostate segmentation mask. The patches can be visualised using visualisation.ipynb
|
| 74 |
|
| 75 |
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
Execute preprocess_main.py to preprocess your MRI files. Each sequenceβT2W, DWI, and ADCβmust be placed in separate folders, with paths specified in config_preprocess.yaml.
|
| 81 |
```bash
|
| 82 |
python preprocess_main.py \
|
| 83 |
--steps register_and_crop get_segmentation_mask histogram_match get_heatmap \
|
|
@@ -85,23 +84,22 @@ python preprocess_main.py \
|
|
| 85 |
```
|
| 86 |
|
| 87 |
|
| 88 |
-
### PI-RADS Training
|
| 89 |
|
| 90 |
```bash
|
| 91 |
python run_pirads.py --mode train --config config/config_pirads_train.yaml
|
| 92 |
```
|
| 93 |
|
| 94 |
-
### csPCa Training
|
| 95 |
|
| 96 |
```bash
|
| 97 |
python run_cspca.py --mode train --config config/config_cspca_train.yaml
|
| 98 |
```
|
| 99 |
-
### Testing
|
| 100 |
|
| 101 |
```bash
|
| 102 |
python run_pirads.py --mode test --config config/config_pirads_test.yaml
|
| 103 |
python run_cspca.py --mode test --config config/config_cspca_test.yaml
|
| 104 |
-
python run_inference.py --config config/config_preprocess.yaml
|
| 105 |
```
|
| 106 |
|
| 107 |
See the [full documentation](https://anirudhbalaraman.github.io/WSAttention-Prostate/) for detailed configuration options and data format requirements.
|
|
@@ -117,35 +115,22 @@ WSAttention-Prostate/
|
|
| 117 |
βββ config/ # YAML configuration files
|
| 118 |
βββ src/
|
| 119 |
β βββ model/
|
| 120 |
-
β β βββ MIL.py # MILModel_3D β core MIL architecture
|
| 121 |
-
β β βββ csPCa_model.py # csPCa_Model
|
| 122 |
β βββ data/
|
| 123 |
β β βββ data_loader.py # MONAI data pipeline
|
| 124 |
-
β β βββ custom_transforms.py
|
| 125 |
β βββ train/
|
| 126 |
β β βββ train_pirads.py # PI-RADS training loop
|
| 127 |
β β βββ train_cspca.py # csPCa training loop
|
| 128 |
-
β βββ preprocessing/ # Registration, segmentation, heatmaps
|
| 129 |
-
β βββ utils.py # Shared utilities
|
| 130 |
βββ tests/
|
| 131 |
βββ dataset/ # Reference images for histogram matching
|
| 132 |
βββ models/ # Downloaded checkpoints (not in repo)
|
| 133 |
```
|
| 134 |
|
| 135 |
-
##
|
| 136 |
-
|
| 137 |
-
Input MRI patches are processed independently through a 3D ResNet18 backbone, then aggregated via a transformer encoder and attention pooling:
|
| 138 |
-
|
| 139 |
-
```mermaid
|
| 140 |
-
flowchart TD
|
| 141 |
-
A["Input [B, N, C, D, H, W]"] --> B["Reshape to [B*N, C, D, H, W]"]
|
| 142 |
-
B --> C[ResNet18-3D Backbone]
|
| 143 |
-
C --> D["Reshape to [B, N, 512]"]
|
| 144 |
-
D --> E[Transformer Encoder\n4 layers, 8 heads]
|
| 145 |
-
E --> F[Attention Pooling\n512 β 2048 β 1]
|
| 146 |
-
F --> G["Weighted Sum [B, 512]"]
|
| 147 |
-
G --> H["FC Head [B, num_classes]"]
|
| 148 |
-
```
|
| 149 |
|
| 150 |
-
For csPCa prediction, the backbone is frozen and a 3-layer MLP (`512 β 256 β 128 β 1`) replaces the classification head.
|
| 151 |
|
|
|
|
| 29 |
- β‘ **Automatic Attention Heatmaps** - Weak attention heatmaps generated automatically from DWI and ADC sequnces.
|
| 30 |
- π§ **Weakly-Supervised Attention** β Heatmap-guided patch sampling and cosine-similarity attention loss, replace the need for voxel-level labels.
|
| 31 |
- π§© **3D Multiple Instance Learning** β Extracts volumetric patches from bpMRI scans and aggregates them via transformer + attention pooling.
|
| 32 |
+
- ποΈ **Explainable** β Visualise salient patches highlighting probable tumour regions.
|
| 33 |
- π§Ή **Preprocessing** β Preprocessing to minimize inter-center MRI acquisiton variability.
|
| 34 |
- π₯ **End-to-end Pipeline** β Open source, clinically viable complete pipeline.
|
| 35 |
|
|
|
|
| 52 |
```
|
| 53 |
|
| 54 |
## π Usage
|
| 55 |
+
### π©Ί Inference
|
| 56 |
```bash
|
| 57 |
python run_inference.py --config config/config_preprocess.yaml
|
| 58 |
```
|
| 59 |
|
| 60 |
Run run_inference.py to execute the full pipeline, from preprocessing to model predictions.
|
| 61 |
+
- π **Input arguments:**
|
| 62 |
+
- *t2_dir, dwi_dir, adc_dir*: Path to T2W, DWI and ADC sequnces respectively.
|
| 63 |
+
- *output_dir*: Path to store preprocessed files and results.
|
| 64 |
|
| 65 |
|
| 66 |
β οΈ ***NOTE: For each scan, all sequences should share the same filename, and the input files must be in NRRD format.***
|
| 67 |
|
| 68 |
- π **Outputs:**
|
| 69 |
The following are stored for each scan:
|
| 70 |
+
- Risk of csPCa.
|
| 71 |
+
- PI-RADS score.
|
| 72 |
+
- Coordinaates of top 5 salient patches.
|
| 73 |
+
The results are stored in `results.json` saved in output_dir along with the intermediary files from pre processing including the prostate segmentation mask. The patches can be visualised using `visualisation.ipynb`
|
| 74 |
|
| 75 |
|
| 76 |
+
### π§Ή Preprocessing
|
| 77 |
|
| 78 |
+
Execute preprocess_main.py to preprocess your MRI files.
|
| 79 |
+
β οΈ ***NOTE: For each scan, all sequences should share the same filename, and the input files must be in NRRD format.***
|
|
|
|
|
|
|
| 80 |
```bash
|
| 81 |
python preprocess_main.py \
|
| 82 |
--steps register_and_crop get_segmentation_mask histogram_match get_heatmap \
|
|
|
|
| 84 |
```
|
| 85 |
|
| 86 |
|
| 87 |
+
### βοΈ PI-RADS Training
|
| 88 |
|
| 89 |
```bash
|
| 90 |
python run_pirads.py --mode train --config config/config_pirads_train.yaml
|
| 91 |
```
|
| 92 |
|
| 93 |
+
### βοΈ csPCa Training
|
| 94 |
|
| 95 |
```bash
|
| 96 |
python run_cspca.py --mode train --config config/config_cspca_train.yaml
|
| 97 |
```
|
| 98 |
+
### π Testing
|
| 99 |
|
| 100 |
```bash
|
| 101 |
python run_pirads.py --mode test --config config/config_pirads_test.yaml
|
| 102 |
python run_cspca.py --mode test --config config/config_cspca_test.yaml
|
|
|
|
| 103 |
```
|
| 104 |
|
| 105 |
See the [full documentation](https://anirudhbalaraman.github.io/WSAttention-Prostate/) for detailed configuration options and data format requirements.
|
|
|
|
| 115 |
βββ config/ # YAML configuration files
|
| 116 |
βββ src/
|
| 117 |
β βββ model/
|
| 118 |
+
β β βββ MIL.py # MILModel_3D β core MIL architecture, PI-RADS model
|
| 119 |
+
β β βββ csPCa_model.py # csPCa_Model
|
| 120 |
β βββ data/
|
| 121 |
β β βββ data_loader.py # MONAI data pipeline
|
| 122 |
+
β β βββ custom_transforms.py # Custom MONAI transforms
|
| 123 |
β βββ train/
|
| 124 |
β β βββ train_pirads.py # PI-RADS training loop
|
| 125 |
β β βββ train_cspca.py # csPCa training loop
|
| 126 |
+
β βββ preprocessing/ # Registration, segmentation, histogram matching, heatmaps
|
| 127 |
+
β βββ utils.py # Shared utilities
|
| 128 |
βββ tests/
|
| 129 |
βββ dataset/ # Reference images for histogram matching
|
| 130 |
βββ models/ # Downloaded checkpoints (not in repo)
|
| 131 |
```
|
| 132 |
|
| 133 |
+
## π Acknowledgement
|
| 134 |
+
This work was in large parts funded by the Wilhelm Sander Foundation. Funded by the European Union. Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union or European Health and Digital Executive Agency (HADEA). Neither the European Union nor the granting authority can be held responsible for them.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
|
|
|
| 136 |
|