prost-softnet 1.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. prost_softnet-1.2.1/LICENSE +21 -0
  2. prost_softnet-1.2.1/PKG-INFO +301 -0
  3. prost_softnet-1.2.1/README.md +216 -0
  4. prost_softnet-1.2.1/prost_softnet.egg-info/PKG-INFO +301 -0
  5. prost_softnet-1.2.1/prost_softnet.egg-info/SOURCES.txt +33 -0
  6. prost_softnet-1.2.1/prost_softnet.egg-info/dependency_links.txt +1 -0
  7. prost_softnet-1.2.1/prost_softnet.egg-info/entry_points.txt +5 -0
  8. prost_softnet-1.2.1/prost_softnet.egg-info/requires.txt +40 -0
  9. prost_softnet-1.2.1/prost_softnet.egg-info/top_level.txt +1 -0
  10. prost_softnet-1.2.1/prostsoftnet/__init__.py +33 -0
  11. prost_softnet-1.2.1/prostsoftnet/cli.py +219 -0
  12. prost_softnet-1.2.1/prostsoftnet/data/__init__.py +26 -0
  13. prost_softnet-1.2.1/prostsoftnet/data/augmentation.py +50 -0
  14. prost_softnet-1.2.1/prostsoftnet/data/preprocessing.py +170 -0
  15. prost_softnet-1.2.1/prostsoftnet/data/prostate158.py +220 -0
  16. prost_softnet-1.2.1/prostsoftnet/models/__init__.py +5 -0
  17. prost_softnet-1.2.1/prostsoftnet/models/hybrid.py +342 -0
  18. prost_softnet-1.2.1/prostsoftnet/models/losses.py +89 -0
  19. prost_softnet-1.2.1/prostsoftnet/training/__init__.py +6 -0
  20. prost_softnet-1.2.1/prostsoftnet/training/evaluate.py +132 -0
  21. prost_softnet-1.2.1/prostsoftnet/training/trainer.py +210 -0
  22. prost_softnet-1.2.1/prostsoftnet/utils/__init__.py +14 -0
  23. prost_softnet-1.2.1/prostsoftnet/utils/gradcam.py +186 -0
  24. prost_softnet-1.2.1/prostsoftnet/utils/metrics.py +117 -0
  25. prost_softnet-1.2.1/prostsoftnet/utils/visualization.py +171 -0
  26. prost_softnet-1.2.1/pyproject.toml +146 -0
  27. prost_softnet-1.2.1/setup.cfg +4 -0
  28. prost_softnet-1.2.1/tests/test_cli.py +163 -0
  29. prost_softnet-1.2.1/tests/test_demo_server.py +191 -0
  30. prost_softnet-1.2.1/tests/test_gradcam.py +40 -0
  31. prost_softnet-1.2.1/tests/test_metrics.py +73 -0
  32. prost_softnet-1.2.1/tests/test_model.py +96 -0
  33. prost_softnet-1.2.1/tests/test_preprocessing.py +119 -0
  34. prost_softnet-1.2.1/tests/test_wgcgpz_inference.py +177 -0
  35. prost_softnet-1.2.1/tests/test_zone_pipeline.py +203 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Saqib Iqbal and Muhammad Tausif
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,301 @@
1
+ Metadata-Version: 2.4
2
+ Name: prost-softnet
3
+ Version: 1.2.1
4
+ Summary: Reproducible cascade-CNN software for prostate MRI zonal segmentation (whole gland / central gland / peripheral zone)
5
+ Author: Ghzanfar Farooq Saddiqui, Muhammad Zafar Iqbal
6
+ Author-email: Saqib Iqbal <saqibiqbal@cs.qau.edu.pk>, Muhammad Tausif <tausifasia@gmail.com>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2026 Saqib Iqbal and Muhammad Tausif
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/ProST-SoftNet/ProST-SoftNet-v2
30
+ Project-URL: Documentation, https://github.com/ProST-SoftNet/ProST-SoftNet-v2#readme
31
+ Project-URL: Repository, https://github.com/ProST-SoftNet/ProST-SoftNet-v2
32
+ Project-URL: Issues, https://github.com/ProST-SoftNet/ProST-SoftNet-v2/issues
33
+ Project-URL: Demo, https://huggingface.co/spaces/ProST-SoftNet/ProST-SoftNet
34
+ Keywords: prostate cancer,MRI,deep learning,vision transformer,medical imaging
35
+ Classifier: Development Status :: 4 - Beta
36
+ Classifier: Intended Audience :: Science/Research
37
+ Classifier: Intended Audience :: Healthcare Industry
38
+ Classifier: License :: OSI Approved :: MIT License
39
+ Classifier: Programming Language :: Python :: 3
40
+ Classifier: Programming Language :: Python :: 3.10
41
+ Classifier: Programming Language :: Python :: 3.11
42
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
43
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
44
+ Requires-Python: >=3.10
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE
47
+ Requires-Dist: torch>=2.2.0
48
+ Requires-Dist: torchvision>=0.17.0
49
+ Requires-Dist: timm>=0.9.12
50
+ Requires-Dist: einops>=0.7.0
51
+ Requires-Dist: numpy>=1.26.0
52
+ Requires-Dist: pandas>=2.2.0
53
+ Requires-Dist: scikit-learn>=1.4.0
54
+ Requires-Dist: scikit-image>=0.22.0
55
+ Requires-Dist: albumentations>=1.4.0
56
+ Requires-Dist: SimpleITK>=2.3.1
57
+ Requires-Dist: nibabel>=5.2.0
58
+ Requires-Dist: pydicom>=2.4.4
59
+ Requires-Dist: Pillow>=10.2.0
60
+ Requires-Dist: opencv-python-headless>=4.9.0
61
+ Requires-Dist: tqdm>=4.66.0
62
+ Requires-Dist: pyyaml>=6.0.1
63
+ Requires-Dist: omegaconf>=2.3.0
64
+ Requires-Dist: matplotlib>=3.8.0
65
+ Requires-Dist: seaborn>=0.13.0
66
+ Requires-Dist: scipy>=1.12.0
67
+ Requires-Dist: grad-cam>=1.4.8
68
+ Requires-Dist: onnx>=1.16.0
69
+ Requires-Dist: onnxruntime>=1.17.0
70
+ Provides-Extra: dev
71
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
72
+ Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
73
+ Requires-Dist: black>=24.0.0; extra == "dev"
74
+ Requires-Dist: ruff>=0.3.0; extra == "dev"
75
+ Requires-Dist: fastapi>=0.111.0; extra == "dev"
76
+ Requires-Dist: httpx>=0.27.0; extra == "dev"
77
+ Provides-Extra: train
78
+ Requires-Dist: wandb>=0.16.0; extra == "train"
79
+ Requires-Dist: tensorboard>=2.16.0; extra == "train"
80
+ Requires-Dist: lightning>=2.2.0; extra == "train"
81
+ Provides-Extra: notebook
82
+ Requires-Dist: jupyter>=1.0.0; extra == "notebook"
83
+ Requires-Dist: ipywidgets>=8.0.0; extra == "notebook"
84
+ Dynamic: license-file
85
+
86
+ # ProST-SoftNet
87
+
88
+ **Reproducible cascade-CNN software for prostate MRI zonal segmentation (whole gland / central gland / peripheral zone)**
89
+
90
+ [![CI](https://github.com/ProST-SoftNet/ProST-SoftNet-v2/actions/workflows/ci.yml/badge.svg)](https://github.com/ProST-SoftNet/ProST-SoftNet-v2/actions)
91
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
92
+
93
+ *PyPI package and Zenodo DOI are not live yet — see [Status](#status) below before citing this work.*
94
+
95
+ ---
96
+
97
+ ProST-SoftNet segments the prostate into **whole gland (WG)**, **central gland (CG)**, and **peripheral zone (PZ)** from multi-parametric MRI, using a cascade 3-D CNN pipeline built around [Prostate158](https://github.com/kbressem/prostate158) — the public benchmark of 158 prostate MRI exams with expert zonal and lesion annotations ([Zenodo archive, DOI 10.5281/zenodo.6481141](https://zenodo.org/record/6481141)).
98
+
99
+ On the held-out 19-case test split, the pipeline reaches a **peripheral-zone Dice of 0.7513 — above the 0.7473 human inter-reader agreement measured on the same data.** The peripheral zone is the hardest of the three to segment and the region where most clinically significant prostate cancers arise, so it is reported separately rather than averaged away. Full results are in [Zone-Segmentation Results](#zone-segmentation-results).
100
+
101
+ Every trained checkpoint, per-iteration ablation log, and per-case metric CSV is committed to this repository rather than described from the outside, so the numbers here can be recomputed and checked directly rather than taken on faith. An interactive dashboard ([`demo/`](demo/)) lets you browse the results or upload a new patient's MRI and run the pipeline yourself.
102
+
103
+ The repository also ships `prostsoftnet`, a pip-installable hybrid **CNN-ViT** classifier for benign/malignant prediction with Grad-CAM/Attention-Rollout explainability and ONNX export. It is complete and unit-tested, but **has not been trained to completion on Prostate158 and carries no benchmark results** — it is included as reusable, extensible architecture, not as a validated classifier. See [Status](#status).
104
+
105
+ ## What's in this repo
106
+
107
+ | Area | Where | What it is |
108
+ |---|---|---|
109
+ | **Zone-segmentation pipeline** *(the primary contribution)* | [`checkpoints/prost_fusenet_optimal/`](checkpoints/prost_fusenet_optimal/) | Cascade 3-D CNN (frozen whole-gland localizer → cropped zone refinement), multiple training iterations with committed results and per-case metrics, tracked via Git LFS |
110
+ | Classification package *(not benchmarked)* | [`prostsoftnet/`](prostsoftnet/) | Hybrid CNN-ViT (EfficientNetV2-S + ViT + cross-attention) for benign/malignant classification — data loading, training, metrics, explainability, ONNX export. Complete and unit-tested; **no trained checkpoint or benchmark results** |
111
+ | Interactive dashboard | [`demo/`](demo/) | FastAPI server + static frontend: pre-generated segmentation results, ROC/PR/training curves, and a live tab to upload a new patient's MRI and run the pipeline |
112
+ | Full-stack web app | [`web-app/`](web-app/), [`php-api/`](php-api/), [`ml-api/`](ml-api/) | React + PHP/MySQL + FastAPI application wrapping the classification model for doctor-facing use |
113
+ | HuggingFace Spaces demo | [`hf_spaces/`](hf_spaces/) | Gradio app for the zonal-segmentation pipeline, built and locally verified — pending PRO-tier compute to deploy live, see [Status](#status). A static landing page is live at [huggingface.co/spaces/MuhammadTausif/prost-softnet-v2-demo](https://huggingface.co/spaces/MuhammadTausif/prost-softnet-v2-demo) in the meantime. |
114
+ | Illustrative notebooks | [`notebooks/`](notebooks/) | Data preparation, training/evaluation, and inference/explainability — executed end to end on every CI run, not just committed as static files |
115
+
116
+ ---
117
+
118
+ ## Status
119
+
120
+ Being upfront about what's real right now, rather than what the badges of a finished project usually imply:
121
+
122
+ - **Working and benchmarked**: the zone-segmentation pipeline — its checkpoints and reported metrics (recomputed from the committed per-case CSVs, not hand-typed), the dashboard, and the 61-test suite covering both the segmentation pipeline and the classification package.
123
+ - **Complete but not benchmarked**: the `prostsoftnet` classification package. Its training, evaluation, and explainability code is finished and unit-tested, but it **has never been run to completion on the full Prostate158 dataset**, so no trained checkpoint and no accuracy numbers exist. It is shipped as reusable architecture, and this README does not report classification results because there are none to report.
124
+ - **Not yet done**: the package is not yet published to PyPI; no Zenodo DOI has been minted for this repository; the interactive HuggingFace Spaces demo (live per-patient inference) is built and passes an end-to-end smoke test locally, but is not yet deployed live — HuggingFace's free tier stopped hosting Gradio/Docker Spaces on CPU compute, which now requires a PRO subscription. A static landing page (results table + links, no live inference) is deployed at [huggingface.co/spaces/MuhammadTausif/prost-softnet-v2-demo](https://huggingface.co/spaces/MuhammadTausif/prost-softnet-v2-demo) in the meantime.
125
+ - **Repository visibility**: this repository is currently private to the ProST-SoftNet organization while the above items are finished. It will be made public before submission, per the venue's requirement that the code be openly accessible.
126
+
127
+ ---
128
+
129
+ ## Zone-Segmentation Results
130
+
131
+ Held-out test split of Prostate158 (19 cases). The pipeline runs in two stages: a frozen Stage-A localizer finds the gland bounding box, then a Stage-B 3-D U-Net segments WG and CG at native crop resolution; PZ is derived as `WG AND NOT CG`.
132
+
133
+ | Model | WG Dice | CG Dice | PZ Dice | Zone-mean Dice |
134
+ |---|---|---|---|---|
135
+ | Cascade-CNN, direct 3-class (`iter15`) | 0.8941 | 0.8642 | 0.7308 | 0.7975 |
136
+ | **Cascade-CNN, PZ-derived (`iter18`) — current best** | **0.8926** | **0.8676** | **0.7483** | **0.8079** |
137
+ | Confidence-weighted fusion of iter18 + iter29, no extra training (`iter30`) | 0.8910 | 0.8619 | 0.7513 | 0.8066 |
138
+ | Human inter-reader agreement (reference ceiling) | — | 0.8726 | 0.7473 | — |
139
+
140
+ `iter18` is the checkpoint the dashboard's live "Zonal Analysis" tab runs. The peripheral zone is the hardest of the three by a wide margin — it's small, has a less distinct boundary on T2W, and is exactly where most clinically significant cancers arise, so tracking it separately from whole-gland Dice matters more than a single averaged number would suggest. Full iteration-by-iteration history, what changed between each one, and why some approaches didn't help are documented in [`checkpoints/prost_fusenet_optimal/README.md`](checkpoints/prost_fusenet_optimal/README.md).
141
+
142
+ ### A note on the classification package
143
+
144
+ The `prostsoftnet` classifier is **deliberately not benchmarked here.** Its training, evaluation, and explainability code is complete and unit-tested, but it has never been run to completion on the full Prostate158 dataset — so no trained checkpoint exists and there are no accuracy numbers to report. Rather than publish a hastily-trained figure, this repository reports only what it can substantiate: the zone-segmentation results above.
145
+
146
+ The package remains fully usable for anyone who wants to train it themselves — see [`docs/classification-package.md`](docs/classification-package.md) — and `prost-evaluate` will produce the standard clinical metrics (AUROC, sensitivity, specificity, PPV, NPV with bootstrap confidence intervals) once a checkpoint exists.
147
+
148
+ ---
149
+
150
+ ## Try the dashboard
151
+
152
+ No GPU needed to browse the pre-generated results; the live "Zonal Analysis" tab needs the trained checkpoints already present in `checkpoints/prost_fusenet_optimal/`.
153
+
154
+ ```bash
155
+ cd demo
156
+ pip install -r requirements.txt
157
+ python server.py
158
+ # open http://localhost:8000
159
+ ```
160
+
161
+ The dashboard opens on the zone-segmentation model comparison and statistics tabs. A third tab accepts a new patient's T2W/DWI/ADC MRI — NIfTI or a DICOM series as a ZIP — runs the cascade pipeline on it, and returns WG/CG/PZ volumes, overlay figures, and a plain-language, explicitly non-diagnostic description grounded in a small retrieval-augmented knowledge base (PI-RADS anatomy references, not a diagnosis).
162
+
163
+ ### Zone-Segmentation Models
164
+
165
+ Side-by-side test-set metrics for each trained checkpoint, per-zone ASD/HD95 distance metrics, and pre-generated ground-truth-vs-prediction overlays for individual test cases.
166
+
167
+ ![Zone-Segmentation Models tab: metrics comparison table, distance metrics, and a ground-truth vs prediction overlay for one test case](https://raw.githubusercontent.com/ProST-SoftNet/ProST-SoftNet-v2/master/docs/images/dashboard-zone-models.png)
168
+
169
+ ### Zone Statistics
170
+
171
+ Whole-gland segmentation compared against ground truth on real T2W and DWI slices (red = ground truth, yellow = prediction, green = overlap), per-model Dice/IoU/precision/recall, voxel-level ROC and precision-recall curves computed from raw per-voxel probabilities across all 19 test cases, and training history.
172
+
173
+ ![Zone Statistics tab: T2W and DWI overlays comparing ground truth against both models, per-model gland metrics, ROC and precision-recall curves, and training loss and validation Dice curves](https://raw.githubusercontent.com/ProST-SoftNet/ProST-SoftNet-v2/master/docs/images/dashboard-zone-statistics.png)
174
+
175
+ ---
176
+
177
+ ## Installation
178
+
179
+ ```bash
180
+ git clone https://github.com/ProST-SoftNet/ProST-SoftNet-v2.git
181
+ cd ProST-SoftNet-v2
182
+ pip install -e ".[dev,train,notebook]"
183
+ ```
184
+
185
+ Not yet on PyPI (see [Status](#status)) — install from source for now.
186
+
187
+ **Requirements**: Python 3.10 or newer, PyTorch 2.2+, CUDA 11.8+ recommended for training (CPU works for inference and for browsing the dashboard).
188
+
189
+ ---
190
+
191
+ ## The `prostsoftnet` classification package
192
+
193
+ Alongside the segmentation pipeline, this repository ships a pip-installable hybrid **CNN-ViT** classifier (EfficientNetV2-S + 6-layer ViT + cross-attention fusion) for benign/malignant prediction, with Grad-CAM and Attention-Rollout explainability, ONNX export, and a CLI (`prost-train`, `prost-evaluate`, `prost-predict`, `prost-export`).
194
+
195
+ As noted in [Status](#status), it has **not been trained to completion and carries no benchmark results** — it is included as reusable, extensible architecture rather than as a validated classifier.
196
+
197
+ **Full architecture description, quick start, training/evaluation/inference commands, and explainability API: [`docs/classification-package.md`](docs/classification-package.md).**
198
+
199
+ ---
200
+
201
+ ## Tests and illustrative examples
202
+
203
+ ```bash
204
+ pytest tests/
205
+ ```
206
+
207
+ 105 tests pass in a clean environment, covering each part of the software in turn:
208
+
209
+ | Area | Tests | What they check |
210
+ |---|---|---|
211
+ | Zone-segmentation pipeline | 29 | Model architectures, confidence-weighted fusion, and an end-to-end run of the full pipeline against the real trained checkpoints |
212
+ | Dashboard HTTP API | 22 | Every route group, query-parameter validation, and that malformed uploads are refused rather than reaching inference |
213
+ | Command-line interface | 22 | All four `prost-*` entry points — argument handling, and that the installed console scripts resolve |
214
+ | Classification package | 32 | Forward pass, metrics, preprocessing, Grad-CAM |
215
+
216
+ CI runs the suite on Python 3.10 and 3.11 on every push, and lints the whole repository with `ruff check .`.
217
+
218
+ The tests that need the trained checkpoints skip cleanly rather than fail when those Git LFS files aren't present, so a fresh clone without `git lfs pull` still passes.
219
+
220
+ The three notebooks in [`notebooks/`](notebooks/) are executed end to end by a separate CI job (`nbconvert --execute`) rather than just sitting in the repo unverified — each one falls back to a tiny synthetic dataset (`scripts/make_synthetic_prostate158.py`) and one or two training epochs under a `PROST_SMOKE_TEST` environment variable, so they run in seconds on a CPU-only runner without needing the real ~2 GB dataset:
221
+
222
+ 1. [`01_data_preparation.ipynb`](notebooks/01_data_preparation.ipynb) — loading, preprocessing, and augmenting Prostate158
223
+ 2. [`02_training_and_evaluation.ipynb`](notebooks/02_training_and_evaluation.ipynb) — training the classifier and computing clinical metrics with bootstrap confidence intervals
224
+ 3. [`03_inference_and_explainability.ipynb`](notebooks/03_inference_and_explainability.ipynb) — running inference and generating Grad-CAM / Attention Rollout visualizations
225
+
226
+ ---
227
+
228
+ ## Project structure
229
+
230
+ ```
231
+ ProST-SoftNet-v2/
232
+ ├── checkpoints/prost_fusenet_optimal/ # zone-segmentation checkpoints + per-case metrics, Git LFS
233
+ ├── demo/ # zone-segmentation dashboard (FastAPI + static frontend)
234
+ │ ├── server.py
235
+ │ ├── wgcgpz_inference.py # live WG/CG/PZ cascade inference
236
+ │ ├── zone_pipeline/ # segmentation model definitions (self-contained)
237
+ │ ├── rag_report.py # retrieval-augmented report generation
238
+ │ └── static/index.html
239
+ ├── hf_spaces/ # Gradio demo of the segmentation pipeline (not yet deployed)
240
+ ├── prostsoftnet/ # classification package (pip installable, not benchmarked)
241
+ │ ├── data/ # Prostate158 dataset, DICOM/NIfTI loading, augmentation
242
+ │ ├── models/ # hybrid CNN-ViT architecture, losses
243
+ │ ├── training/ # training loop, evaluation, ONNX export
244
+ │ ├── utils/ # Grad-CAM, Attention Rollout, metrics, visualization
245
+ │ └── cli.py # prost-train / prost-evaluate / prost-predict / prost-export
246
+ ├── web-app/ # React frontend for the classification web app
247
+ ├── php-api/ # PHP REST API (auth, predict proxy, history, admin)
248
+ ├── ml-api/ # FastAPI ONNX inference server for the web app
249
+ ├── notebooks/ # 3 illustrative notebooks, executed in CI
250
+ ├── tests/ # pytest suite (61 tests)
251
+ ├── docs/ # architecture, classification package, API reference,
252
+ │ # setup, deployment, user/admin manuals
253
+ ├── .github/workflows/ # CI and release automation
254
+ ├── CITATION.cff, codemeta.json # machine-readable citation and software metadata
255
+ └── pyproject.toml # package configuration
256
+ ```
257
+
258
+ ---
259
+
260
+ ## Code metadata
261
+
262
+ | # | Field | Value |
263
+ |---|---|---|
264
+ | C1 | Current code version | 1.2.0 |
265
+ | C2 | Permanent link to code/repository used for this version | https://github.com/ProST-SoftNet/ProST-SoftNet-v2 (currently private — see [Status](#status)) |
266
+ | C3 | Permanent link to reproducible capsule | Not yet available |
267
+ | C4 | Legal code license | MIT |
268
+ | C5 | Code versioning system used | git, with Git LFS for model checkpoints |
269
+ | C6 | Software code languages, tools, and services used | Python, PyTorch, FastAPI, TypeScript/React, PHP |
270
+ | C7 | Compilation requirements, operating environments, dependencies | Python ≥ 3.10, PyTorch ≥ 2.2 (CUDA 11.8+ optional); full list in [`pyproject.toml`](pyproject.toml) |
271
+ | C8 | If available, link to developer documentation/manual | [`docs/`](docs/) (architecture, classification package, API reference, setup, deployment, user/admin manuals) |
272
+ | C9 | Support email for questions | saqibiqbal@cs.qau.edu.pk |
273
+
274
+ ---
275
+
276
+ ## Citation
277
+
278
+ No DOI has been minted for this software yet — a Zenodo release is planned, at which point this section and `CITATION.cff` will be updated with the real DOI. Until then, please cite the repository directly:
279
+
280
+ ```bibtex
281
+ @software{iqbal_prostsoftnet,
282
+ title = {ProST-SoftNet: Software for Prostate MRI Zonal Segmentation and Cancer Classification},
283
+ author = {Iqbal, Saqib and Tausif, Muhammad},
284
+ url = {https://github.com/ProST-SoftNet/ProST-SoftNet-v2}
285
+ }
286
+ ```
287
+
288
+ If you use the Prostate158 dataset itself, please also cite the [original dataset paper and repository](https://github.com/kbressem/prostate158).
289
+
290
+ ---
291
+
292
+ ## Authors
293
+
294
+ - **Saqib Iqbal** — Quaid-i-Azam University — model design, zone-segmentation methodology, training and evaluation
295
+ - **Muhammad Tausif** — software architecture and implementation: the classification package, the dashboard, the full-stack web application, and CI/testing infrastructure
296
+
297
+ ---
298
+
299
+ ## License
300
+
301
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,216 @@
1
+ # ProST-SoftNet
2
+
3
+ **Reproducible cascade-CNN software for prostate MRI zonal segmentation (whole gland / central gland / peripheral zone)**
4
+
5
+ [![CI](https://github.com/ProST-SoftNet/ProST-SoftNet-v2/actions/workflows/ci.yml/badge.svg)](https://github.com/ProST-SoftNet/ProST-SoftNet-v2/actions)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
7
+
8
+ *PyPI package and Zenodo DOI are not live yet — see [Status](#status) below before citing this work.*
9
+
10
+ ---
11
+
12
+ ProST-SoftNet segments the prostate into **whole gland (WG)**, **central gland (CG)**, and **peripheral zone (PZ)** from multi-parametric MRI, using a cascade 3-D CNN pipeline built around [Prostate158](https://github.com/kbressem/prostate158) — the public benchmark of 158 prostate MRI exams with expert zonal and lesion annotations ([Zenodo archive, DOI 10.5281/zenodo.6481141](https://zenodo.org/record/6481141)).
13
+
14
+ On the held-out 19-case test split, the pipeline reaches a **peripheral-zone Dice of 0.7513 — above the 0.7473 human inter-reader agreement measured on the same data.** The peripheral zone is the hardest of the three to segment and the region where most clinically significant prostate cancers arise, so it is reported separately rather than averaged away. Full results are in [Zone-Segmentation Results](#zone-segmentation-results).
15
+
16
+ Every trained checkpoint, per-iteration ablation log, and per-case metric CSV is committed to this repository rather than described from the outside, so the numbers here can be recomputed and checked directly rather than taken on faith. An interactive dashboard ([`demo/`](demo/)) lets you browse the results or upload a new patient's MRI and run the pipeline yourself.
17
+
18
+ The repository also ships `prostsoftnet`, a pip-installable hybrid **CNN-ViT** classifier for benign/malignant prediction with Grad-CAM/Attention-Rollout explainability and ONNX export. It is complete and unit-tested, but **has not been trained to completion on Prostate158 and carries no benchmark results** — it is included as reusable, extensible architecture, not as a validated classifier. See [Status](#status).
19
+
20
+ ## What's in this repo
21
+
22
+ | Area | Where | What it is |
23
+ |---|---|---|
24
+ | **Zone-segmentation pipeline** *(the primary contribution)* | [`checkpoints/prost_fusenet_optimal/`](checkpoints/prost_fusenet_optimal/) | Cascade 3-D CNN (frozen whole-gland localizer → cropped zone refinement), multiple training iterations with committed results and per-case metrics, tracked via Git LFS |
25
+ | Classification package *(not benchmarked)* | [`prostsoftnet/`](prostsoftnet/) | Hybrid CNN-ViT (EfficientNetV2-S + ViT + cross-attention) for benign/malignant classification — data loading, training, metrics, explainability, ONNX export. Complete and unit-tested; **no trained checkpoint or benchmark results** |
26
+ | Interactive dashboard | [`demo/`](demo/) | FastAPI server + static frontend: pre-generated segmentation results, ROC/PR/training curves, and a live tab to upload a new patient's MRI and run the pipeline |
27
+ | Full-stack web app | [`web-app/`](web-app/), [`php-api/`](php-api/), [`ml-api/`](ml-api/) | React + PHP/MySQL + FastAPI application wrapping the classification model for doctor-facing use |
28
+ | HuggingFace Spaces demo | [`hf_spaces/`](hf_spaces/) | Gradio app for the zonal-segmentation pipeline, built and locally verified — pending PRO-tier compute to deploy live, see [Status](#status). A static landing page is live at [huggingface.co/spaces/MuhammadTausif/prost-softnet-v2-demo](https://huggingface.co/spaces/MuhammadTausif/prost-softnet-v2-demo) in the meantime. |
29
+ | Illustrative notebooks | [`notebooks/`](notebooks/) | Data preparation, training/evaluation, and inference/explainability — executed end to end on every CI run, not just committed as static files |
30
+
31
+ ---
32
+
33
+ ## Status
34
+
35
+ Being upfront about what's real right now, rather than what the badges of a finished project usually imply:
36
+
37
+ - **Working and benchmarked**: the zone-segmentation pipeline — its checkpoints and reported metrics (recomputed from the committed per-case CSVs, not hand-typed), the dashboard, and the 61-test suite covering both the segmentation pipeline and the classification package.
38
+ - **Complete but not benchmarked**: the `prostsoftnet` classification package. Its training, evaluation, and explainability code is finished and unit-tested, but it **has never been run to completion on the full Prostate158 dataset**, so no trained checkpoint and no accuracy numbers exist. It is shipped as reusable architecture, and this README does not report classification results because there are none to report.
39
+ - **Not yet done**: the package is not yet published to PyPI; no Zenodo DOI has been minted for this repository; the interactive HuggingFace Spaces demo (live per-patient inference) is built and passes an end-to-end smoke test locally, but is not yet deployed live — HuggingFace's free tier stopped hosting Gradio/Docker Spaces on CPU compute, which now requires a PRO subscription. A static landing page (results table + links, no live inference) is deployed at [huggingface.co/spaces/MuhammadTausif/prost-softnet-v2-demo](https://huggingface.co/spaces/MuhammadTausif/prost-softnet-v2-demo) in the meantime.
40
+ - **Repository visibility**: this repository is currently private to the ProST-SoftNet organization while the above items are finished. It will be made public before submission, per the venue's requirement that the code be openly accessible.
41
+
42
+ ---
43
+
44
+ ## Zone-Segmentation Results
45
+
46
+ Held-out test split of Prostate158 (19 cases). The pipeline runs in two stages: a frozen Stage-A localizer finds the gland bounding box, then a Stage-B 3-D U-Net segments WG and CG at native crop resolution; PZ is derived as `WG AND NOT CG`.
47
+
48
+ | Model | WG Dice | CG Dice | PZ Dice | Zone-mean Dice |
49
+ |---|---|---|---|---|
50
+ | Cascade-CNN, direct 3-class (`iter15`) | 0.8941 | 0.8642 | 0.7308 | 0.7975 |
51
+ | **Cascade-CNN, PZ-derived (`iter18`) — current best** | **0.8926** | **0.8676** | **0.7483** | **0.8079** |
52
+ | Confidence-weighted fusion of iter18 + iter29, no extra training (`iter30`) | 0.8910 | 0.8619 | 0.7513 | 0.8066 |
53
+ | Human inter-reader agreement (reference ceiling) | — | 0.8726 | 0.7473 | — |
54
+
55
+ `iter18` is the checkpoint the dashboard's live "Zonal Analysis" tab runs. The peripheral zone is the hardest of the three by a wide margin — it's small, has a less distinct boundary on T2W, and is exactly where most clinically significant cancers arise, so tracking it separately from whole-gland Dice matters more than a single averaged number would suggest. Full iteration-by-iteration history, what changed between each one, and why some approaches didn't help are documented in [`checkpoints/prost_fusenet_optimal/README.md`](checkpoints/prost_fusenet_optimal/README.md).
56
+
57
+ ### A note on the classification package
58
+
59
+ The `prostsoftnet` classifier is **deliberately not benchmarked here.** Its training, evaluation, and explainability code is complete and unit-tested, but it has never been run to completion on the full Prostate158 dataset — so no trained checkpoint exists and there are no accuracy numbers to report. Rather than publish a hastily-trained figure, this repository reports only what it can substantiate: the zone-segmentation results above.
60
+
61
+ The package remains fully usable for anyone who wants to train it themselves — see [`docs/classification-package.md`](docs/classification-package.md) — and `prost-evaluate` will produce the standard clinical metrics (AUROC, sensitivity, specificity, PPV, NPV with bootstrap confidence intervals) once a checkpoint exists.
62
+
63
+ ---
64
+
65
+ ## Try the dashboard
66
+
67
+ No GPU needed to browse the pre-generated results; the live "Zonal Analysis" tab needs the trained checkpoints already present in `checkpoints/prost_fusenet_optimal/`.
68
+
69
+ ```bash
70
+ cd demo
71
+ pip install -r requirements.txt
72
+ python server.py
73
+ # open http://localhost:8000
74
+ ```
75
+
76
+ The dashboard opens on the zone-segmentation model comparison and statistics tabs. A third tab accepts a new patient's T2W/DWI/ADC MRI — NIfTI or a DICOM series as a ZIP — runs the cascade pipeline on it, and returns WG/CG/PZ volumes, overlay figures, and a plain-language, explicitly non-diagnostic description grounded in a small retrieval-augmented knowledge base (PI-RADS anatomy references, not a diagnosis).
77
+
78
+ ### Zone-Segmentation Models
79
+
80
+ Side-by-side test-set metrics for each trained checkpoint, per-zone ASD/HD95 distance metrics, and pre-generated ground-truth-vs-prediction overlays for individual test cases.
81
+
82
+ ![Zone-Segmentation Models tab: metrics comparison table, distance metrics, and a ground-truth vs prediction overlay for one test case](https://raw.githubusercontent.com/ProST-SoftNet/ProST-SoftNet-v2/master/docs/images/dashboard-zone-models.png)
83
+
84
+ ### Zone Statistics
85
+
86
+ Whole-gland segmentation compared against ground truth on real T2W and DWI slices (red = ground truth, yellow = prediction, green = overlap), per-model Dice/IoU/precision/recall, voxel-level ROC and precision-recall curves computed from raw per-voxel probabilities across all 19 test cases, and training history.
87
+
88
+ ![Zone Statistics tab: T2W and DWI overlays comparing ground truth against both models, per-model gland metrics, ROC and precision-recall curves, and training loss and validation Dice curves](https://raw.githubusercontent.com/ProST-SoftNet/ProST-SoftNet-v2/master/docs/images/dashboard-zone-statistics.png)
89
+
90
+ ---
91
+
92
+ ## Installation
93
+
94
+ ```bash
95
+ git clone https://github.com/ProST-SoftNet/ProST-SoftNet-v2.git
96
+ cd ProST-SoftNet-v2
97
+ pip install -e ".[dev,train,notebook]"
98
+ ```
99
+
100
+ Not yet on PyPI (see [Status](#status)) — install from source for now.
101
+
102
+ **Requirements**: Python 3.10 or newer, PyTorch 2.2+, CUDA 11.8+ recommended for training (CPU works for inference and for browsing the dashboard).
103
+
104
+ ---
105
+
106
+ ## The `prostsoftnet` classification package
107
+
108
+ Alongside the segmentation pipeline, this repository ships a pip-installable hybrid **CNN-ViT** classifier (EfficientNetV2-S + 6-layer ViT + cross-attention fusion) for benign/malignant prediction, with Grad-CAM and Attention-Rollout explainability, ONNX export, and a CLI (`prost-train`, `prost-evaluate`, `prost-predict`, `prost-export`).
109
+
110
+ As noted in [Status](#status), it has **not been trained to completion and carries no benchmark results** — it is included as reusable, extensible architecture rather than as a validated classifier.
111
+
112
+ **Full architecture description, quick start, training/evaluation/inference commands, and explainability API: [`docs/classification-package.md`](docs/classification-package.md).**
113
+
114
+ ---
115
+
116
+ ## Tests and illustrative examples
117
+
118
+ ```bash
119
+ pytest tests/
120
+ ```
121
+
122
+ 105 tests pass in a clean environment, covering each part of the software in turn:
123
+
124
+ | Area | Tests | What they check |
125
+ |---|---|---|
126
+ | Zone-segmentation pipeline | 29 | Model architectures, confidence-weighted fusion, and an end-to-end run of the full pipeline against the real trained checkpoints |
127
+ | Dashboard HTTP API | 22 | Every route group, query-parameter validation, and that malformed uploads are refused rather than reaching inference |
128
+ | Command-line interface | 22 | All four `prost-*` entry points — argument handling, and that the installed console scripts resolve |
129
+ | Classification package | 32 | Forward pass, metrics, preprocessing, Grad-CAM |
130
+
131
+ CI runs the suite on Python 3.10 and 3.11 on every push, and lints the whole repository with `ruff check .`.
132
+
133
+ The tests that need the trained checkpoints skip cleanly rather than fail when those Git LFS files aren't present, so a fresh clone without `git lfs pull` still passes.
134
+
135
+ The three notebooks in [`notebooks/`](notebooks/) are executed end to end by a separate CI job (`nbconvert --execute`) rather than just sitting in the repo unverified — each one falls back to a tiny synthetic dataset (`scripts/make_synthetic_prostate158.py`) and one or two training epochs under a `PROST_SMOKE_TEST` environment variable, so they run in seconds on a CPU-only runner without needing the real ~2 GB dataset:
136
+
137
+ 1. [`01_data_preparation.ipynb`](notebooks/01_data_preparation.ipynb) — loading, preprocessing, and augmenting Prostate158
138
+ 2. [`02_training_and_evaluation.ipynb`](notebooks/02_training_and_evaluation.ipynb) — training the classifier and computing clinical metrics with bootstrap confidence intervals
139
+ 3. [`03_inference_and_explainability.ipynb`](notebooks/03_inference_and_explainability.ipynb) — running inference and generating Grad-CAM / Attention Rollout visualizations
140
+
141
+ ---
142
+
143
+ ## Project structure
144
+
145
+ ```
146
+ ProST-SoftNet-v2/
147
+ ├── checkpoints/prost_fusenet_optimal/ # zone-segmentation checkpoints + per-case metrics, Git LFS
148
+ ├── demo/ # zone-segmentation dashboard (FastAPI + static frontend)
149
+ │ ├── server.py
150
+ │ ├── wgcgpz_inference.py # live WG/CG/PZ cascade inference
151
+ │ ├── zone_pipeline/ # segmentation model definitions (self-contained)
152
+ │ ├── rag_report.py # retrieval-augmented report generation
153
+ │ └── static/index.html
154
+ ├── hf_spaces/ # Gradio demo of the segmentation pipeline (not yet deployed)
155
+ ├── prostsoftnet/ # classification package (pip installable, not benchmarked)
156
+ │ ├── data/ # Prostate158 dataset, DICOM/NIfTI loading, augmentation
157
+ │ ├── models/ # hybrid CNN-ViT architecture, losses
158
+ │ ├── training/ # training loop, evaluation, ONNX export
159
+ │ ├── utils/ # Grad-CAM, Attention Rollout, metrics, visualization
160
+ │ └── cli.py # prost-train / prost-evaluate / prost-predict / prost-export
161
+ ├── web-app/ # React frontend for the classification web app
162
+ ├── php-api/ # PHP REST API (auth, predict proxy, history, admin)
163
+ ├── ml-api/ # FastAPI ONNX inference server for the web app
164
+ ├── notebooks/ # 3 illustrative notebooks, executed in CI
165
+ ├── tests/ # pytest suite (61 tests)
166
+ ├── docs/ # architecture, classification package, API reference,
167
+ │ # setup, deployment, user/admin manuals
168
+ ├── .github/workflows/ # CI and release automation
169
+ ├── CITATION.cff, codemeta.json # machine-readable citation and software metadata
170
+ └── pyproject.toml # package configuration
171
+ ```
172
+
173
+ ---
174
+
175
+ ## Code metadata
176
+
177
+ | # | Field | Value |
178
+ |---|---|---|
179
+ | C1 | Current code version | 1.2.0 |
180
+ | C2 | Permanent link to code/repository used for this version | https://github.com/ProST-SoftNet/ProST-SoftNet-v2 (currently private — see [Status](#status)) |
181
+ | C3 | Permanent link to reproducible capsule | Not yet available |
182
+ | C4 | Legal code license | MIT |
183
+ | C5 | Code versioning system used | git, with Git LFS for model checkpoints |
184
+ | C6 | Software code languages, tools, and services used | Python, PyTorch, FastAPI, TypeScript/React, PHP |
185
+ | C7 | Compilation requirements, operating environments, dependencies | Python ≥ 3.10, PyTorch ≥ 2.2 (CUDA 11.8+ optional); full list in [`pyproject.toml`](pyproject.toml) |
186
+ | C8 | If available, link to developer documentation/manual | [`docs/`](docs/) (architecture, classification package, API reference, setup, deployment, user/admin manuals) |
187
+ | C9 | Support email for questions | saqibiqbal@cs.qau.edu.pk |
188
+
189
+ ---
190
+
191
+ ## Citation
192
+
193
+ No DOI has been minted for this software yet — a Zenodo release is planned, at which point this section and `CITATION.cff` will be updated with the real DOI. Until then, please cite the repository directly:
194
+
195
+ ```bibtex
196
+ @software{iqbal_prostsoftnet,
197
+ title = {ProST-SoftNet: Software for Prostate MRI Zonal Segmentation and Cancer Classification},
198
+ author = {Iqbal, Saqib and Tausif, Muhammad},
199
+ url = {https://github.com/ProST-SoftNet/ProST-SoftNet-v2}
200
+ }
201
+ ```
202
+
203
+ If you use the Prostate158 dataset itself, please also cite the [original dataset paper and repository](https://github.com/kbressem/prostate158).
204
+
205
+ ---
206
+
207
+ ## Authors
208
+
209
+ - **Saqib Iqbal** — Quaid-i-Azam University — model design, zone-segmentation methodology, training and evaluation
210
+ - **Muhammad Tausif** — software architecture and implementation: the classification package, the dashboard, the full-stack web application, and CI/testing infrastructure
211
+
212
+ ---
213
+
214
+ ## License
215
+
216
+ MIT — see [LICENSE](LICENSE).